Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#15315 closed defect (fixed)

setting one Stateful as the value of another copies `_watchCallbacks`

Reported by: ben hockey Owned by: Kris Zyp
Priority: undecided Milestone: 1.8
Component: Core Version: 1.7.2
Keywords: Cc: Kitson Kelly
Blocked By: Blocking:

Description

when setting one Stateful as the value for another, the watchers of the Stateful being passed are then also effectively watching the Stateful that is being set. the diff below is for tests/Stateful.js to demonstrate the problem

  • tests/Stateful.js

     
    2020                doh.is(5, s.get("foo"));
    2121        },
    2222        function setHash(t){
    23                 var s = new dojo.Stateful();
     23                var s = new dojo.Stateful(),
     24                        fooCount = 0,
     25                        handle = s.watch('foo', function () {
     26                                fooCount++;
     27                        });
    2428                s.set({
    2529                        foo:3,
    2630                        bar: 5
    2731                });
    2832                doh.is(3, s.get("foo"));
    2933                doh.is(5, s.get("bar"));
     34                doh.is(1, fooCount);
    3035                var s2 = new dojo.Stateful();
    3136                s2.set(s);
    3237                doh.is(3, s2.get("foo"));
    3338                doh.is(5, s2.get("bar"));
     39                // s watchers should not be copied to s2
     40                doh.is(1, fooCount);
     41                handle.unwatch();
    3442        },
    3543        function wildcard(t){
    3644                var s = new dojo.Stateful();

i found this while looking at #15187 but since this issue has existed all along i opened it as a new ticket.

Change History (3)

comment:1 Changed 8 years ago by bill

Cc: Kitson Kelly added
Owner: set to Kris Zyp
Status: newassigned

Guess this should be assigned to Kris unless Kitson wants to fix it.

comment:2 Changed 7 years ago by Kris Zyp

Resolution: fixed
Status: assignedclosed

In [29038]:

Don't copy watch callbacks, fixes #15315 !strict

comment:3 Changed 7 years ago by bill

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