lib0 icon indicating copy to clipboard operation
lib0 copied to clipboard

Please document that Observable.once does not respect Observable.off

Open Flamenco opened this issue 2 years ago • 1 comments

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.

Flamenco avatar Jan 28 '24 22:01 Flamenco

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);

Flamenco avatar Jan 28 '24 22:01 Flamenco