plug-code 1.1.12 → 1.1.13

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.12",
3
+ "version": "1.1.13",
4
4
  "description": "",
5
5
  "main": "src/plug-code.tsx",
6
6
  "types": "types/plug-code.d.ts",
@@ -69,19 +69,28 @@ export class PlcAPI<S extends ObjectType> {
69
69
  calculator: () => any
70
70
  ) {
71
71
  let lastValue: any
72
+ let isComputing = false
72
73
 
73
74
  const runUpdate = () => {
74
- const result = calculator()
75
- lastValue = result
76
- this.replace("root" as any, { [outputKey]: result })
75
+ if (isComputing) return
76
+
77
+ isComputing = true
78
+ try {
79
+ const result = calculator()
80
+ lastValue = result
81
+ this.replace("root" as any, { [outputKey]: result })
82
+ } finally {
83
+ isComputing = false
84
+ }
77
85
  }
78
86
 
79
- // cálculo inicial inmediato
80
87
  runUpdate()
81
88
 
82
- // suscripción a dependencias
83
89
  dependencies.forEach(dep => {
84
- this.store.subscribe(dep as any, runUpdate)
90
+ this.store.subscribe(dep as any, () => {
91
+ if (isComputing) return
92
+ runUpdate()
93
+ })
85
94
  })
86
95
 
87
96
  return () => lastValue
@@ -89,6 +98,7 @@ export class PlcAPI<S extends ObjectType> {
89
98
 
90
99
 
91
100
 
101
+
92
102
  register(slot: SlotKey, node: () => React.ReactNode): void;
93
103
  register<K extends string>(slot: SlotKey, node: (data: any) => React.ReactNode, dependencyKey: K): void;
94
104
  register(slot: SlotKey, node: (data?: any) => React.ReactNode, dependencyKey?: string) {