sproutcore/sproutcore — Issue #715: SC.ManyArray leaks observers into the stores data hashes
Author: mauritslamers
Created: 2012-02-10 16:06:47+00:00
State: open
Labels: datastore

I always assumed that the datahashes in SC.Store were as free as possible from SC additives, but it turns out that SC.ManyArray adds observers to arrays in the datahashes.

My server client can partially update hashes, for example when relations on the server have changed. However, it turns out these changes systematically will not cause updates of data in SC.ManyArrays, because the arrays observers don't fire.

Looking at the way SC.ManyArray puts observers on the arrays with ids, it showed that SC.ManyArray takes the data from the record using readAttribute which directly returns the data from the property. As this is a pointer (and not a value, because it is an object) and SC.ManyArray is directly using and storing this pointer, it turned out that it was actually loading observers onto the stores data hashes.

This causes problems because when taking a datahash out of the store, adjusting it using the normal JS methods and pushing it back into the store with pushRetrieve, as this process will not fire the observers on these arrays.
While I can use the SC.Array methods when working with the data hashes, I cannot help but feel that this is a very dirty and unnecessary workaround. Moreover, when I use pushRetrieve stuff into the store, I would expect all changes to be picked up.

It would be a much cleaner design if SC.ManyArray worked like a SC.RecordArray.