Add a constructor option to the field that specifies a debounce delay, allowing for listeners to be called after a delay.
This is mostly useful in order to not have any invariants broken when listeners are executing;
class A {
// Invariant: b = a + 5;
protected a = new Field(0);
protected b = new Field(5);
setA(value: number){
this.a.set(value);
// Now field a is invoking all its listeners, which may want to use this instance.
// But currently the invariant on which correctness of this class may rely is not met.
this.b.set(value+5);
}
}
By debouncing the listener invocation for 0ms by default, It would only call listeners after the synchronous changes finished. This behavior seems more intuitive to me. If your function is asynchronous, you will still need to consider that other code can execute inbetween parts, but that's always the case.
Add a constructor option to the field that specifies a debounce delay, allowing for listeners to be called after a delay. This is mostly useful in order to not have any invariants broken when listeners are executing;
By debouncing the listener invocation for 0ms by default, It would only call listeners after the synchronous changes finished. This behavior seems more intuitive to me. If your function is asynchronous, you will still need to consider that other code can execute inbetween parts, but that's always the case.