Skip to content

Commit 56b85f5

Browse files
authored
Merge pull request #5 from GeekyAnts/feat/remove
Feat/remove
2 parents 2fe8971 + 4fab79c commit 56b85f5

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

example/Plugins/ClickMePlugin.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ class ClickMePlugin implements IPlugin {
66
public pluginStore;
77

88
init(pluginStore) {
9-
console.log('Inside init');
109
this.pluginStore = pluginStore;
1110
}
1211

@@ -20,7 +19,7 @@ class ClickMePlugin implements IPlugin {
2019
));
2120
}
2221
deactivate() {
23-
//
22+
this.pluginStore.removeFunction('sendAlert');
2423
}
2524
}
2625

example/components/Test.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { usePluginStore } from '../../.';
33

44
const Test = (props: any) => {
55
const pluginStore: any = usePluginStore();
6-
console.log(pluginStore);
7-
pluginStore.executeFunction('test', 1, 2);
86
let Renderer = pluginStore.executeFunction(
97
'RendererPlugin.getRendererComponent'
108
);

example/index.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ pluginStore.install('RendererPlugin', new RendererPlugin());
1010
pluginStore.install('ClickMePlugin', new ClickMePlugin());
1111

1212
const App = () => {
13-
pluginStore.addFunction('test', (a, b) => {
14-
console.log('working 1', a, b);
15-
});
1613
return (
1714
<PluginProvider pluginStore={pluginStore}>
1815
<Test></Test>

src/PluginStore.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,22 @@ export class PluginStore {
2121

2222
executeFunction(key: string, ...args: any): any {
2323
let fn = this.functionArray.get(key);
24-
return fn(...args);
24+
if (fn) {
25+
return fn(...args);
26+
}
27+
console.error('No function added for the key ' + key + '.');
28+
}
29+
30+
removeFunction(key: string): any {
31+
this.functionArray.delete(key);
32+
}
33+
34+
uninstall(key: string) {
35+
let plugin = this.pluginMap.get(key);
36+
37+
if (plugin) {
38+
plugin.deactivate();
39+
this.pluginMap.delete(key);
40+
}
2541
}
2642
}

src/plugins/RendererPlugin/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export class RendererPlugin implements IPlugin {
4747
}
4848

4949
deactivate() {
50-
//
50+
this.pluginStore.removeFunction('RendererPlugin.add');
51+
52+
this.pluginStore.removeFunction('RendererPlugin.getComponentsInPosition');
53+
54+
this.pluginStore.removeFunction('RendererPlugin.getRendererComponent');
5155
}
5256
}

0 commit comments

Comments
 (0)