Closed fbuchinger closed 12 years ago
@fbuchinger Sorry to not get back to your earlier on this one. I suppose that one option would be to put your publishOn
onto a computed that actually returns an object that has the value along with the extra context. Then, in your subscribeTo
, you could specify a transform to look at the context and determine the final boolean. Does that make sense?
thanks for this interesting approach... Could you give a tiny example? I thought subscribeTo just receives the "naked" value, not the observable/computed itself.
After playing around a bit, I managed to figure it out on my own! Many thanks for your advice!
@fbuchinger ok- great. Sorry that I hadn't had a chance to respond. Let me know if you have more issues/questions.
In my app I've modelled a web form as a hierarchic structure of fields, groupds and the form. When I change the visibility of a group, all contained fields should also be invisible (same goes for editibility). As I want a loose coupling between my sub-models, I decided to use PubSub/ko.postbox.
But my problem is that the
publishOn
/ 'subscribeTo' methods are lacking context information for this task.subscribeTo
just gives me the newValue of the "observed observable", but not its id or other properties. I need this information e.g. to determine if a field is contained in a hidden group.Sure I could add the identifier (name) of the property to the channel name, but I want to avoid this, so that I can subscribe to the
group:visibility:change
event in general (e.g. perform an action every time the visibility of the group changes)Any idea how i could enhance the event handler context with the needed info?