plug-code 1.1.11 → 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 +1 -1
- package/src/core/plcAPI.tsx +20 -20
package/package.json
CHANGED
package/src/core/plcAPI.tsx
CHANGED
|
@@ -69,36 +69,36 @@ export class PlcAPI<S extends ObjectType> {
|
|
|
69
69
|
calculator: () => any
|
|
70
70
|
) {
|
|
71
71
|
let lastValue: any
|
|
72
|
-
|
|
73
|
-
let isRunning = false
|
|
74
|
-
let idleHandle: number | null = null
|
|
72
|
+
let isComputing = false
|
|
75
73
|
|
|
76
74
|
const runUpdate = () => {
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
isRunning = false
|
|
88
|
-
idleHandle = null
|
|
89
|
-
}
|
|
90
|
-
}, { timeout: 100 })
|
|
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
|
+
}
|
|
91
85
|
}
|
|
92
86
|
|
|
87
|
+
runUpdate()
|
|
88
|
+
|
|
93
89
|
dependencies.forEach(dep => {
|
|
94
|
-
this.store.subscribe(dep as any, () =>
|
|
90
|
+
this.store.subscribe(dep as any, () => {
|
|
91
|
+
if (isComputing) return
|
|
92
|
+
runUpdate()
|
|
93
|
+
})
|
|
95
94
|
})
|
|
96
95
|
|
|
97
|
-
runUpdate()
|
|
98
|
-
|
|
99
96
|
return () => lastValue
|
|
100
97
|
}
|
|
101
98
|
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
102
|
register(slot: SlotKey, node: () => React.ReactNode): void;
|
|
103
103
|
register<K extends string>(slot: SlotKey, node: (data: any) => React.ReactNode, dependencyKey: K): void;
|
|
104
104
|
register(slot: SlotKey, node: (data?: any) => React.ReactNode, dependencyKey?: string) {
|