Permalink
Browse files

0.3.0 build of knockout-postbox

  • Loading branch information...
1 parent 0c673ef commit 8b7e96726ae8179880bcda65476def30b61e1c3d @rniemeyer committed Mar 1, 2013
Showing with 8 additions and 5 deletions.
  1. +6 −3 build/knockout-postbox.js
  2. +2 −2 build/knockout-postbox.min.js
@@ -1,4 +1,4 @@
-//knockout-postbox v0.2.4 | (c) 2012 Ryan Niemeyer | http://www.opensource.org/licenses/mit-license
+//knockout-postbox 0.3.0 | (c) 2013 Ryan Niemeyer | http://www.opensource.org/licenses/mit-license
!(function(factory) {
//CommonJS
if (typeof require === "function" && typeof exports === "object" && typeof module === "object") {
@@ -19,13 +19,16 @@
//keep a cache of the latest value and subscribers
exports.topicCache = {};
+ //allow customization of the function used to serialize values for the topic cache
+ exports.serializer = ko.toJSON;
+
//wrap notifySubscribers passing topic first and caching latest value
exports.publish = function(topic, value) {
if (topic) {
//keep the value and a serialized version for comparison
exports.topicCache[topic] = {
value: value,
- serialized: ko.toJSON(value)
+ serialized: exports.serializer(value)
};
exports.notifySubscribers(value, topic);
}
@@ -41,7 +44,7 @@
//by default publish when the previous cached value does not equal the new value
exports.defaultComparer = function(newValue, cacheItem) {
- return cacheItem && newValue === cacheItem.value && ko.toJSON(newValue) === cacheItem.serialized;
+ return cacheItem && exports.serializer(newValue) === cacheItem.serialized;
};
//augment observables/computeds with the ability to automatically publish updates on a topic
@@ -1,2 +1,2 @@
-//knockout-postbox v0.2.4 | (c) 2012 Ryan Niemeyer | http://www.opensource.org/licenses/mit-license
-!function(e){typeof require=="function"&&typeof exports=="object"&&typeof module=="object"?e(require("knockout"),exports):typeof define=="function"&&define.amd?define(["knockout","exports"],e):e(ko,ko.postbox={})}(function(e,t,n){var r,i;e.subscribable.call(t),t.topicCache={},t.publish=function(n,r){n&&(t.topicCache[n]={value:r,serialized:e.toJSON(r)},t.notifySubscribers(r,n))},i=t.subscribe,t.subscribe=function(e,n,r){if(e)return i.call(t,n,r,e)},t.defaultComparer=function(t,n){return n&&t===n.value&&e.toJSON(t)===n.serialized},e.subscribable.fn.publishOn=function(e,n,i){var s;return e&&(typeof n=="function"?i=n:s=n,i=i||t.defaultComparer,r.call(this,e,"publishOn"),this.postboxSubs[e].publishOn=this.subscribe(function(n){i.call(this,n,t.topicCache[e])||t.publish(e,n)},this),s||t.publish(e,this())),this},r=function(e,t){var n=this.postboxSubs=this.postboxSubs||{};n[e]=n[e]||{},n[e][t]&&n[e][t].dispose()},e.subscribable.fn.stopPublishingOn=function(e){return r.call(this,e,"publishOn"),this},e.subscribable.fn.subscribeTo=function(i,s,o){var u,a,f,l=this;return typeof s=="function"?o=s:u=s,i&&e.isWriteableObservable(this)&&(r.call(this,i,"subscribeTo"),f=function(e){l(o?o.call(l,e):e)},this.postboxSubs[i].subscribeTo=t.subscribe(i,f),u&&(a=t.topicCache[i],a!==n&&f(a.value))),this},e.subscribable.fn.unsubscribeFrom=function(e){return r.call(this,e,"subscribeTo"),this},e.subscribable.fn.syncWith=function(e,t,n,r){return this.subscribeTo(e,t).publishOn(e,n,r),this}})
+//knockout-postbox 0.3.0 | (c) 2013 Ryan Niemeyer | http://www.opensource.org/licenses/mit-license
+!function(e){typeof require=="function"&&typeof exports=="object"&&typeof module=="object"?e(require("knockout"),exports):typeof define=="function"&&define.amd?define(["knockout","exports"],e):e(ko,ko.postbox={})}(function(e,t,n){var r,i;e.subscribable.call(t),t.topicCache={},t.serializer=e.toJSON,t.publish=function(e,n){e&&(t.topicCache[e]={value:n,serialized:t.serializer(n)},t.notifySubscribers(n,e))},i=t.subscribe,t.subscribe=function(e,n,r){if(e)return i.call(t,n,r,e)},t.defaultComparer=function(e,n){return n&&t.serializer(e)===n.serialized},e.subscribable.fn.publishOn=function(e,n,i){var s;return e&&(typeof n=="function"?i=n:s=n,i=i||t.defaultComparer,r.call(this,e,"publishOn"),this.postboxSubs[e].publishOn=this.subscribe(function(n){i.call(this,n,t.topicCache[e])||t.publish(e,n)},this),s||t.publish(e,this())),this},r=function(e,t){var n=this.postboxSubs=this.postboxSubs||{};n[e]=n[e]||{},n[e][t]&&n[e][t].dispose()},e.subscribable.fn.stopPublishingOn=function(e){return r.call(this,e,"publishOn"),this},e.subscribable.fn.subscribeTo=function(i,s,o){var u,a,f,l=this;return typeof s=="function"?o=s:u=s,i&&e.isWriteableObservable(this)&&(r.call(this,i,"subscribeTo"),f=function(e){l(o?o.call(l,e):e)},this.postboxSubs[i].subscribeTo=t.subscribe(i,f),u&&(a=t.topicCache[i],a!==n&&f(a.value))),this},e.subscribable.fn.unsubscribeFrom=function(e){return r.call(this,e,"subscribeTo"),this},e.subscribable.fn.syncWith=function(e,t,n,r){return this.subscribeTo(e,t).publishOn(e,n,r),this}})

0 comments on commit 8b7e967

Please sign in to comment.