-
Notifications
You must be signed in to change notification settings - Fork 220
DOC-2898: Documentation enhancements: for https://www.tiny.cloud/docs/tinymce/latest/custom-toggle-toolbar-button/ #4071
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
Open
jeslynbo
wants to merge
8
commits into
tinymce/8
Choose a base branch
from
hotfix/8/testingPR
base: tinymce/8
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+35
−22
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
99befda
DOC-2898: Documentation enhancements: for https://www.tiny.cloud/docs…
2356bb2
DOC-2898: Clarify usage of onSetup in documentation with improved des…
f69b987
Update modules/ROOT/pages/custom-toggle-toolbar-button.adoc
jeslynbo b86bc22
Update modules/ROOT/pages/custom-toggle-toolbar-button.adoc
jeslynbo f7a5c5c
Update modules/ROOT/pages/custom-toggle-toolbar-button.adoc
jeslynbo 2d6f721
Update modules/ROOT/pages/custom-toggle-toolbar-button.adoc
jeslynbo 9867581
Update modules/ROOT/pages/custom-toggle-toolbar-button.adoc
jeslynbo fdf2615
Update modules/ROOT/partials/misc/onSetup.adoc
jeslynbo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,27 @@ | ||
| [[using-onsetup]] | ||
| == Using `+onSetup+` | ||
|
|
||
| `+onSetup+` is a complex property. It takes a function that is passed the component's API and should return a callback that is passed the component's API and returns nothing. This occurs because `+onSetup+` runs whenever the component is rendered, and the returned callback is executed when the component is destroyed. This is essentially an `+onTeardown+` handler, and can be used to unbind events and callbacks. | ||
| `+onSetup+` accepts a function that receives the component’s API. This function should return a callback that returns nothing after being passed the component’s API. This occurs because `+onSetup+` runs whenever the component is rendered, and the callback returned by `+onSetup+` is executed when the component is destroyed. The function returned from `+onSetup+` is essentially an `+onTeardown+` handler, and can be used to unbind events and callbacks. | ||
|
|
||
| To clarify, in code `+onSetup+` may look like this: | ||
|
|
||
| [source,js] | ||
| ---- | ||
| onSetup: (api) => { | ||
| // Do something here on component render, like set component properties or bind an event listener | ||
| // Runs when the component is created | ||
| // Configure the component or bind event listeners | ||
|
|
||
| return (api) => { | ||
| // Do something here on teardown, like unbind an event listener | ||
| // Runs when the component is destroyed | ||
| // Unbind event listeners or clean up resources | ||
| }; | ||
| }; | ||
| ---- | ||
|
|
||
| To bind a callback function to an editor event use `+editor.on(eventName, callback)+`. To unbind an event listener use `+editor.off(eventName, callback)+`. Any event listeners _should_ be unbound in the teardown callback. The only editor event which does not need to be unbound is `+init+` e.g. `+editor.on('init', callback)+`. | ||
| To bind a callback function to an editor event use xref:apis/tinymce.editor.adoc#on[`+editor.on(eventName, callback)+`]. To unbind an event listener use xref:apis/tinymce.editor.adoc#off[`+editor.off(eventName, callback)+`]. Any event listeners _should_ be unbound in the teardown callback. The only editor event which does not need to be unbound is `+init+` e.g. `+editor.on('init', callback)+`. | ||
|
|
||
| [NOTE] | ||
| ==== | ||
| * The callback function for `+editor.off()+` should be the same function passed to `+editor.on()+`. For example, if a `+editorEventCallback+` function is bound to the `+NodeChange+` event when the button is created, `+onSetup+` should return `+(api) => editor.off('NodeChange', editorEventCallback)+`. | ||
| * If `+onSetup+` does not have any event listeners or only listens to the `+init+` event, `+onSetup+` can return an empty function e.g. `+return () => {};+`. | ||
| * The callback function passed to `+editor.off()+` should be the same function passed to `+editor.on()+`. For example, if an `+editorEventCallback+` function is bound to the `+NodeChange+` event when the button is created, `+onSetup+` should return `+(api) => editor.off('NodeChange', editorEventCallback)+`. | ||
| * If `+onSetup+` does not register any event listeners or only listens to the `+init+` event, `+onSetup+` can return an empty function e.g. `+return () => {};+`. | ||
| ==== |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated paragraph — remove the first occurrence.