ZiadJ / knockoutjs-reactor

Recursively tracks changes within a view model no matter how deeply nested the observables are or whether they are nested within dynamically created array elements.
Other
74 stars 22 forks source link

Bad parents in the notifications when sub-objects are replaced #47

Closed bago closed 7 years ago

bago commented 7 years ago
var subModel = {
  c: ko.observable(1),
  d: ko.observable(0)
};

var subModelB = {
  e: ko.observable(0),
  f: ko.observable(1)
};

var model = {
  a: ko.observable(1),
  b: {
    g: ko.observable(0),
    h: ko.observable(0),
  },
  sub: ko.observable(subModel),
};

var w = ko.watch(model, { depth: -1, oldValues: 1, mutable: true, tagFields: true }, listener);

model.sub().c(4); // this is notified correctly

model.sub(subModelB);
model.sub().e(4); // this is notified with the wrong number of parents

Once you replace an observable object the new notifications have one more "parent" that is not expected.