Skip to content

How to know when a widget is unmounted? #5945

Closed Answered by linonetwo
linonetwo asked this question in Q&A
Discussion options

You must be logged in to vote

Update: use https://www.npmjs.com/package/@seznam/visibility-observer , which only add 6.09KB to each plugin.

Usage

import { widget as Widget } from '$:/core/modules/widgets/widget.js';
import { IChangedTiddlers, ITiddlerFields } from 'tiddlywiki';
import { observe, unobserve } from '@seznam/visibility-observer';

class CommandPaletteWidget extends Widget {

  render(parent: Element, nextSibling: Element) {
    this.parentDomNode = parent;
    this.computeAttributes();
    this.execute();
    const containerElement = $tw.utils.domMaker('nav', {
      class: 'tw-commandpalette-container',
    });
    parent.insertBefore(containerElement, nextSibling);
    this.domNodes.push(containerElement);

Replies: 4 comments 8 replies

Comment options

You must be logged in to vote
5 replies
@linonetwo
Comment options

@buggyj
Comment options

@linonetwo
Comment options

@Jermolene
Comment options

@buggyj
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@Jermolene
Comment options

@linonetwo
Comment options

@linonetwo
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by linonetwo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants