Skip to content

Conversation

@chrisinajar
Copy link

@chrisinajar chrisinajar commented Oct 19, 2017

A has a nested struct B, B updates itself inside it's own handler, A will have a broken inconsistent state such that A().B !== A.B()

It seems to be caused by event queuing causing the internal state copy to contain an old version and not receiving the new version for reasons.

The fix I wrote simply takes the current value of the nested observable instead of the value passed into the event handler since that value is no longer accurate since the value was updated in the previous listener of that same change event (which is not not re-emitted for reasons, but this is actually somewhat ideal)

@chrisinajar
Copy link
Author

Simplest possible repro case I could manage to get working, the test cases I wrote are more thorough

var Struct = require('observ-struct');
var Value = require('observ');

var base = Struct({
  nested: Nested()
});

function Nested () {
  var struct = Struct({
    foo: Value(null),
    bar: Value(false)
  });

  struct(function () {
    if (struct().foo && !struct.bar()) {
      struct.bar.set(true);
    }
  });

  setTimeout(function() {
    struct.foo.set(true);
  })

  return struct;
}

setTimeout(function() {
  console.log("These are different even though they shouldn't be!", base().nested.bar, base.nested().bar);
}, 100);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant