Skip to content

Commit 8023342

Browse files
authored
Merge pull request #2 from flotiq/feature/add-detach-event-listener
add detached event listener and remove manage modal event
2 parents 65c9aa0 + 652ae16 commit 8023342

File tree

4 files changed

+7
-35
lines changed

4 files changed

+7
-35
lines changed

common/plugin-element-cache.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
const appRoots = {};
22

3-
export const onElementRemoved = (element, callback) => {
4-
new MutationObserver(function () {
5-
if (!document.contains(element)) {
6-
callback();
7-
this.disconnect();
8-
}
9-
}).observe(element.parentElement, { childList: true });
10-
};
11-
123
export const addElementToCache = (element, key, data = {}) => {
134
appRoots[key] = {
145
element,
156
data,
167
};
178

18-
element.addEventListener(
19-
"flotiq.attached",
20-
() => onElementRemoved(element, () => delete appRoots[key]),
21-
true,
9+
setTimeout(
10+
() =>
11+
element.addEventListener("flotiq.detached", () => {
12+
delete appRoots[key];
13+
}),
14+
50,
2215
);
2316
};
2417

plugin-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"id": "flotiq.plain-js-template",
33
"name": "Plain JS Plugin Template",
44
"description": "A plain js example of Flotiq plugin. This plugin changes the rendering of some data in the grid. It renders colorful text properties, bold numbers, and relations as text.",
5-
"version": "0.1.0",
5+
"version": "0.1.1",
66
"repository": "https://github.com/flotiq/flotiq-ui-plugin-templates-plain-js",
77
"url": "https://localhost:3053/index.js",
88
"permissions": [

plugins/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { registerFn } from "../common/plugin-element-cache";
22
import pluginInfo from "../plugin-manifest.json";
33
import cssString from "inline:./styles/style.css";
44
import { handleGridPlugin } from "./grid-renderers";
5-
import { handleManagePlugin } from "./manage-modal";
65

76
registerFn(pluginInfo, (handler, client) => {
87
/**
@@ -18,7 +17,4 @@ registerFn(pluginInfo, (handler, client) => {
1817
handler.on("flotiq.grid.cell::render", (data) =>
1918
handleGridPlugin(data, client, pluginInfo),
2019
);
21-
handler.on("flotiq.plugins.manage::render", (data) =>
22-
handleManagePlugin(data, pluginInfo),
23-
);
2420
});

plugins/manage-modal/index.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)