subscribe semantics wrong?

29 views
Skip to first unread message

Greg Veres

unread,
Jan 13, 2017, 10:12:28 AM1/13/17
to KnockoutJS
Hi

I am using subscribe for the first time and to me the semantics of the value passed into the subscribe callback are wrong. From my testing and from the excellent documentation on the knockoutjs.com site, it seems that if you subscribe to the value change "after" it has been changed, the value that is passed in is the "new value" and if you subscribe to the beforeChanged event, then the value passed in is the "old value". That seems backwards to what would be really useful. 

For instance, wouldn't it be so much more useful if beforeChanged passed in the new value? I can always look up the old value because before the change, the old value is still sitting in the observable. 
And shouldn't the afterChanged pass in the old value? because again, I can look up then new value because it is sitting in the observable. 

if beforeChanged got the new value as an argument and afterChanged got the old value as an argument, then we would be able to do comparisons easily between what it was and what it will become without having to try to do two subscriptions and save the oldValue in between. And the documentation even warns that these wont always come in pairs so even that doesn't really work. 

Anyway, just wondering what I am missing in my understanding as to why it is the way it is. 

I realize that now it is probably next to impossible to change the behaviour. :(

Thanks
Greg

Michael Best

unread,
Jan 13, 2017, 4:46:46 PM1/13/17
to KnockoutJS
See https://github.com/knockout/knockout/issues/914. There are examples there of how to create a "subscribe" that works closer to what you want.

Greg Veres

unread,
Jan 13, 2017, 5:25:15 PM1/13/17
to knock...@googlegroups.com
That’s an interesting thread. Thanks for pointing it out

Reply all
Reply to author
Forward
0 new messages