@constela/runtime 0.6.0 → 0.7.0
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/dist/index.d.ts +1 -0
- package/dist/index.js +7 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -26,6 +26,7 @@ declare function createEffect(fn: EffectFn): () => void;
|
|
|
26
26
|
interface StateStore {
|
|
27
27
|
get(name: string): unknown;
|
|
28
28
|
set(name: string, value: unknown): void;
|
|
29
|
+
subscribe(name: string, fn: (value: unknown) => void): () => void;
|
|
29
30
|
}
|
|
30
31
|
interface StateDefinition {
|
|
31
32
|
type: string;
|
package/dist/index.js
CHANGED
|
@@ -111,6 +111,13 @@ function createStateStore(definitions) {
|
|
|
111
111
|
throw new Error(`State field "${name}" does not exist`);
|
|
112
112
|
}
|
|
113
113
|
signal.set(value);
|
|
114
|
+
},
|
|
115
|
+
subscribe(name, fn) {
|
|
116
|
+
const signal = signals.get(name);
|
|
117
|
+
if (!signal) {
|
|
118
|
+
throw new Error(`State field "${name}" does not exist`);
|
|
119
|
+
}
|
|
120
|
+
return signal.subscribe(fn);
|
|
114
121
|
}
|
|
115
122
|
};
|
|
116
123
|
}
|