After hours of testing, it turns out that to observe changes in Memory Store
, you have to add / remove / update
objects through Observable object not through the Memory
.
This means you have two options to implement this
.
var inventoryStore = new Memory({data:inventory, idProperty:"name"});
var observer = new Observable(inventoryStore);
results = observer.query({});
observer.put(someObject);
or
var inventoryStore = new Observable(new Memory({data:inventory, idProperty:"name"});
results = inventoryStore.query({});
inventoryStore.put(someObject);
This may seem obvious but I was confused following the tutorial under this link.
http://www.tulek.org/2011/04/14/dojo-memory-and-observable-classes/
In addition,
observer.setData(another Inventory);
does not fire the observe()
method but just change data store in the observer. This causes mismatching
data store between Observable and Memory Store
since Memory Store still has the original inventory set.
The reason why some of my object couldn't be stored in Observable
was that I used dojo/calendar/Calendar
and it had a reference to some of the objects from the Memory that call some weird method due to property name mismatched.
I hope none of you people suffer from this matter. :)