You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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 theadd
method to overwrite old callbacks with the same name. Callbacks without a name won't be overwritten.Related: #459
The text was updated successfully, but these errors were encountered: