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

ko.postbox.subscribe initializeWithLatestValue #20

Closed vdlindk closed 10 years ago

vdlindk commented 10 years ago

Hello,

I'm using ko.postbox together with ko-amd-helpers. When I reload a module with subscriptions that are initialized I ran into the problem that the handler linked to the subscription is executed in the global context. I expected that the handler was executed in the target-context.

I solved this issue by changing line 53 of knockout-postbox.js from 'action(current.value);' with 'action.call(target, current.value);'

I don't know if this change breaks any other code of your javascript since I'm using only using the basic functionalities of knockout-postbox.js (ko.postbox.subscribe and ko.postbox.publish).

kind regards,

Koen

rniemeyer commented 10 years ago

@vdlindk - thanks for reporting this one. not useful/correct for it to not use the target. Thanks!