Closed sorvell closed 11 years ago
Given the following example, an iloop is generated.
Is this expected and if so, do we have a better way to achieve the desired A to B to A type of binding?
var A = { foo: 0 }; var B = { foo: 0 }; // Model.observe(A, 'foo', function(inNew) { if (loops++ > 5) { console.error("propagation circularity, aborting"); return; } console.log('propagating A.foo to B.foo; A.foo == %s, inNew = %s', A.foo, inNew); B.foo = inNew; }); Model.observe(B, 'foo', function(inNew) { console.log('propagating B.foo to A.foo; B.foo == %s, inNew = %s', B.foo, inNew); A.foo = inNew; }); // loops = 0; A.foo = 1; // adding this dirtyCheck avoids the iloop // Model.dirtyCheck() B.foo = 2; Model.dirtyCheck();
If MDV's proper semantics are to play back a history of changes as they occured, then the problem is entirely in your test code.
I don't think there's any way to prevent this, and we shouldn't attempt it.
Given the following example, an iloop is generated.
Is this expected and if so, do we have a better way to achieve the desired A to B to A type of binding?
var A = { foo: 0 }; var B = { foo: 0 }; // Model.observe(A, 'foo', function(inNew) { if (loops++ > 5) { console.error("propagation circularity, aborting"); return; } console.log('propagating A.foo to B.foo; A.foo == %s, inNew = %s', A.foo, inNew); B.foo = inNew; }); Model.observe(B, 'foo', function(inNew) { console.log('propagating B.foo to A.foo; B.foo == %s, inNew = %s', B.foo, inNew); A.foo = inNew; }); // loops = 0; A.foo = 1; // adding this dirtyCheck avoids the iloop // Model.dirtyCheck() B.foo = 2; Model.dirtyCheck();