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

The 'notify always' extender does not work for published topics #27

Closed neo-headz closed 10 years ago

neo-headz commented 10 years ago

It would be nice if the published postbox observables had the ability to notify subscribers always, just like normal observables. See this fiddle: http://jsfiddle.net/headz68/Aw9B5/

rniemeyer commented 10 years ago

@headz68 - postbox doesn't work directly with the notify extender, but does support its own equality comparer option either globally or for anything extended with publishOn. Your definition would look like:

    myTopic = ko.observable(originalVal).publishOn('myTopic', function () { return true; }),

The function takes in the value to be published as an argument and returns true/false for whether to publish the value.

Hope that helps!

neo-headz commented 10 years ago

@rniemeyer thanks for the response! Unfortunately your suggestion did not work. I updated http://jsfiddle.net/headz68/Aw9B5/ I also tried using

 myTopic = ko.observable(originalVal).publishOn('myTopic', false, function () { return true; }),

Nonetheless, I have a workaround in place but seems like there should be other experiencing this issue.

rniemeyer commented 10 years ago

@headz68 - I guess that I had it a bit off. The equality comparer returns whether the new/prev values are equal. So, we would want to return false. Additionally, without the notify: always the publish would never be attempted on primitive values that are the same. Would need to be like: http://jsfiddle.net/3H37j/ Sounds like you solved your issue, but I wanted to clarify.

neo-headz commented 10 years ago

@rniemeyer Thanks!