@expressive/react 0.77.0 → 0.79.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.
@@ -1,63 +0,0 @@
1
- import { event, observer, watch } from "@expressive/state";
2
-
3
- //#region src/runtime.ts
4
- const Runtime = {};
5
- function useFactory(factory) {
6
- const ref = Runtime.useRef(null);
7
- return ref.current || (ref.current = factory());
8
- }
9
- function useReady(callback) {
10
- return Runtime.useEffect(() => void callback(), []);
11
- }
12
- /**
13
- * Mount-effect with a refreshable return value, safe under React StrictMode.
14
- *
15
- * @param callback Setup handler; receives a setter, must return a cleanup.
16
- * @returns Latest value published via the setter (`undefined` until set).
17
- */
18
- function useHook(callback) {
19
- const { current } = Runtime.useRef({ mounted: 0 });
20
- current.update = Runtime.useState(() => {
21
- if (!current.mounted) current.unmount = callback((next) => {
22
- current.output = next;
23
- current.update?.((x) => x + 1);
24
- });
25
- return current.mounted++;
26
- })[1];
27
- Runtime.useEffect(() => () => {
28
- if (--current.mounted < 1) current.unmount();
29
- }, []);
30
- return current.output;
31
- }
32
-
33
- //#endregion
34
- //#region src/use.ts
35
- function use(subject) {
36
- const { current } = Runtime.useRef({
37
- mounted: 0,
38
- proxy: subject
39
- });
40
- const update = Runtime.useState(() => current.mounted++)[1];
41
- if (current.source !== subject) {
42
- const status = observer(subject);
43
- if (status === null) throw new Error("Provided object is no longer observable.");
44
- if (!status) throw new Error("Provided object is not observable.");
45
- if (!status.ready) event(subject);
46
- current.unwatch?.();
47
- current.source = subject;
48
- let init = true;
49
- current.unwatch = watch(subject, (next, changed) => {
50
- current.proxy = next;
51
- if (changed.length && !init) update((x) => x + 1);
52
- });
53
- init = false;
54
- }
55
- Runtime.useEffect(() => () => {
56
- if (--current.mounted < 1) current.unwatch?.();
57
- }, []);
58
- return current.proxy;
59
- }
60
-
61
- //#endregion
62
- export { useReady as a, useHook as i, Runtime as n, useFactory as r, use as t };
63
- //# sourceMappingURL=use-AIA25P7A.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"use-AIA25P7A.js","names":[],"sources":["../src/runtime.ts","../src/use.ts"],"sourcesContent":["export const Runtime = {} as {\n createElement(type: any, props?: any, ...children: any[]): any;\n useState<S>(initial: S | (() => S)): [S, (next: (previous: S) => S) => void];\n useEffect(effect: () => (() => void) | void, deps?: any[]): void;\n useRef<T>(initial: T): { current: T };\n};\n\nexport function useFactory<T extends Function>(factory: () => T) {\n const ref = Runtime.useRef<T | null>(null);\n return ref.current || (ref.current = factory());\n}\n\nexport function useReady<T>(callback: () => void) {\n return Runtime.useEffect(() => void callback(), []);\n}\n\n/**\n * Mount-effect with a refreshable return value, safe under React StrictMode.\n *\n * @param callback Setup handler; receives a setter, must return a cleanup.\n * @returns Latest value published via the setter (`undefined` until set).\n */\nexport function useHook<T = void>(\n callback: (refresh: (next: T) => void) => () => void\n) {\n const { current } = Runtime.useRef(\n { mounted: 0 } as {\n mounted: number;\n unmount: () => void;\n update: (next: (previous: number) => number) => void;\n output: T;\n }\n );\n\n current.update = Runtime.useState(() => {\n if (!current.mounted)\n current.unmount = callback((next) => {\n current.output = next;\n current.update?.((x) => x + 1);\n });\n\n return current.mounted++;\n })[1];\n\n Runtime.useEffect(() => () => {\n if (--current.mounted < 1) current.unmount();\n }, []);\n\n return current.output;\n}","import { event, observer, watch } from '@expressive/state';\nimport { Runtime } from './runtime';\n\nexport function use<T extends object>(subject: T) {\n const { current } = Runtime.useRef<{\n proxy: T;\n source?: T;\n mounted: number;\n unwatch?: () => void;\n }>({ mounted: 0, proxy: subject });\n\n const update = Runtime.useState(() => current.mounted++)[1];\n\n if (current.source !== subject) {\n const status = observer(subject);\n\n if (status === null)\n throw new Error('Provided object is no longer observable.');\n\n if (!status)\n throw new Error('Provided object is not observable.');\n\n if (!status.ready) event(subject);\n\n current.unwatch?.();\n current.source = subject;\n\n let init = true;\n\n current.unwatch = watch(subject, (next, changed) => {\n current.proxy = next;\n if (changed.length && !init)\n update((x) => x + 1);\n });\n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