Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#14273 closed defect (fixed)

Observable doesn't support nested callbacks, this is undocumented behavior.

Reported by: Bruno Deferrari Owned by: Kris Zyp
Priority: high Milestone: 1.8
Component: Documentation Version: 1.7.0
Keywords: Cc:
Blocked By: Blocking:


When wrapping a store with Observable, and setting one or more observe callbacks, calling a put/remove/add from inside the callback modifies the store but does not notify observers.

Looking at the code, this seems to be on purpose (is this necessary?), but the behavior is a bit surprising and undocumented (here:

Change History (7)

comment:1 Changed 9 years ago by Bruno Deferrari

#13445 seems to be related to this.

comment:2 Changed 9 years ago by bill

Owner: set to Kris Zyp

Probably the code you are talking about is the part the prevents a double notify when store.add() calls store.put() (or vice-versa)?

comment:3 Changed 9 years ago by Bruno Deferrari

Correct, an inMethod variable is used to prevent nested calls. Is avoiding a double notify on store.add the only reason for this? If thats it, then thats good news, I will try to figure out a way to remove the limitation for other calls.

Here is the code (unmodified) I'm talking about (dojo/store/Observable.js, 1.7.0b6):

        var inMethod;
        function whenFinished(method, action){
                var original = store[method];
                        store[method] = function(value){
                                        // if one method calls another (like add() calling put()) we don't want two events
                                        return original.apply(this, arguments);
                                inMethod = true;
                                        var results = original.apply(this, arguments);
                                        Deferred.when(results, function(results){
                                                action((typeof results == "object" && results) || value);
                                        return results;
                                        inMethod = false;
Last edited 9 years ago by Bruno Deferrari (previous) (diff)

comment:4 Changed 9 years ago by Bruno Deferrari

Sorry, by "nested calls" y mean "nested notifications".

comment:5 Changed 9 years ago by bill

Milestone: tbd

comment:6 Changed 9 years ago by Kris Zyp

Resolution: fixed
Status: newclosed

The double notify on store.add is an example of the type multiple notification that this is intended to avoid. It is assumed that stores could have more complex implementations of put and add that perform various calls to each other, and there should be a single notification for the action.

I updated to indicate this.

comment:7 Changed 9 years ago by bill

Milestone: tbd1.8
Note: See TracTickets for help on using tickets.