Dismissing layers and cleanup #584
Closed
alexandremjacques
started this conversation in
General
Replies: 2 comments
-
The canonical way to initialize third-party libraries is a compiler. Compilers can return a destructor function that is called when the element is destroyed.. When a layer is closed, all fragments in that layer are destroyed and their destructor functions are called. I found this TinyMCE example in a project: up.compiler('[wysiwyg-editor]', (element) => {
let editor
TinyMCE.init({
target: element,
init_instance_callback: (instance) => editor = instance,
})
return () => { editor?.destroy() }
}) |
Beta Was this translation helpful? Give feedback.
0 replies
-
That's great! Worked like a charm. Thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I'm having some issues integrating TinyMCE with Unpoly (inside layers, TinyMCE doesn't reinitialize when the layer is closed then reopened).
I kinda solved the issue by using the
up:layer:dismiss
event to find and remove the editor. It's a bit generic though since I have to check if the layer has an editor to remove in the first place (in the case of closing other layers that don't have an editor).Just wondering if there's a better way to do this.
Beta Was this translation helpful? Give feedback.
All reactions