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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/core/plcAPI.tsx +20 -20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "plug-code",
3
- "version": "1.1.11",
3
+ "version": "1.1.13",
4
4
  "description": "",
5
5
  "main": "src/plug-code.tsx",
6
6
  "types": "types/plug-code.d.ts",
@@ -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 (isRunning) return
78
- if (idleHandle) cancelIdleCallback(idleHandle)
79
-
80
- idleHandle = requestIdleCallback(() => {
81
- isRunning = true
82
- try {
83
- const result = calculator()
84
- lastValue = result
85
- this.replace("root" as any, { [outputKey]: result })
86
- } finally {
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, () => runUpdate())
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) {