@bian-womp/spark-graph 0.1.19 → 0.1.20
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/misc/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../../src/misc/base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,eAAe,CAAC;AA0CvB,wBAAgB,uBAAuB,IAAI,QAAQ,CA4elD;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,QA+BnD;AAqBD,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,QA6BvD;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,GAAG,EAAE,eAAe,6BAUrE"}
|
package/lib/esm/index.js
CHANGED
|
@@ -2156,6 +2156,57 @@ function setupBasicGraphRegistry() {
|
|
|
2156
2156
|
return { Values: out };
|
|
2157
2157
|
},
|
|
2158
2158
|
});
|
|
2159
|
+
// Timer
|
|
2160
|
+
registry.registerNode({
|
|
2161
|
+
id: "base.timer",
|
|
2162
|
+
categoryId: "compute",
|
|
2163
|
+
inputs: {
|
|
2164
|
+
Enabled: "base.bool",
|
|
2165
|
+
IntervalMs: "base.float",
|
|
2166
|
+
Immediate: "base.bool",
|
|
2167
|
+
},
|
|
2168
|
+
outputs: { Now: "base.float", Count: "base.float" },
|
|
2169
|
+
inputDefaults: { Enabled: true, IntervalMs: 1000, Immediate: true },
|
|
2170
|
+
impl: (ins, ctx) => {
|
|
2171
|
+
const enabled = Boolean(ins.Enabled);
|
|
2172
|
+
const intervalMs = Math.max(1, Math.trunc(Number(ins.IntervalMs ?? 1000)));
|
|
2173
|
+
const immediate = Boolean(ins.Immediate);
|
|
2174
|
+
const stop = () => {
|
|
2175
|
+
const id = ctx.state.timerId;
|
|
2176
|
+
if (id !== undefined) {
|
|
2177
|
+
clearInterval(id);
|
|
2178
|
+
ctx.setState({ timerId: undefined });
|
|
2179
|
+
}
|
|
2180
|
+
};
|
|
2181
|
+
if (!enabled) {
|
|
2182
|
+
stop();
|
|
2183
|
+
return;
|
|
2184
|
+
}
|
|
2185
|
+
// restart timer with new settings
|
|
2186
|
+
stop();
|
|
2187
|
+
let count = 0;
|
|
2188
|
+
if (immediate) {
|
|
2189
|
+
ctx.emit("Now", Date.now());
|
|
2190
|
+
ctx.emit("Count", count);
|
|
2191
|
+
count += 1;
|
|
2192
|
+
}
|
|
2193
|
+
const id = setInterval(() => {
|
|
2194
|
+
ctx.emit("Now", Date.now());
|
|
2195
|
+
ctx.emit("Count", count);
|
|
2196
|
+
count += 1;
|
|
2197
|
+
}, intervalMs);
|
|
2198
|
+
ctx.setState({ timerId: id });
|
|
2199
|
+
},
|
|
2200
|
+
lifecycle: {
|
|
2201
|
+
dispose: (ctx) => {
|
|
2202
|
+
const id = ctx.state.timerId;
|
|
2203
|
+
if (id !== undefined) {
|
|
2204
|
+
clearInterval(id);
|
|
2205
|
+
ctx.setState({ timerId: undefined });
|
|
2206
|
+
}
|
|
2207
|
+
},
|
|
2208
|
+
},
|
|
2209
|
+
});
|
|
2159
2210
|
return registry;
|
|
2160
2211
|
}
|
|
2161
2212
|
function registerDelayNode(registry) {
|