@virtuoso.dev/reactive-engine-react 0.0.2 → 0.0.4

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 CHANGED
@@ -17,7 +17,8 @@ export declare const EngineContext: React_2.Context<Engine | null>;
17
17
  *
18
18
  * @example
19
19
  * ```tsx
20
- * import { Cell, useCellValue, e, EngineProvider } from '@virtuoso.dev/reactive-engine'
20
+ * import { Cell, useCellValue, EngineProvider } from '@virtuoso.dev/reactive-engine-react'
21
+ *
21
22
  * const cell$ = Cell(0)
22
23
  *
23
24
  * function MyComponent() {
@@ -26,7 +27,16 @@ export declare const EngineContext: React_2.Context<Engine | null>;
26
27
  * }
27
28
  *
28
29
  * export default function App() {
29
- * return <EngineProvider><MyComponent /></EngineProvider>
30
+ * const [count, setCount] = useState(0)
31
+ * return (
32
+ * <EngineProvider
33
+ * initFn={(engine) => engine.register(cell$)}
34
+ * updateFn={(engine) => engine.pub(cell$, count)}
35
+ * updateDeps={[count]}
36
+ * >
37
+ * <MyComponent />
38
+ * </EngineProvider>
39
+ * )
30
40
  * }
31
41
  * ```
32
42
  *
@@ -48,14 +58,22 @@ export declare interface EngineProviderProps {
48
58
  * Optional stable ID for storage namespacing. Use this for multi-engine apps to prevent storage key conflicts.
49
59
  */
50
60
  engineId?: string;
61
+ /**
62
+ * A callback invoked once when the engine is created. Use this to register nodes and set up subscriptions.
63
+ */
64
+ initFn?: (engine: Engine) => void;
51
65
  /**
52
66
  * The initial values to set in the engine.
53
67
  */
54
68
  initWith?: Record<symbol, unknown>;
55
69
  /**
56
- * The values to update in the engine on each render.
70
+ * The dependency array for the update effect. When any of these values change, `updateFn` is called.
71
+ */
72
+ updateDeps?: unknown[];
73
+ /**
74
+ * A callback invoked when any value in `updateDeps` changes. Use this to publish new values to the engine.
57
75
  */
58
- updateWith?: Record<symbol, unknown>;
76
+ updateFn?: (engine: Engine) => void;
59
77
  }
60
78
 
61
79
  /**
@@ -116,8 +134,6 @@ export declare const useCellValue: typeof useCellValueWithStore;
116
134
  * }
117
135
  * ```
118
136
  */
119
- export declare function useCellValues(...cells: Out[]): unknown[];
120
-
121
137
  /** @hidden */
122
138
  export declare function useCellValues<T1>(...cells: [Out<T1>]): [T1];
123
139
 
@@ -157,6 +173,9 @@ export declare function useCellValues<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T
157
173
  /** @hidden */
158
174
  export declare function useCellValues<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13>(...cells: [Out<T1>, Out<T2>, Out<T3>, Out<T4>, Out<T5>, Out<T6>, Out<T7>, Out<T8>, Out<T9>, Out<T10>, Out<T11>, Out<T12>, Out<T13>]): [T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13];
159
175
 
176
+ /** @hidden */
177
+ export declare function useCellValues(...cells: Out[]): unknown[];
178
+
160
179
  declare function useCellValueWithStore<T>(cell: Out<T>): T;
161
180
 
162
181
  /**
@@ -178,7 +197,7 @@ export declare const useIsomorphicLayoutEffect: typeof React_2.useLayoutEffect;
178
197
  *
179
198
  * @example
180
199
  * ```tsx
181
- * import {Stream, e, usePublisher} from '@virtuoso.dev/reactive-engine'
200
+ * import {Stream, e, usePublisher} from '@virtuoso.dev/reactive-engine-react'
182
201
  *
183
202
  * const stream$ = Stream<number>()
184
203
  * e.sub(stream, (value) => console.log(`${value} was published in the stream`))
package/dist/index.js CHANGED
@@ -1,63 +1,63 @@
1
- import { jsx as g } from "react/jsx-runtime";
2
- import { Engine as m } from "@virtuoso.dev/reactive-engine-core";
3
- import * as t from "react";
4
- import C from "tiny-invariant";
5
- const i = typeof document < "u" ? t.useLayoutEffect : t.useEffect, c = t.createContext(null);
1
+ import { jsx as C } from "react/jsx-runtime";
2
+ import { Engine as E } from "@virtuoso.dev/reactive-engine-core";
3
+ import * as u from "react";
4
+ import b from "tiny-invariant";
5
+ const a = typeof document < "u" ? u.useLayoutEffect : u.useEffect, g = u.createContext(null);
6
6
  function o() {
7
- const e = t.useContext(c);
8
- return C(e !== null, "useEngine must be used within an EngineProvider"), e;
7
+ const e = u.useContext(g);
8
+ return b(e !== null, "useEngine must be used within an EngineProvider"), e;
9
9
  }
10
- function E(e) {
10
+ function S(e) {
11
11
  const n = o();
12
12
  n.register(e);
13
- const u = t.useCallback((r) => n.sub(e, r), [n, e]);
14
- return t.useSyncExternalStore(
15
- u,
13
+ const t = u.useCallback((r) => n.sub(e, r), [n, e]);
14
+ return u.useSyncExternalStore(
15
+ t,
16
16
  () => n.getValue(e),
17
17
  () => n.getValue(e)
18
18
  );
19
19
  }
20
- function b(e) {
20
+ function V(e) {
21
21
  const n = o();
22
22
  n.register(e);
23
- const [u, r] = t.useState(() => n.getValue(e));
24
- return i(() => n.sub(e, r), [n, e]), u;
23
+ const [t, r] = u.useState(() => n.getValue(e));
24
+ return a(() => n.sub(e, r), [n, e]), t;
25
25
  }
26
- const l = "useSyncExternalStore" in t ? E : b;
27
- function d(...e) {
28
- const n = o(), u = t.useMemo(() => n.combineCells(e), [n, ...e]);
29
- return l(u);
26
+ const f = "useSyncExternalStore" in u ? S : V;
27
+ function h(...e) {
28
+ const n = o(), t = u.useMemo(() => n.combineCells(e), [n, ...e]);
29
+ return f(t);
30
30
  }
31
- function p(e) {
31
+ function x(e) {
32
32
  const n = o();
33
- return n.register(e), t.useCallback(
34
- (u) => {
35
- n.pub(e, u);
33
+ return n.register(e), u.useCallback(
34
+ (t) => {
35
+ n.pub(e, t);
36
36
  },
37
37
  [n, e]
38
38
  );
39
39
  }
40
- function v(e) {
41
- return [l(e), p(e)];
40
+ function P(e) {
41
+ return [f(e), x(e)];
42
42
  }
43
- const y = ({ children: e, engineId: n, initWith: u, updateWith: r = {} }) => {
44
- const [s, f] = t.useState(null);
45
- return i(() => {
46
- const a = new m(u, n);
47
- return f(a), () => {
48
- a.dispose();
43
+ const d = ({ children: e, engineId: n, initFn: t, initWith: r, updateDeps: l, updateFn: i }) => {
44
+ const [s, m] = u.useState(null);
45
+ return a(() => {
46
+ const c = new E(r, n);
47
+ return m(c), t == null || t(c), () => {
48
+ c.dispose();
49
49
  };
50
- }, [u, n]), i(() => {
51
- s == null || s.pubIn(r);
52
- }, [r, s]), s && /* @__PURE__ */ g(c.Provider, { value: s, children: e });
50
+ }, [r, n]), a(() => {
51
+ s && (i == null || i(s));
52
+ }, [s, ...l ?? []]), s && /* @__PURE__ */ C(g.Provider, { value: s, children: e });
53
53
  };
54
54
  export {
55
- c as EngineContext,
56
- y as EngineProvider,
57
- v as useCell,
58
- l as useCellValue,
59
- d as useCellValues,
55
+ g as EngineContext,
56
+ d as EngineProvider,
57
+ P as useCell,
58
+ f as useCellValue,
59
+ h as useCellValues,
60
60
  o as useEngine,
61
- i as useIsomorphicLayoutEffect,
62
- p as usePublisher
61
+ a as useIsomorphicLayoutEffect,
62
+ x as usePublisher
63
63
  };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "private": false,
4
4
  "sideEffects": false,
5
5
  "type": "module",
6
- "version": "0.0.2",
6
+ "version": "0.0.4",
7
7
  "module": "dist/index.js",
8
8
  "main": "dist/index.js",
9
9
  "types": "dist/index.d.ts",
@@ -21,7 +21,7 @@
21
21
  "tiny-invariant": "^1.3.3"
22
22
  },
23
23
  "peerDependencies": {
24
- "@virtuoso.dev/reactive-engine-core": ">=0.0.2",
24
+ "@virtuoso.dev/reactive-engine-core": ">=0.0.3",
25
25
  "react": ">= 18",
26
26
  "react-dom": ">= 18"
27
27
  },
@@ -45,8 +45,8 @@
45
45
  "vite-plugin-dts": "^4.5.4",
46
46
  "vitest": "^4.0.16",
47
47
  "vitest-browser-react": "^2.0.2",
48
- "@virtuoso.dev/reactive-engine-core": "0.0.2",
49
- "@virtuoso.dev/tooling": "0.1.0"
48
+ "@virtuoso.dev/tooling": "0.1.0",
49
+ "@virtuoso.dev/reactive-engine-core": "0.0.3"
50
50
  },
51
51
  "files": [
52
52
  "dist"