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

Add a way to remove hooks #1993

Open
RunDevelopment opened this issue Jul 21, 2019 · 1 comment
Open

Add a way to remove hooks #1993

RunDevelopment opened this issue Jul 21, 2019 · 1 comment

Comments

@RunDevelopment
Copy link
Member

RunDevelopment commented Jul 21, 2019

Motivation
Sometimes Prism has to reload languages (and soon plugins). This is a problem because the added hooks cannot be removed which will lead to multiple runs of the same hook.

Even if this doesn't cause highlighting issues, it's just unnecessary CPU time to execute the same hook multiple times.

Description
Require all callbacks added to a specific hook to have a name. The name of a callback should be the id of the language/plugin which added it.
If no name is provided, the callback will still be added but cannot be removed.

A new method Prism.hooks.remove(name: string): void can then be used to remove the callbacks of all hooks with the given name.

Alternatives
Instead of introducing a remove method, we could modify the add method to overwrite old callbacks with the same name. Callbacks without a name won't be overwritten.


Related: #459

@RunDevelopment
Copy link
Member Author

This is a problem because the added hooks cannot be removed which will lead to multiple runs of the same hook.

#2716 was caused by exactly this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant