From 2c89eb3eb958ae8ae08454b829b642c14afb03dc Mon Sep 17 00:00:00 2001 From: joashc Date: Fri, 24 Oct 2014 13:06:35 +1100 Subject: [PATCH 1/4] Added no-op callbacks to subscriptions with undefined callbacks. Fixes Issue #3: "You can only make functions into Conduits." https://github.com/postaljs/postal.when/issues/3 --- src/when.js | 4 ++++ 1 file changed, 4 insertions(+) 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 ) { From cdfeceeb1639aa36cecb41e54ed7844b06f08e86 Mon Sep 17 00:00:00 2001 From: joashc Date: Fri, 24 Oct 2014 15:35:00 +1100 Subject: [PATCH 2/4] Fixed typo in test spec --- spec/postalwhen.spec.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/postalwhen.spec.js b/spec/postalwhen.spec.js index 50e4f87..c784a34 100755 --- a/spec/postalwhen.spec.js +++ b/spec/postalwhen.spec.js @@ -3,7 +3,7 @@ var postal = typeof window === "undefined" ? require("../bower/postal.js/lib/postal.js") : 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 +}()); From d723e82562e347b3bef71efff1c40670a1aeebaf Mon Sep 17 00:00:00 2001 From: joashc Date: Fri, 24 Oct 2014 16:05:37 +1100 Subject: [PATCH 3/4] Use npm postal dependency --- spec/postalwhen.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/postalwhen.spec.js b/spec/postalwhen.spec.js index c784a34..3049b3f 100755 --- a/spec/postalwhen.spec.js +++ b/spec/postalwhen.spec.js @@ -1,6 +1,6 @@ /* 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 === "undefined" ? require("../lib/postal.when.js")(postal) : window.postal; From cdcd0313a66cb2196289f4d3016d4b522aa8f931 Mon Sep 17 00:00:00 2001 From: joashc Date: Fri, 24 Oct 2014 16:06:22 +1100 Subject: [PATCH 4/4] Rebuild package to update /lib --- lib/postal.when.js | 4 ++++ lib/postal.when.min.js | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) 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