Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Although circular references <em>should</em> work with CommonJS (<a href="https://stackoverflow.com/questions/10859630/appcelerator-and-commonjs-modules-caching-and-circular-references">This thread suggests it</a>) I personally avoid them as you might get unexpected results, most of all with Titanium and different platforms.</p> <p>You could work with callbacks or eventListeners, either would do in your case.</p> <p>Here is an example for the callback solution:</p> <p><strong>scanView.js</strong></p> <pre><code>theButton.addEventListener('click', function() { var b = require('scanController'); // You could pass an existing function as well b.startScanning(function(response) { if(response &amp;&amp; response.text) { myResultTxt.text = response.text; } }); }); </code></pre> <p><strong>scanController.js</strong></p> <pre><code>exports.startScanning = function(callback) { callback({ text:'My new text'}); }; </code></pre> <p><br><strong>Edit:</strong><br> To make setText available from any module, you could set a global eventListener. (I know some consider this bad practice, mainly because of possible memory leaks, but if you clean up behind you it is a valuable feature).</p> <p><strong>app.js</strong></p> <pre><code>Ti.App.addEventListener('app:setScanText', module.setResultText); </code></pre> <p><br><strong>scanController.js</strong></p> <pre><code>exports.startScanning = function() { Ti.App.fireEvent('app:setScanText', { text: 'My new text' }); }; </code></pre> <p><br><strong>scanView.js</strong></p> <pre><code>exports.setResultText = function(response) { if(response &amp;&amp; response.text) { myResultTxt.text = response.text; } }; </code></pre> <p>This is untested. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload