Skip to content
Browse files

changed files structure to enable amd generation

  • Loading branch information...
1 parent 3c670e8 commit 2c0d0cf2dea86aebf2beb59353f3ed8fb36f6870 @millermedeiros committed Feb 21, 2011
View
20 build.xml
@@ -12,7 +12,7 @@
<target name="-purgeJsDeploy">
<delete>
- <fileset dir="${dist.dir}" includes="${dist.name} ${dist.min.name}" />
+ <fileset dir="${dist.dir}" includes="${dist.name} ${dist.min.name} ${dist.amd.name}" />
</delete>
</target>
@@ -25,20 +25,28 @@
<format property="build.date" pattern="MM/dd/yyyy hh:mm aa" unit="hour"/>
</tstamp>
- <copy file="${src.dir}/signals.js" tofile="${dist.dir}/${dist.name}" />
+ <loadfile property="license.txt" srcFile="${src.dir}/license.txt"/>
+ <loadfile property="signals.js" srcFile="${src.dir}/signals.js"/>
<loadfile property="SignalBinding.js" srcFile="${src.dir}/SignalBinding.js"/>
<loadfile property="Signal.js" srcFile="${src.dir}/Signal.js"/>
- <replace file="${dist.dir}/${dist.name}">
+ <copy file="${src.dir}/wrapper_closure.js" tofile="${dist.dir}/${dist.name}" />
+ <copy file="${src.dir}/wrapper_amd.js" tofile="${dist.dir}/${dist.amd.name}" />
+
+ <replace>
+ <fileset dir="${dist.dir}" includes="${dist.name} ${dist.amd.name}" />
+ <replacefilter token="//::LICENSE:://" value="${license.txt}" />
+ <replacefilter token="//::SIGNALS_JS:://" value="${signals.js}" />
+ <replacefilter token="//::SIGNAL_BINDING_JS:://" value="${SignalBinding.js}" />
+ <replacefilter token="//::SIGNAL_JS:://" value="${Signal.js}" />
+ <!-- version number, build number/date should come after other replaces -->
<replacefilter token="::VERSION_NUMBER::" value="${version.number}" />
<replacefilter token="::BUILD_NUMBER::" value="${build.number}" />
<replacefilter token="::BUILD_DATE::" value="${build.date}" />
- <replacefilter token="//::SIGNAL_BINDING_JS:://" value="${SignalBinding.js}" />
- <replacefilter token="//::SIGNAL_JS:://" value="${Signal.js}" />
</replace>
<echo message="${dist.name} built." />
- </target>
+ </target>
<target name="lint">
<echo message="JSLinting ${dist.name}..."/>
View
4 dev/build/build.number
@@ -1,3 +1,3 @@
#Build Number for ANT. Do not edit!
-#Mon Feb 21 18:05:43 EST 2011
-build.number=143
+#Mon Feb 21 20:27:42 EST 2011
+build.number=155
View
1 dev/build/build.properties
@@ -13,6 +13,7 @@ yuitest-coverage-report.jar = ${build.dir}/yuitest-coverage/yuitest-coverage-rep
product.name = js-signals
version.number = 0.5.2
dist.name = ${product.name}.js
+dist.amd.name = ${product.name}.amd.js
dist.min.name = ${product.name}.min.js
dist.inst.name = ${product.name}.inst.js
coverage.json = ${coverage.dir}/coverage.json
View
7 dev/src/license.txt
@@ -0,0 +1,7 @@
+/*!!
+ * JS Signals <http://millermedeiros.github.com/js-signals/>
+ * Released under the MIT license <http://www.opensource.org/licenses/mit-license.php>
+ * @author Miller Medeiros <http://millermedeiros.com/>
+ * @version ::VERSION_NUMBER::
+ * @build ::BUILD_NUMBER:: (::BUILD_DATE::)
+ */
View
25 dev/src/signals.js
@@ -1,31 +1,8 @@
-/*jslint onevar:true, undef:true, newcap:true, regexp:true, bitwise:true, maxerr:50, indent:4, white:false, nomen:false, plusplus:false */
-
-/*!!
- * JS Signals <http://millermedeiros.github.com/js-signals/>
- * Released under the MIT license <http://www.opensource.org/licenses/mit-license.php>
- * @author Miller Medeiros <http://millermedeiros.com/>
- * @version ::VERSION_NUMBER::
- * @build ::BUILD_NUMBER:: (::BUILD_DATE::)
- */
-
-/**
- * @namespace Signals Namespace - Custom event/messaging system based on AS3 Signals
- */
-var signals = (function(){
-
var signals = /** @lends signals */{
/**
* Signals Version Number
* @type string
* @const
*/
VERSION : '::VERSION_NUMBER::'
- };
-
-//::SIGNAL_BINDING_JS:://
-
-//::SIGNAL_JS:://
-
- return signals;
-
-}());
+ };
View
14 dev/src/wrapper_amd.js
@@ -0,0 +1,14 @@
+/*jslint onevar:true, undef:true, newcap:true, regexp:true, bitwise:true, maxerr:50, indent:4, white:false, nomen:false, plusplus:false */
+/*global define:true*/
+
+//::LICENSE:://
+define('signals', function(){
+
+//::SIGNALS_JS:://
+
+//::SIGNAL_BINDING_JS:://
+
+//::SIGNAL_JS:://
+
+ return signals;
+});
View
18 dev/src/wrapper_closure.js
@@ -0,0 +1,18 @@
+/*jslint onevar:true, undef:true, newcap:true, regexp:true, bitwise:true, maxerr:50, indent:4, white:false, nomen:false, plusplus:false */
+
+//::LICENSE:://
+
+/**
+ * @namespace Signals Namespace - Custom event/messaging system based on AS3 Signals
+ */
+var signals = (function(){
+
+//::SIGNALS_JS:://
+
+//::SIGNAL_BINDING_JS:://
+
+//::SIGNAL_JS:://
+
+ return signals;
+
+}());
View
2 dist/docs/files.html
@@ -61,7 +61,7 @@ <h1 class="classTitle">File Index</h1>
</div>
<div class="fineprint" style="clear:both;text-align:center">
- Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Feb 21 2011 18:05:49 GMT-0500 (EST)
+ Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Feb 21 2011 20:30:07 GMT-0500 (EST)
| template based on Steffen Siering <a href="http://github.com/urso/jsdoc-simple">jsdoc-simple</a>.
</div>
</body>
View
2 dist/docs/index.html
@@ -85,7 +85,7 @@ <h1 class="classTitle">Class Index</h1>
</div>
<div class="fineprint" style="clear:both;text-align:center">
- Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Feb 21 2011 18:05:49 GMT-0500 (EST)
+ Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Feb 21 2011 20:30:07 GMT-0500 (EST)
| template based on Steffen Siering <a href="http://github.com/urso/jsdoc-simple">jsdoc-simple</a>.
</div>
</body>
View
2 dist/docs/symbolindex.html
@@ -293,7 +293,7 @@ <h1 id="classTitle">Symbol Index</h1>
</div>
<div class="fineprint" style="clear:both;text-align:center">
- Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Feb 21 2011 18:05:49 GMT-0500 (EST)
+ Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Feb 21 2011 20:30:07 GMT-0500 (EST)
| template based on Steffen Siering <a href="http://github.com/urso/jsdoc-simple">jsdoc-simple</a>.
</div>
</body>
View
2 dist/docs/symbols/_global_.html
@@ -101,7 +101,7 @@ <h1 class="classTitle">
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both;text-align:center">
- Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Feb 21 2011 18:05:49 GMT-0500 (EST)
+ Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Feb 21 2011 20:30:07 GMT-0500 (EST)
| template based on Steffen Siering <a href="http://github.com/urso/jsdoc-simple">jsdoc-simple</a>.
</div>
</body>
View
2 dist/docs/symbols/signals.Signal.html
@@ -663,7 +663,7 @@ <h1 class="classTitle">
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both;text-align:center">
- Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Feb 21 2011 18:05:49 GMT-0500 (EST)
+ Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Feb 21 2011 20:30:07 GMT-0500 (EST)
| template based on Steffen Siering <a href="http://github.com/urso/jsdoc-simple">jsdoc-simple</a>.
</div>
</body>
View
2 dist/docs/symbols/signals.SignalBinding.html
@@ -579,7 +579,7 @@ <h1 class="classTitle">
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both;text-align:center">
- Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Feb 21 2011 18:05:49 GMT-0500 (EST)
+ Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Feb 21 2011 20:30:07 GMT-0500 (EST)
| template based on Steffen Siering <a href="http://github.com/urso/jsdoc-simple">jsdoc-simple</a>.
</div>
</body>
View
2 dist/docs/symbols/signals.html
@@ -179,7 +179,7 @@ <h1 class="classTitle">
<!-- ============================== footer ================================= -->
<div class="fineprint" style="clear:both;text-align:center">
- Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Feb 21 2011 18:05:49 GMT-0500 (EST)
+ Documentation generated by <a href="http://code.google.com/p/jsdoc-toolkit/" target="_blankt">JsDoc Toolkit</a> 2.4.0 on Mon Feb 21 2011 20:30:07 GMT-0500 (EST)
| template based on Steffen Siering <a href="http://github.com/urso/jsdoc-simple">jsdoc-simple</a>.
</div>
</body>
View
8 ...cs/symbols/src/C__Miller_Personal_open_source_projects_js-signals_dist_js-signals.js.html
@@ -12,15 +12,15 @@
<span class='line'> 5</span> * Released under the MIT license &lt;http://www.opensource.org/licenses/mit-license.php>
<span class='line'> 6</span> * @author Miller Medeiros &lt;http://millermedeiros.com/>
<span class='line'> 7</span> * @version 0.5.2
-<span class='line'> 8</span> * @build 142 (02/21/2011 06:05 PM)
+<span class='line'> 8</span> * @build 154 (02/21/2011 08:27 PM)
<span class='line'> 9</span> */</span><span class="WHIT">
<span class='line'> 10</span>
<span class='line'> 11</span> </span><span class="COMM">/**
<span class='line'> 12</span> * @namespace Signals Namespace - Custom event/messaging system based on AS3 Signals
<span class='line'> 13</span> */</span><span class="WHIT">
<span class='line'> 14</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">signals</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="PUNC">(</span><span class="KEYW">function</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">{</span><span class="WHIT">
-<span class='line'> 15</span> </span><span class="WHIT"> </span><span class="WHIT">
-<span class='line'> 16</span> </span><span class="WHIT"> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">signals</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="COMM">/** @lends signals */</span><span class="PUNC">{</span><span class="WHIT">
+<span class='line'> 15</span> </span><span class="WHIT">
+<span class='line'> 16</span> </span><span class="KEYW">var</span><span class="WHIT"> </span><span class="NAME">signals</span><span class="WHIT"> </span><span class="PUNC">=</span><span class="WHIT"> </span><span class="COMM">/** @lends signals */</span><span class="PUNC">{</span><span class="WHIT">
<span class='line'> 17</span> </span><span class="WHIT"> </span><span class="COMM">/**
<span class='line'> 18</span> * Signals Version Number
<span class='line'> 19</span> * @type string
@@ -405,5 +405,5 @@
<span class='line'>398</span> </span><span class="WHIT"> </span><span class="PUNC">}</span><span class="PUNC">;</span><span class="WHIT">
<span class='line'>399</span>
<span class='line'>400</span> </span><span class="WHIT"> </span><span class="KEYW">return</span><span class="WHIT"> </span><span class="NAME">signals</span><span class="PUNC">;</span><span class="WHIT">
-<span class='line'>401</span> </span><span class="WHIT"> </span><span class="WHIT">
+<span class='line'>401</span> </span><span class="WHIT">
<span class='line'>402</span> </span><span class="PUNC">}</span><span class="PUNC">(</span><span class="PUNC">)</span><span class="PUNC">)</span><span class="PUNC">;</span></pre></body></html>
View
398 dist/js-signals.amd.js
@@ -0,0 +1,398 @@
+/*jslint onevar:true, undef:true, newcap:true, regexp:true, bitwise:true, maxerr:50, indent:4, white:false, nomen:false, plusplus:false */
+/*global define:true*/
+
+/*!!
+ * JS Signals <http://millermedeiros.github.com/js-signals/>
+ * Released under the MIT license <http://www.opensource.org/licenses/mit-license.php>
+ * @author Miller Medeiros <http://millermedeiros.com/>
+ * @version 0.5.2
+ * @build 154 (02/21/2011 08:27 PM)
+ */
+define('signals', function(){
+
+ var signals = /** @lends signals */{
+ /**
+ * Signals Version Number
+ * @type string
+ * @const
+ */
+ VERSION : '0.5.2'
+ };
+
+ // SignalBinding -------------------------------------------------
+ //================================================================
+
+ /**
+ * Object that represents a binding between a Signal and a listener function.
+ * <br />- <strong>This is an internal constructor and shouldn't be called by regular users.</strong>
+ * <br />- inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes.
+ * @author Miller Medeiros
+ * @constructor
+ * @internal
+ * @name signals.SignalBinding
+ * @param {signals.Signal} signal Reference to Signal object that listener is currently bound to.
+ * @param {Function} listener Handler function bound to the signal.
+ * @param {boolean} isOnce If binding should be executed just once.
+ * @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
+ * @param {Number} [priority] The priority level of the event listener. (default = 0).
+ */
+ function SignalBinding(signal, listener, isOnce, listenerContext, priority){
+
+ /**
+ * Handler function bound to the signal.
+ * @type Function
+ * @private
+ */
+ this._listener = listener;
+
+ /**
+ * If binding should be executed just once.
+ * @type boolean
+ * @private
+ */
+ this._isOnce = isOnce;
+
+ /**
+ * Context on which listener will be executed (object that should represent the `this` variable inside listener function).
+ * @memberOf signals.SignalBinding.prototype
+ * @name context
+ * @type {Object|undefined}
+ */
+ this.context = listenerContext;
+
+ /**
+ * Reference to Signal object that listener is currently bound to.
+ * @type signals.Signal
+ * @private
+ */
+ this._signal = signal;
+
+ /**
+ * Listener priority
+ * @type Number
+ * @private
+ */
+ this._priority = priority || 0;
+ }
+
+ SignalBinding.prototype = /** @lends signals.SignalBinding.prototype */ {
+
+ /**
+ * @type boolean
+ * @private
+ */
+ _isEnabled : true,
+
+ /**
+ * Call listener passing arbitrary parameters.
+ * <p>If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.</p>
+ * @param {Array} [paramsArr] Array of parameters that should be passed to the listener
+ * @return {*} Value returned by the listener.
+ */
+ execute : function(paramsArr){
+ var r;
+ if(this._isEnabled){
+ r = this._listener.apply(this.context, paramsArr);
+ if(this._isOnce){
+ this.detach();
+ }
+ }
+ return r;
+ },
+
+ /**
+ * Detach binding from signal.
+ * - alias to: mySignal.remove(myBinding.getListener());
+ * @return {Function} Handler function bound to the signal.
+ */
+ detach : function(){
+ return this._signal.remove(this._listener);
+ },
+
+ /**
+ * @return {Function} Handler function bound to the signal.
+ */
+ getListener : function(){
+ return this._listener;
+ },
+
+ /**
+ * Remove binding from signal and destroy any reference to external Objects (destroy SignalBinding object).
+ * <p><strong>IMPORTANT:</strong> calling methods on the binding instance after calling dispose will throw errors.</p>
+ */
+ dispose : function(){
+ this.detach();
+ this._destroy();
+ },
+
+ /**
+ * Delete all instance properties
+ * @private
+ */
+ _destroy : function(){
+ delete this._signal;
+ delete this._isOnce;
+ delete this._listener;
+ delete this.context;
+ },
+
+ /**
+ * Disable SignalBinding, block listener execution. Listener will only be executed after calling `enable()`.
+ * @see signals.SignalBinding.enable()
+ */
+ disable : function(){
+ this._isEnabled = false;
+ },
+
+ /**
+ * Enable SignalBinding. Enable listener execution.
+ * @see signals.SignalBinding.disable()
+ */
+ enable : function(){
+ this._isEnabled = true;
+ },
+
+ /**
+ * @return {boolean} If SignalBinding is currently paused and won't execute listener during dispatch.
+ */
+ isEnabled : function(){
+ return this._isEnabled;
+ },
+
+ /**
+ * @return {boolean} If SignalBinding will only be executed once.
+ */
+ isOnce : function(){
+ return this._isOnce;
+ },
+
+ /**
+ * @return {string} String representation of the object.
+ */
+ toString : function(){
+ return '[SignalBinding isOnce: '+ this._isOnce +', isEnabled: '+ this._isEnabled +']';
+ }
+
+ };
+
+/*global signals:true, SignalBinding:true*/
+
+ // Signal --------------------------------------------------------
+ //================================================================
+
+ /**
+ * Custom event broadcaster
+ * <br />- inspired by Robert Penner's AS3 Signals.
+ * @author Miller Medeiros
+ * @constructor
+ */
+ signals.Signal = function(){
+ /**
+ * @type Array.<SignalBinding>
+ * @private
+ */
+ this._bindings = [];
+ };
+
+ signals.Signal.prototype = {
+
+ /**
+ * @type boolean
+ * @private
+ */
+ _shouldPropagate : true,
+
+ /**
+ * @type boolean
+ * @private
+ */
+ _isEnabled : true,
+
+ /**
+ * @param {Function} listener
+ * @param {boolean} isOnce
+ * @param {Object} [scope]
+ * @param {Number} [priority]
+ * @return {SignalBinding}
+ * @private
+ */
+ _registerListener : function(listener, isOnce, scope, priority){
+
+ if(typeof listener !== 'function'){
+ throw new Error('listener is a required param of add() and addOnce() and should be a Function.');
+ }
+
+ var prevIndex = this._indexOfListener(listener),
+ binding;
+
+ if(prevIndex !== -1){ //avoid creating a new Binding for same listener if already added to list
+ binding = this._bindings[prevIndex];
+ if(binding.isOnce() !== isOnce){
+ throw new Error('You cannot add'+ (isOnce? '' : 'Once') +'() then add'+ (!isOnce? '' : 'Once') +'() the same listener without removing the relationship first.');
+ }
+ } else {
+ binding = new SignalBinding(this, listener, isOnce, scope, priority);
+ this._addBinding(binding);
+ }
+
+ return binding;
+ },
+
+ /**
+ * @param {Function} binding
+ * @private
+ */
+ _addBinding : function(binding){
+ //simplified insertion sort
+ var n = this._bindings.length;
+ do { --n; } while (this._bindings[n] && binding._priority <= this._bindings[n]._priority);
+ this._bindings.splice(n+1, 0, binding);
+ },
+
+ /**
+ * @param {Function} listener
+ * @return {number}
+ * @private
+ */
+ _indexOfListener : function(listener){
+ var n = this._bindings.length;
+ while(n--){
+ if(this._bindings[n]._listener === listener){
+ return n;
+ }
+ }
+ return -1;
+ },
+
+ /**
+ * Add a listener to the signal.
+ * @param {Function} listener Signal handler function.
+ * @param {Object} [scope] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
+ * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
+ * @return {SignalBinding} An Object representing the binding between the Signal and listener.
+ */
+ add : function(listener, scope, priority){
+ return this._registerListener(listener, false, scope, priority);
+ },
+
+ /**
+ * Add listener to the signal that should be removed after first execution (will be executed only once).
+ * @param {Function} listener Signal handler function.
+ * @param {Object} [scope] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
+ * @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
+ * @return {SignalBinding} An Object representing the binding between the Signal and listener.
+ */
+ addOnce : function(listener, scope, priority){
+ return this._registerListener(listener, true, scope, priority);
+ },
+
+ /**
+ * Remove a single listener from the dispatch queue.
+ * @param {Function} listener Handler function that should be removed.
+ * @return {Function} Listener handler function.
+ */
+ remove : function(listener){
+ if(typeof listener !== 'function'){
+ throw new Error('listener is a required param of remove() and should be a Function.');
+ }
+
+ var i = this._indexOfListener(listener);
+ if(i !== -1){
+ this._bindings[i]._destroy(); //no reason to a SignalBinding exist if it isn't attached to a signal
+ this._bindings.splice(i, 1);
+ }
+ return listener;
+ },
+
+ /**
+ * Remove all listeners from the Signal.
+ */
+ removeAll : function(){
+ var n = this._bindings.length;
+ while(n--){
+ this._bindings[n]._destroy();
+ }
+ this._bindings.length = 0;
+ },
+
+ /**
+ * @return {number} Number of listeners attached to the Signal.
+ */
+ getNumListeners : function(){
+ return this._bindings.length;
+ },
+
+ /**
+ * Disable Signal. Block dispatch to listeners until `enable()` is called.
+ * <p><strong>IMPORTANT:</strong> If this method is called during a dispatch it will only have effect on the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.</p>
+ * @see signals.Signal.prototype.enable
+ * @see signals.Signal.prototype.halt
+ */
+ disable : function(){
+ this._isEnabled = false;
+ },
+
+ /**
+ * Enable broadcast to listeners.
+ * @see signals.Signal.prototype.disable
+ */
+ enable : function(){
+ this._isEnabled = true;
+ },
+
+ /**
+ * @return {boolean} If Signal is currently enabled and will broadcast message to listeners.
+ */
+ isEnabled : function(){
+ return this._isEnabled;
+ },
+
+ /**
+ * Stop propagation of the event, blocking the dispatch to next listeners on the queue.
+ * <p><strong>IMPORTANT:</strong> should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.</p>
+ * @see signals.Signal.prototype.disable
+ */
+ halt : function(){
+ this._shouldPropagate = false;
+ },
+
+ /**
+ * Dispatch/Broadcast Signal to all listeners added to the queue.
+ * @param {...*} [params] Parameters that should be passed to each handler.
+ */
+ dispatch : function(params){
+ if(! this._isEnabled){
+ return;
+ }
+
+ var paramsArr = Array.prototype.slice.call(arguments),
+ bindings = this._bindings.slice(), //clone array in case add/remove items during dispatch
+ n = this._bindings.length;
+
+ this._shouldPropagate = true; //in case `halt` was called before dispatch or during the previous dispatch.
+
+ //execute all callbacks until end of the list or until a callback returns `false` or stops propagation
+ //reverse loop since listeners with higher priority will be added at the end of the list
+ do { n--; } while (bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
+ },
+
+ /**
+ * Remove all bindings from signal and destroy any reference to external objects (destroy Signal object).
+ * <p><strong>IMPORTANT:</strong> calling any method on the signal instance after calling dispose will throw errors.</p>
+ */
+ dispose : function(){
+ this.removeAll();
+ delete this._bindings;
+ },
+
+ /**
+ * @return {string} String representation of the object.
+ */
+ toString : function(){
+ return '[Signal isEnabled: '+ this._isEnabled +' numListeners: '+ this.getNumListeners() +']';
+ }
+
+ };
+
+ return signals;
+});
View
2 dist/js-signals.js
@@ -5,7 +5,7 @@
* Released under the MIT license <http://www.opensource.org/licenses/mit-license.php>
* @author Miller Medeiros <http://millermedeiros.com/>
* @version 0.5.2
- * @build 142 (02/21/2011 06:05 PM)
+ * @build 154 (02/21/2011 08:27 PM)
*/
/**
View
2 dist/js-signals.min.js
@@ -3,6 +3,6 @@
* Released under the MIT license <http://www.opensource.org/licenses/mit-license.php>
* @author Miller Medeiros <http://millermedeiros.com/>
* @version 0.5.2
- * @build 142 (02/21/2011 06:05 PM)
+ * @build 154 (02/21/2011 08:27 PM)
*/
var signals=(function(){var a={VERSION:"0.5.2"};function b(g,f,d,e,c){this._listener=f;this._isOnce=d;this.context=e;this._signal=g;this._priority=c||0}b.prototype={_isEnabled:true,execute:function(c){var d;if(this._isEnabled){d=this._listener.apply(this.context,c);if(this._isOnce){this.detach()}}return d},detach:function(){return this._signal.remove(this._listener)},getListener:function(){return this._listener},dispose:function(){this.detach();this._destroy()},_destroy:function(){delete this._signal;delete this._isOnce;delete this._listener;delete this.context},disable:function(){this._isEnabled=false},enable:function(){this._isEnabled=true},isEnabled:function(){return this._isEnabled},isOnce:function(){return this._isOnce},toString:function(){return"[SignalBinding isOnce: "+this._isOnce+", isEnabled: "+this._isEnabled+"]"}};a.Signal=function(){this._bindings=[]};a.Signal.prototype={_shouldPropagate:true,_isEnabled:true,_registerListener:function(g,f,e,d){if(typeof g!=="function"){throw new Error("listener is a required param of add() and addOnce() and should be a Function.")}var c=this._indexOfListener(g),h;if(c!==-1){h=this._bindings[c];if(h.isOnce()!==f){throw new Error("You cannot add"+(f?"":"Once")+"() then add"+(!f?"":"Once")+"() the same listener without removing the relationship first.")}}else{h=new b(this,g,f,e,d);this._addBinding(h)}return h},_addBinding:function(c){var d=this._bindings.length;do{--d}while(this._bindings[d]&&c._priority<=this._bindings[d]._priority);this._bindings.splice(d+1,0,c)},_indexOfListener:function(c){var d=this._bindings.length;while(d--){if(this._bindings[d]._listener===c){return d}}return -1},add:function(e,d,c){return this._registerListener(e,false,d,c)},addOnce:function(e,d,c){return this._registerListener(e,true,d,c)},remove:function(d){if(typeof d!=="function"){throw new Error("listener is a required param of remove() and should be a Function.")}var c=this._indexOfListener(d);if(c!==-1){this._bindings[c]._destroy();this._bindings.splice(c,1)}return d},removeAll:function(){var c=this._bindings.length;while(c--){this._bindings[c]._destroy()}this._bindings.length=0},getNumListeners:function(){return this._bindings.length},disable:function(){this._isEnabled=false},enable:function(){this._isEnabled=true},isEnabled:function(){return this._isEnabled},halt:function(){this._shouldPropagate=false},dispatch:function(d){if(!this._isEnabled){return}var c=Array.prototype.slice.call(arguments),f=this._bindings.slice(),e=this._bindings.length;this._shouldPropagate=true;do{e--}while(f[e]&&this._shouldPropagate&&f[e].execute(c)!==false)},dispose:function(){this.removeAll();delete this._bindings},toString:function(){return"[Signal isEnabled: "+this._isEnabled+" numListeners: "+this.getNumListeners()+"]"}};return a}());

0 comments on commit 2c0d0cf

Please sign in to comment.
Something went wrong with that request. Please try again.