diff --git a/lib/postal.when.js b/lib/postal.when.js index 083e09e..de554ea 100644 --- a/lib/postal.when.js +++ b/lib/postal.when.js @@ -62,6 +62,10 @@ _subscriptions = []; }; _.each(queue, function (sub) { + // Add no-op callback for subscriptions with undefined callbacks. + if (!sub.callback) { + sub.callback = function () {}; + } var subscriptionDefinition = postal.subscribe(sub); subscriptionDefinition.data = undefined; subscriptionDefinition.subscribe(function (data) { diff --git a/lib/postal.when.min.js b/lib/postal.when.min.js index 94fc6e7..a6c41dd 100644 --- a/lib/postal.when.min.js +++ b/lib/postal.when.min.js @@ -5,4 +5,4 @@ * Url: http://github.com/postaljs/postal.when * License(s): MIT */ -(function(t,n){"object"==typeof module&&module.exports?module.exports=function(t){return n(require("underscore"),t,this)}:"function"==typeof define&&define.amd?define(["underscore","postal"],function(e,o){return n(e,o,t)}):t.postal=n(t._,t.postal,t)})(this,function(t,n,e,o){var i=function(e,i,u,c){var a,r=this,s="[object Function]"===Object.prototype.toString.call(u)?u:function(){},f="[object Object]"===Object.prototype.toString.call(u)?u:c||{},p=[],d=function(){f.timeout&&(a=setTimeout(function(){s({type:"timeout",data:t.pluck(p,"data")})},f.timeout))},l=function(){t.each(p,function(t){t.data=o})},b=function(){var n=t.pluck(p,"data");t.all(n,t.identity)&&(clearTimeout(a),i.apply(this,n),f.once?r.dispose():(l(),d()))};r.dispose=function(){t.each(p,function(t){t.unsubscribe()}),p=[]},t.each(e,function(t){var e=n.subscribe(t);e.data=o,e.subscribe(function(t){e.data=t,b()}),p.push(e)}),d()};return n.when=function(t,n,e,o){return new i(t,n,e,o)},n}); \ No newline at end of file +(function(t,n){"object"==typeof module&&module.exports?module.exports=function(t){return n(require("underscore"),t,this)}:"function"==typeof define&&define.amd?define(["underscore","postal"],function(e,o){return n(e,o,t)}):t.postal=n(t._,t.postal,t)})(this,function(t,n,e,o){var c=function(e,c,i,u){var a,r=this,f="[object Function]"===Object.prototype.toString.call(i)?i:function(){},s="[object Object]"===Object.prototype.toString.call(i)?i:u||{},l=[],p=function(){s.timeout&&(a=setTimeout(function(){f({type:"timeout",data:t.pluck(l,"data")})},s.timeout))},d=function(){t.each(l,function(t){t.data=o})},b=function(){var n=t.pluck(l,"data");t.all(n,t.identity)&&(clearTimeout(a),c.apply(this,n),s.once?r.dispose():(d(),p()))};r.dispose=function(){t.each(l,function(t){t.unsubscribe()}),l=[]},t.each(e,function(t){t.callback||(t.callback=function(){});var e=n.subscribe(t);e.data=o,e.subscribe(function(t){e.data=t,b()}),l.push(e)}),p()};return n.when=function(t,n,e,o){return new c(t,n,e,o)},n}); \ No newline at end of file diff --git a/spec/postalwhen.spec.js b/spec/postalwhen.spec.js index 50e4f87..3049b3f 100755 --- a/spec/postalwhen.spec.js +++ b/spec/postalwhen.spec.js @@ -1,9 +1,9 @@ /* global describe, postal, it, after, before, expect */ (function(global) { - var postal = typeof window === "undefined" ? require("../bower/postal.js/lib/postal.js") : window.postal; + var postal = typeof window === "undefined" ? require("postal") : window.postal; var expect = typeof window === "undefined" ? require("expect.js") : window.expect; var _ = typeof window === "undefined" ? require("underscore") : window._; - var postalWhen = typeof window === "undefinde" ? require("../lib/postal.when.js")(postal) : window.postal; + var postalWhen = typeof window === "undefined" ? require("../lib/postal.when.js")(postal) : window.postal; var subscription; var sub; var channel; @@ -182,4 +182,4 @@ } ); } ); -}()); \ No newline at end of file +}()); diff --git a/src/when.js b/src/when.js index 94dafa8..7b57093 100755 --- a/src/when.js +++ b/src/when.js @@ -41,6 +41,10 @@ var ForkJoin = function ( queue, onSuccess, onError, options ) { }; _.each( queue, function ( sub ) { + // Add no-op callback for subscriptions with undefined callbacks. + if (!sub.callback) { + sub.callback = function () {}; + } var subscriptionDefinition = postal.subscribe( sub ); subscriptionDefinition.data = undefined; subscriptionDefinition.subscribe( function ( data ) {