subscription event types - documentation

35 views
Skip to first unread message

Ian Yates

unread,
Apr 25, 2015, 7:52:18 AM4/25/15
to knock...@googlegroups.com
Inspired by an earlier thread on this forum (https://groups.google.com/forum/#!topic/knockoutjs/M4SpXo8cbhU) I thought I'd go out and learn more about the trackArrayChanges extender... 
The best I could find was here

Based on Michael's answer I dug a bit in to knockout-3.3.0-debug.js and can see where this extender is used (observable arrays by default) and what that extender does.  However I then figured that bindings like foreach might take advantage of this, and it appears they don't.

So...
1. Should these event types be documented somewhere on knockoutjs.com?  This page: http://knockoutjs.com/documentation/observables.html#explicitly-subscribing-to-observables talks about the change and beforeChange events, but that's about it.  I suspect there may be more as they come up from time to time in various GitHub issue discussions but I can't find much on the net about them.  I've got by with Knockout and not knowing this for many months so I suspect they're used in niche cases, but it's unsettling not quite understanding something a library I'm using :)

2. What benefit comes from arrayChange event being raised?  I assumed the foreach binding would use it, but arrayChange doesn't appear anywhere else in the knockout debug javascript file apart from within that extender.  Am I missing something?

Thanks...  :)


Update:  Some extra Google/Bing fu found Steve's blog post from 3.0 RC where the arrayChange stuff is discussed. http://blog.stevensanderson.com/2013/10/08/knockout-3-0-release-candidate-available/
Ryan's blog post about ko.utils talks about the ko.utils.compareArrays function, which has a similar purpose but is not O(1) like the arrayChange (sometimes) is.

Still are there other events, and if so, is there somewhere we can go to get a summary of them?

Michael Best

unread,
Apr 27, 2015, 8:10:13 PM4/27/15
to knock...@googlegroups.com
The only other events (starting with version 3.3.0) are "awake" and "asleep" which are minimally documented here: http://knockoutjs.com/documentation/computed-pure.html#state-change-notifications

There's an interesting plugin that uses those events: https://github.com/danielearwicker/knockout.clear

-- Michael

Ian Yates

unread,
Apr 27, 2015, 8:26:36 PM4/27/15
to knock...@googlegroups.com
Hi Michael,

Thanks for the advice :)

I had been following the issue thread that lead to the creation of that plugin - I've got it bookmarked to really try it out properly when I get some spare time.  That solution to the disposal issue seems to be quite elegant...

Cheers,
Ian
Reply all
Reply to author
Forward
0 new messages