rniemeyer / knockout-postbox

A small library that uses Knockout's native pub/sub capabilities to facilitate decoupled communication between separate view models or components.
MIT License
350 stars 55 forks source link

Execution time, serialization, large data and topicCache #10

Closed vamp closed 11 years ago

vamp commented 11 years ago

Large amount of data (100+kb) increases execution time up to 185x + Perhaps there is a need for serialized variable configuration, like:

exports.serializer = ko.toJSON // by default

but if i work only with js-like data, i can do:

postbox.serializer = JSON.stringify
// ko.subscribable.fn.toJSON = function(){ return this.peek(); }

my benchmark:

  ko: 22.469ms
json: 1.511ms
noop: 0.115ms 
rniemeyer commented 11 years ago

Seems reasonable to be able to configure it. I will look at adding this in.

rniemeyer commented 11 years ago

The serializer is now exposed as ko.postbox.serializer. This could be used to use JSON.stringify or even simply returning an empty object {} would force it to publish every time without needing to process the data at all.