plug-code 1.1.8 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plug-code",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "",
5
5
  "main": "src/plug-code.tsx",
6
6
  "types": "types/plug-code.d.ts",
@@ -64,13 +64,24 @@ export class PlcAPI<S extends ObjectType> {
64
64
  }
65
65
 
66
66
  derive<K extends string>(outputKey: K, dependencies: string[], calculator: () => any) {
67
+ let isRunning = false;
68
+
67
69
  const runUpdate = () => {
68
- const result = calculator();
69
- this.replace("root" as any, { [outputKey]: result });
70
+ if (isRunning) return;
71
+
72
+ isRunning = true;
73
+ try {
74
+ const result = calculator();
75
+ this.replace("root" as any, { [outputKey]: result });
76
+ } finally {
77
+ isRunning = false;
78
+ }
70
79
  };
71
80
 
72
81
  dependencies.forEach(dep => {
73
- this.store.subscribe(dep as any, () => runUpdate());
82
+ this.store.subscribe(dep as any, () => {
83
+ runUpdate();
84
+ });
74
85
  });
75
86
 
76
87
  runUpdate();
@@ -104,7 +115,7 @@ export class PlcAPI<S extends ObjectType> {
104
115
  }
105
116
  }
106
117
 
107
- scope<T = any>(key: string & "root"): {
118
+ scope<T = any>(key: string | "root"): {
108
119
  get: () => T;
109
120
  update: (updater: (draft: T) => void) => void;
110
121
  connect: (renderer: (data: T) => React.ReactNode) => React.FC;
@@ -116,7 +127,7 @@ export class PlcAPI<S extends ObjectType> {
116
127
  get: (): T => this.getData(key),
117
128
 
118
129
  update: (updater: (draft: T) => void) => {
119
- this.update(key, updater);
130
+ this.update(key as any, updater);
120
131
  },
121
132
 
122
133
  connect: (renderer: (data: T) => React.ReactNode) => {
@@ -79,7 +79,7 @@ export declare class PlcAPI<S extends ObjectType> {
79
79
 
80
80
  derive<K extends string>(outputKey: K, dependencies: string[], calculator: () => any): void
81
81
 
82
- update<K extends keyof S>(key: string & "root", updater: (draft: any) => void, slot?: string): void;
82
+ update(key: string | "root", updater: (draft: any) => void, slot?: string): void;
83
83
 
84
84
  subscribe(listener: () => void): () => void;
85
85