Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Flamenco opened this issue Jan 28, 2024 · 1 comment
Open
Assignees
Labels
bug Something isn't working

Comments

@Flamenco
Copy link

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 Flamenco added the bug Something isn't working label Jan 28, 2024
Flamenco added a commit to Flamenco/lib0 that referenced this issue Jan 28, 2024
@Flamenco
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants