plug-code 1.1.10 → 1.1.12
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 +19 -20
package/package.json
CHANGED
package/src/core/plcAPI.tsx
CHANGED
|
@@ -63,33 +63,32 @@ export class PlcAPI<S extends ObjectType> {
|
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
derive<K extends string>(
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
derive<K extends string>(
|
|
67
|
+
outputKey: K,
|
|
68
|
+
dependencies: string[],
|
|
69
|
+
calculator: () => any
|
|
70
|
+
) {
|
|
71
|
+
let lastValue: any
|
|
69
72
|
|
|
70
73
|
const runUpdate = () => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.replace("root" as any, { [outputKey]: result });
|
|
79
|
-
} finally {
|
|
80
|
-
isRunning = false;
|
|
81
|
-
idleHandle = null;
|
|
82
|
-
}
|
|
83
|
-
}, { timeout: 100 });
|
|
84
|
-
};
|
|
74
|
+
const result = calculator()
|
|
75
|
+
lastValue = result
|
|
76
|
+
this.replace("root" as any, { [outputKey]: result })
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// cálculo inicial inmediato
|
|
80
|
+
runUpdate()
|
|
85
81
|
|
|
82
|
+
// suscripción a dependencias
|
|
86
83
|
dependencies.forEach(dep => {
|
|
87
|
-
this.store.subscribe(dep as any,
|
|
88
|
-
})
|
|
84
|
+
this.store.subscribe(dep as any, runUpdate)
|
|
85
|
+
})
|
|
89
86
|
|
|
90
|
-
|
|
87
|
+
return () => lastValue
|
|
91
88
|
}
|
|
92
89
|
|
|
90
|
+
|
|
91
|
+
|
|
93
92
|
register(slot: SlotKey, node: () => React.ReactNode): void;
|
|
94
93
|
register<K extends string>(slot: SlotKey, node: (data: any) => React.ReactNode, dependencyKey: K): void;
|
|
95
94
|
register(slot: SlotKey, node: (data?: any) => React.ReactNode, dependencyKey?: string) {
|