lib0
lib0 copied to clipboard
Please document that Observable.once does not respect Observable.off
Describe the bug A clear and concise description of what the bug is.
Observable.once creates a wrapper around the function, so calling Observable.off does not prevent it from being called.
let fn = ()=>{};
item.once('update', fn);
item.off('update', fn);
fn, will still be invoked under this scenario.
This seems to by design, so it should be documented that off will not prevent once from being called.
As a workaround, the callback function can use on and then remove itself when invoked, in order to be both callable once, and also removable.
let fn = ()=>{
item.off('update', fn);
};
item.on('update', fn);
item.off('update', fn);