Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Updated defer to match withDelay for calling setTimeout. Fixes #28 #29

Merged
merged 1 commit into from

2 participants

@dcneiner
Collaborator

This removes passing additional data to setTimeout. Since withDelay already does not use this data parameter, I updated defer to be the same.

Sorry for all the changes in the minified file… it looks like it swapped "n" and "t" minified variables so there are many changes through the file for that swap. Feel free to rebuild the minified file if you need to.

@ifandelse ifandelse merged commit 25d4550 into postaljs:master
@dcneiner dcneiner deleted the dcneiner:settimeout-data branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
4 lib/postal.js
@@ -108,7 +108,9 @@
defer : function () {
var fn = this.callback;
this.callback = function ( data ) {
- setTimeout( fn, 0, data );
+ setTimeout( function () {
+ fn( data );
+ }, 0 );
};
return this;
},
View
2  lib/postal.min.js
@@ -4,4 +4,4 @@
License: Dual licensed MIT (http://www.opensource.org/licenses/mit-license) & GPL (http://www.opensource.org/licenses/gpl-license)
Version 0.8.2
*/
-(function(t,n){"object"==typeof module&&module.exports?module.exports=function(t){return t=t||require("underscore"),n(t)}:"function"==typeof define&&define.amd?define(["underscore"],function(i){return n(i,t)}):t.postal=n(t._,t)})(this,function(t){var n="/",i="postal",s=function(){var n;return function(i){var s=!1;return t.isString(i)?(s=i===n,n=i):(s=t.isEqual(i,n),n=t.clone(i)),!s}},c=function(){var n=[];return function(i){var s=!t.any(n,function(n){return t.isObject(i)||t.isArray(i)?t.isEqual(i,n):i===n});return s&&n.push(i),s}},e=function(t){this.channel=t||n};e.prototype.subscribe=function(){return 1===arguments.length?new r(this.channel,arguments[0].topic,arguments[0].callback):new r(this.channel,arguments[0],arguments[1])},e.prototype.publish=function(){var t=1===arguments.length?"[object String]"===Object.prototype.toString.call(arguments[0])?{topic:arguments[0]}:arguments[0]:{topic:arguments[0],data:arguments[1]};return t.channel=this.channel,h.configuration.bus.publish(t)};var r=function(t,n,s){this.channel=t,this.topic=n,this.callback=s,this.constraints=[],this.context=null,h.configuration.bus.publish({channel:i,topic:"subscription.created",data:{event:"subscription.created",channel:t,topic:n}}),h.configuration.bus.subscribe(this)};r.prototype={unsubscribe:function(){h.configuration.bus.unsubscribe(this),h.configuration.bus.publish({channel:i,topic:"subscription.removed",data:{event:"subscription.removed",channel:this.channel,topic:this.topic}})},defer:function(){var t=this.callback;return this.callback=function(n){setTimeout(t,0,n)},this},disposeAfter:function(n){if(t.isNaN(n)||0>=n)throw"The value provided to disposeAfter (maxCalls) must be a number greater than zero.";var i=this.callback,s=t.after(n,t.bind(function(){this.unsubscribe()},this));return this.callback=function(){i.apply(this.context,arguments),s()},this},distinctUntilChanged:function(){return this.withConstraint(new s),this},distinct:function(){return this.withConstraint(new c),this},once:function(){this.disposeAfter(1)},withConstraint:function(n){if(!t.isFunction(n))throw"Predicate constraint must be a function";return this.constraints.push(n),this},withConstraints:function(n){var i=this;return t.isArray(n)&&t.each(n,function(t){i.withConstraint(t)}),i},withContext:function(t){return this.context=t,this},withDebounce:function(n){if(t.isNaN(n))throw"Milliseconds must be a number";var i=this.callback;return this.callback=t.debounce(i,n),this},withDelay:function(n){if(t.isNaN(n))throw"Milliseconds must be a number";var i=this.callback;return this.callback=function(t){setTimeout(function(){i(t)},n)},this},withThrottle:function(n){if(t.isNaN(n))throw"Milliseconds must be a number";var i=this.callback;return this.callback=t.throttle(i,n),this},subscribe:function(t){return this.callback=t,this}};var o={cache:{},regex:{},compare:function(n,i){var s,c,e,r=this.cache[i]&&this.cache[i][n];return r!==undefined?r:((c=this.regex[n])||(s="^"+t.map(n.split("."),function(t){var n=e&&"#"!==e?"\\.\\b":"\\b";return n+="#"===t?"[A-Z,a-z,0-9,\\.]*":"*"===t?"[A-Z,a-z,0-9]+":t,e=t,n}).join("")+"$",c=this.regex[n]=RegExp(s)),this.cache[i]=this.cache[i]||{},this.cache[i][n]=r=c.test(i),r)},reset:function(){this.cache={},this.regex={}}},u=function(n,i){h.configuration.resolver.compare(n.topic,i.topic)&&t.all(n.constraints,function(t){return t.call(n.context,i.data,i)})&&"function"==typeof n.callback&&n.callback.call(n.context,i.data,i)},a={addWireTap:function(t){var n=this;return n.wireTaps.push(t),function(){var i=n.wireTaps.indexOf(t);-1!==i&&n.wireTaps.splice(i,1)}},publish:function(n){return n.timeStamp=new Date,t.each(this.wireTaps,function(t){t(n.data,n)}),this.subscriptions[n.channel]&&t.each(this.subscriptions[n.channel],function(t){for(var i,s=0,c=t.length;c>s;)(i=t[s++])&&u(i,n)}),n},reset:function(){this.subscriptions&&(t.each(this.subscriptions,function(n){t.each(n,function(t){for(;t.length;)t.pop().unsubscribe()})}),this.subscriptions={})},subscribe:function(t){var n,i=this.subscriptions[t.channel];return i||(i=this.subscriptions[t.channel]={}),n=this.subscriptions[t.channel][t.topic],n||(n=this.subscriptions[t.channel][t.topic]=[]),n.push(t),t},subscriptions:{},wireTaps:[],unsubscribe:function(t){if(this.subscriptions[t.channel][t.topic])for(var n=this.subscriptions[t.channel][t.topic].length,i=0;n>i;i++)if(this.subscriptions[t.channel][t.topic][i]===t){this.subscriptions[t.channel][t.topic].splice(i,1);break}}};a.subscriptions[i]={};var h={configuration:{bus:a,resolver:o,DEFAULT_CHANNEL:n,SYSTEM_CHANNEL:i},ChannelDefinition:e,SubscriptionDefinition:r,channel:function(t){return new e(t)},subscribe:function(t){return new r(t.channel||n,t.topic,t.callback)},publish:function(t){return t.channel=t.channel||n,h.configuration.bus.publish(t)},addWireTap:function(t){return this.configuration.bus.addWireTap(t)},linkChannels:function(i,s){var c=[];return i=t.isArray(i)?i:[i],s=t.isArray(s)?s:[s],t.each(i,function(i){i.topic||"#",t.each(s,function(s){var e=s.channel||n;c.push(h.subscribe({channel:i.channel||n,topic:i.topic||"#",callback:function(n,i){var c=t.clone(i);c.topic=t.isFunction(s.topic)?s.topic(i.topic):s.topic||i.topic,c.channel=e,c.data=n,h.publish(c)}}))})}),c},utils:{getSubscribersFor:function(){var t=arguments[0],n=arguments[1];return 1===arguments.length&&(t=arguments[0].channel||h.configuration.DEFAULT_CHANNEL,n=arguments[0].topic),h.configuration.bus.subscriptions[t]&&h.configuration.bus.subscriptions[t].hasOwnProperty(n)?h.configuration.bus.subscriptions[t][n]:[]},reset:function(){h.configuration.bus.reset(),h.configuration.resolver.reset()}}};return h});
+(function(n,t){"object"==typeof module&&module.exports?module.exports=function(n){return n=n||require("underscore"),t(n)}:"function"==typeof define&&define.amd?define(["underscore"],function(i){return t(i,n)}):n.postal=t(n._,n)})(this,function(n){var t="/",i="postal",s=function(){var t;return function(i){var s=!1;return n.isString(i)?(s=i===t,t=i):(s=n.isEqual(i,t),t=n.clone(i)),!s}},c=function(){var t=[];return function(i){var s=!n.any(t,function(t){return n.isObject(i)||n.isArray(i)?n.isEqual(i,t):i===t});return s&&t.push(i),s}},e=function(n){this.channel=n||t};e.prototype.subscribe=function(){return 1===arguments.length?new r(this.channel,arguments[0].topic,arguments[0].callback):new r(this.channel,arguments[0],arguments[1])},e.prototype.publish=function(){var n=1===arguments.length?"[object String]"===Object.prototype.toString.call(arguments[0])?{topic:arguments[0]}:arguments[0]:{topic:arguments[0],data:arguments[1]};return n.channel=this.channel,h.configuration.bus.publish(n)};var r=function(n,t,s){this.channel=n,this.topic=t,this.callback=s,this.constraints=[],this.context=null,h.configuration.bus.publish({channel:i,topic:"subscription.created",data:{event:"subscription.created",channel:n,topic:t}}),h.configuration.bus.subscribe(this)};r.prototype={unsubscribe:function(){h.configuration.bus.unsubscribe(this),h.configuration.bus.publish({channel:i,topic:"subscription.removed",data:{event:"subscription.removed",channel:this.channel,topic:this.topic}})},defer:function(){var n=this.callback;return this.callback=function(t){setTimeout(function(){n(t)},0)},this},disposeAfter:function(t){if(n.isNaN(t)||0>=t)throw"The value provided to disposeAfter (maxCalls) must be a number greater than zero.";var i=this.callback,s=n.after(t,n.bind(function(){this.unsubscribe()},this));return this.callback=function(){i.apply(this.context,arguments),s()},this},distinctUntilChanged:function(){return this.withConstraint(new s),this},distinct:function(){return this.withConstraint(new c),this},once:function(){this.disposeAfter(1)},withConstraint:function(t){if(!n.isFunction(t))throw"Predicate constraint must be a function";return this.constraints.push(t),this},withConstraints:function(t){var i=this;return n.isArray(t)&&n.each(t,function(n){i.withConstraint(n)}),i},withContext:function(n){return this.context=n,this},withDebounce:function(t){if(n.isNaN(t))throw"Milliseconds must be a number";var i=this.callback;return this.callback=n.debounce(i,t),this},withDelay:function(t){if(n.isNaN(t))throw"Milliseconds must be a number";var i=this.callback;return this.callback=function(n){setTimeout(function(){i(n)},t)},this},withThrottle:function(t){if(n.isNaN(t))throw"Milliseconds must be a number";var i=this.callback;return this.callback=n.throttle(i,t),this},subscribe:function(n){return this.callback=n,this}};var o={cache:{},regex:{},compare:function(t,i){var s,c,e,r=this.cache[i]&&this.cache[i][t];return r!==undefined?r:((c=this.regex[t])||(s="^"+n.map(t.split("."),function(n){var t=e&&"#"!==e?"\\.\\b":"\\b";return t+="#"===n?"[A-Z,a-z,0-9,\\.]*":"*"===n?"[A-Z,a-z,0-9]+":n,e=n,t}).join("")+"$",c=this.regex[t]=RegExp(s)),this.cache[i]=this.cache[i]||{},this.cache[i][t]=r=c.test(i),r)},reset:function(){this.cache={},this.regex={}}},u=function(t,i){h.configuration.resolver.compare(t.topic,i.topic)&&n.all(t.constraints,function(n){return n.call(t.context,i.data,i)})&&"function"==typeof t.callback&&t.callback.call(t.context,i.data,i)},a={addWireTap:function(n){var t=this;return t.wireTaps.push(n),function(){var i=t.wireTaps.indexOf(n);-1!==i&&t.wireTaps.splice(i,1)}},publish:function(t){return t.timeStamp=new Date,n.each(this.wireTaps,function(n){n(t.data,t)}),this.subscriptions[t.channel]&&n.each(this.subscriptions[t.channel],function(n){for(var i,s=0,c=n.length;c>s;)(i=n[s++])&&u(i,t)}),t},reset:function(){this.subscriptions&&(n.each(this.subscriptions,function(t){n.each(t,function(n){for(;n.length;)n.pop().unsubscribe()})}),this.subscriptions={})},subscribe:function(n){var t,i=this.subscriptions[n.channel];return i||(i=this.subscriptions[n.channel]={}),t=this.subscriptions[n.channel][n.topic],t||(t=this.subscriptions[n.channel][n.topic]=[]),t.push(n),n},subscriptions:{},wireTaps:[],unsubscribe:function(n){if(this.subscriptions[n.channel][n.topic])for(var t=this.subscriptions[n.channel][n.topic].length,i=0;t>i;i++)if(this.subscriptions[n.channel][n.topic][i]===n){this.subscriptions[n.channel][n.topic].splice(i,1);break}}};a.subscriptions[i]={};var h={configuration:{bus:a,resolver:o,DEFAULT_CHANNEL:t,SYSTEM_CHANNEL:i},ChannelDefinition:e,SubscriptionDefinition:r,channel:function(n){return new e(n)},subscribe:function(n){return new r(n.channel||t,n.topic,n.callback)},publish:function(n){return n.channel=n.channel||t,h.configuration.bus.publish(n)},addWireTap:function(n){return this.configuration.bus.addWireTap(n)},linkChannels:function(i,s){var c=[];return i=n.isArray(i)?i:[i],s=n.isArray(s)?s:[s],n.each(i,function(i){i.topic||"#",n.each(s,function(s){var e=s.channel||t;c.push(h.subscribe({channel:i.channel||t,topic:i.topic||"#",callback:function(t,i){var c=n.clone(i);c.topic=n.isFunction(s.topic)?s.topic(i.topic):s.topic||i.topic,c.channel=e,c.data=t,h.publish(c)}}))})}),c},utils:{getSubscribersFor:function(){var n=arguments[0],t=arguments[1];return 1===arguments.length&&(n=arguments[0].channel||h.configuration.DEFAULT_CHANNEL,t=arguments[0].topic),h.configuration.bus.subscriptions[n]&&h.configuration.bus.subscriptions[n].hasOwnProperty(t)?h.configuration.bus.subscriptions[n][t]:[]},reset:function(){h.configuration.bus.reset(),h.configuration.resolver.reset()}}};return h});
View
4 src/SubscriptionDefinition.js
@@ -33,7 +33,9 @@ SubscriptionDefinition.prototype = {
defer : function () {
var fn = this.callback;
this.callback = function ( data ) {
- setTimeout( fn, 0, data );
+ setTimeout( function () {
+ fn( data );
+ }, 0 );
};
return this;
},
Something went wrong with that request. Please try again.