@open-pioneer/reactivity 4.1.0 → 4.2.0-dev.20251021072202
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/CHANGELOG.md +11 -0
- package/index.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @open-pioneer/reactivity
|
|
2
2
|
|
|
3
|
+
## 4.2.0-dev.20251021072202
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- ed3d452: Update @conterra/reactivity-core to 0.8.0. This release is backwards compatible to 0.7.x, but contains a few deprecations.
|
|
8
|
+
- 1b95a62: Update chakra-ui to 3.28.0
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- 81308c0: Update to eslint 9
|
|
13
|
+
|
|
3
14
|
## 4.1.0
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ReadonlyReactive, Reactive, computed, reactive, watch } from \"@conterra/reactivity-core\";\nimport {\n DependencyList,\n useCallback,\n useDebugValue,\n useMemo,\n useRef,\n useSyncExternalStore\n} from \"react\";\n\n/**\n * Creates a new signal with the initial value `undefined`.\n *\n * The initial value will only be applied on the very first call to this hook.\n * The same signal instance will be returned when this hook is called on the next render.\n * This is very similar (in concept) to React's builtin `useState` hook.\n *\n * @example\n *\n * ```jsx\n * function YourComponent() {\n * const mySignal = useReactive();\n * const someEventHandler = () => {\n * // Update the value after some event\n * mySignal.value = \"new value\";\n * };\n *\n * // Always returns the current value, re-renders if necessary.\n * const currentValue = useReactiveValue(mySignal);\n * }\n * ```\n */\nexport function useReactive<T>(): Reactive<T | undefined>;\n\n/**\n * Creates a new signal with the given initial value.\n *\n * @see {@link useReactive()}.\n */\nexport function useReactive<T>(initialValue: T): Reactive<T>;\n\nexport function useReactive<T>(initialValue?: T): Reactive<T | undefined> {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useMemo(() => reactive(initialValue), []);\n}\n\n/**\n * Creates a new computed signal that evaluates the given `compute` function.\n *\n * The hook returns the same signal for as long as `deps` remains the same.\n * When `deps` change, a new signal will be created.\n *\n * @example\n *\n * Defining a simple computed value in your react component:\n *\n * ```jsx\n * function MyComponent(props) {\n * // Creates a computed value based on the given function.\n * // The computed value will be re-created whenever one of the listed dependencies changes.\n * // While the computed value can track all its _reactive_ dependencies automatically (`.value` reads etc.)\n * // the reactive value itself used here might change (different props) - this cannot be detected automatically.\n * const computed = useComputed(() => props.someReactive.value * 2, [props.someReactive]);\n *\n * // Watches on `computed` and returns its current value.\n * const currentValue = useReactiveValue(computed);\n * }\n * ```\n *\n * > If the body of your compute function depends on non-reactive values (such as react props or state),\n * > list those values in the `deps` array.\n *\n * @see {@link useReactiveValue()}\n * @see {@link useReactiveSnapshot()}\n */\nexport function useComputed<T>(compute: () => T, deps: DependencyList): ReadonlyReactive<T> {\n const computeRef = useRef(compute);\n computeRef.current = compute;\n\n const computedDeps = useComputedDeps(deps);\n return useMemo(() => {\n void computedDeps; // not really used, but computed must be recreated when this value changes\n return computed(() => computeRef.current());\n }, [computedDeps]);\n}\n\n/**\n * Watches the given reactive object and returns its current value.\n *\n * > NOTE: The return value of this hook should be considered read-only.\n *\n * @see {@link useComputed()}\n */\nexport function useReactiveValue<T>(reactive: ReadonlyReactive<T>): T {\n const getSnapshot = useCallback(() => {\n return reactive.peek();\n }, [reactive]);\n const subscribe = useCallback(\n (cb: () => void) => {\n const handle = watch(() => [reactive.value], cb);\n return () => handle.destroy();\n },\n [reactive]\n );\n const value = useSyncExternalStore(subscribe, getSnapshot);\n useDebugValue(value);\n return value;\n}\n\n/**\n * Evaluates the `compute` function and returns its result.\n *\n * The body of the compute function is tracked: it\n * will be re-evaluated whenever its reactive dependencies change.\n * The outer react component will re-render whenever `compute` returns a new value.\n *\n * > NOTE: The return value of this hook should be considered read-only.\n *\n * @example\n *\n * Simple Example:\n *\n * ```jsx\n * // A reactive signal from anywhere (global data, props, ...).\n * const name = reactive(\"User\");\n *\n * function YourComponent() {\n * const nameSnapshot = useReactiveSnapshot(() => name.value);\n * // snapshot is automatically up to date\n * }\n * ```\n *\n * @example\n *\n * Multiple values, with props:\n *\n * ```jsx\n * function YourComponent({firstName, lastName}) {\n * // You can use complex expressions in your compute function,\n * // just like in a computed signal.\n * // React-dependencies used in the callback must be listed in the second argument,\n * // just like when using `useMemo()` or `useEffect`.\n * const snapshot = useReactiveSnapshot(() => {\n * return {\n * firstName: firstName.value,\n * lastName: lastName.value,\n * fullName: `${firstName.value} ${lastName.value}`\n * };\n * }, [firstName, lastName]);\n * // snapshot.firstName, snapshot.lastName, snapshot.fullName are available and up to date\n * }\n * ```\n *\n * @see\n * This hook is based on {@link useComputed()} and {@link useReactiveValue()}.\n */\nexport function useReactiveSnapshot<T>(compute: () => T, deps: DependencyList): T {\n // We create an internal computed value that executes the compute function;\n // this way the implementation of `compute` is automatically tracked.\n // getSnapshot and subscribe simply watch the current value of that computed value.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const computedSnapshot = useComputed(compute, deps);\n const snapshot = useReactiveValue(computedSnapshot);\n useDebugValue(snapshot);\n return snapshot;\n}\n\nfunction useComputedDeps(deps: DependencyList): DependencyList {\n const computedDeps = useRef<DependencyList>(null);\n if (computedDeps.current == null || !shallowEqual(computedDeps.current, deps)) {\n computedDeps.current = deps ?? [];\n }\n return computedDeps.current;\n}\n\nfunction shallowEqual(a: DependencyList, b: DependencyList): boolean {\n if (a === b) {\n return true;\n }\n return a.length === (b?.length ?? 0) && a.every((v, i) => v === b![i]);\n}\n"],"names":["reactive"],"mappings":";;;AA2CO,SAAS,YAAe,YAAA,EAA2C;AAEtE,EA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D,EAAA,MAAM,YAAA,GAAe,OAAuB,IAAI,CAAA;AAChD,EAAA,IAAI,YAAA,CAAa,WAAW,IAAA,IAAQ,CAAC,aAAa,YAAA,CAAa,OAAA,EAAS,IAAI,CAAA,EAAG;AAC3E,IAAA,YAAA,CAAa,OAAA,GAAU,QAAQ,EAAC;AAAA,EACpC;AACA,EAAA,OAAO,YAAA,CAAa,OAAA;AACxB;AAEA,SAAS,YAAA,CAAa,GAAmB,CAAA,EAA4B;AACjE,EAAA,IAAI,MAAM,CAAA,EAAG;AACT,IAAA,OAAO,IAAA;AAAA,EACX;
|
|
1
|
+
{"version":3,"file":"index.js","sources":["index.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2023-2025 Open Pioneer project (https://github.com/open-pioneer)\n// SPDX-License-Identifier: Apache-2.0\nimport { ReadonlyReactive, Reactive, computed, reactive, watch } from \"@conterra/reactivity-core\";\nimport {\n DependencyList,\n useCallback,\n useDebugValue,\n useMemo,\n useRef,\n useSyncExternalStore\n} from \"react\";\n\n/**\n * Creates a new signal with the initial value `undefined`.\n *\n * The initial value will only be applied on the very first call to this hook.\n * The same signal instance will be returned when this hook is called on the next render.\n * This is very similar (in concept) to React's builtin `useState` hook.\n *\n * @example\n *\n * ```jsx\n * function YourComponent() {\n * const mySignal = useReactive();\n * const someEventHandler = () => {\n * // Update the value after some event\n * mySignal.value = \"new value\";\n * };\n *\n * // Always returns the current value, re-renders if necessary.\n * const currentValue = useReactiveValue(mySignal);\n * }\n * ```\n */\nexport function useReactive<T>(): Reactive<T | undefined>;\n\n/**\n * Creates a new signal with the given initial value.\n *\n * @see {@link useReactive()}.\n */\nexport function useReactive<T>(initialValue: T): Reactive<T>;\n\nexport function useReactive<T>(initialValue?: T): Reactive<T | undefined> {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return useMemo(() => reactive(initialValue), []);\n}\n\n/**\n * Creates a new computed signal that evaluates the given `compute` function.\n *\n * The hook returns the same signal for as long as `deps` remains the same.\n * When `deps` change, a new signal will be created.\n *\n * @example\n *\n * Defining a simple computed value in your react component:\n *\n * ```jsx\n * function MyComponent(props) {\n * // Creates a computed value based on the given function.\n * // The computed value will be re-created whenever one of the listed dependencies changes.\n * // While the computed value can track all its _reactive_ dependencies automatically (`.value` reads etc.)\n * // the reactive value itself used here might change (different props) - this cannot be detected automatically.\n * const computed = useComputed(() => props.someReactive.value * 2, [props.someReactive]);\n *\n * // Watches on `computed` and returns its current value.\n * const currentValue = useReactiveValue(computed);\n * }\n * ```\n *\n * > If the body of your compute function depends on non-reactive values (such as react props or state),\n * > list those values in the `deps` array.\n *\n * @see {@link useReactiveValue()}\n * @see {@link useReactiveSnapshot()}\n */\nexport function useComputed<T>(compute: () => T, deps: DependencyList): ReadonlyReactive<T> {\n const computeRef = useRef(compute);\n computeRef.current = compute;\n\n const computedDeps = useComputedDeps(deps);\n return useMemo(() => {\n void computedDeps; // not really used, but computed must be recreated when this value changes\n return computed(() => computeRef.current());\n }, [computedDeps]);\n}\n\n/**\n * Watches the given reactive object and returns its current value.\n *\n * > NOTE: The return value of this hook should be considered read-only.\n *\n * @see {@link useComputed()}\n */\nexport function useReactiveValue<T>(reactive: ReadonlyReactive<T>): T {\n const getSnapshot = useCallback(() => {\n return reactive.peek();\n }, [reactive]);\n const subscribe = useCallback(\n (cb: () => void) => {\n const handle = watch(() => [reactive.value], cb);\n return () => handle.destroy();\n },\n [reactive]\n );\n const value = useSyncExternalStore(subscribe, getSnapshot);\n useDebugValue(value);\n return value;\n}\n\n/**\n * Evaluates the `compute` function and returns its result.\n *\n * The body of the compute function is tracked: it\n * will be re-evaluated whenever its reactive dependencies change.\n * The outer react component will re-render whenever `compute` returns a new value.\n *\n * > NOTE: The return value of this hook should be considered read-only.\n *\n * @example\n *\n * Simple Example:\n *\n * ```jsx\n * // A reactive signal from anywhere (global data, props, ...).\n * const name = reactive(\"User\");\n *\n * function YourComponent() {\n * const nameSnapshot = useReactiveSnapshot(() => name.value);\n * // snapshot is automatically up to date\n * }\n * ```\n *\n * @example\n *\n * Multiple values, with props:\n *\n * ```jsx\n * function YourComponent({firstName, lastName}) {\n * // You can use complex expressions in your compute function,\n * // just like in a computed signal.\n * // React-dependencies used in the callback must be listed in the second argument,\n * // just like when using `useMemo()` or `useEffect`.\n * const snapshot = useReactiveSnapshot(() => {\n * return {\n * firstName: firstName.value,\n * lastName: lastName.value,\n * fullName: `${firstName.value} ${lastName.value}`\n * };\n * }, [firstName, lastName]);\n * // snapshot.firstName, snapshot.lastName, snapshot.fullName are available and up to date\n * }\n * ```\n *\n * @see\n * This hook is based on {@link useComputed()} and {@link useReactiveValue()}.\n */\nexport function useReactiveSnapshot<T>(compute: () => T, deps: DependencyList): T {\n // We create an internal computed value that executes the compute function;\n // this way the implementation of `compute` is automatically tracked.\n // getSnapshot and subscribe simply watch the current value of that computed value.\n // eslint-disable-next-line react-hooks/exhaustive-deps\n const computedSnapshot = useComputed(compute, deps);\n const snapshot = useReactiveValue(computedSnapshot);\n useDebugValue(snapshot);\n return snapshot;\n}\n\nfunction useComputedDeps(deps: DependencyList): DependencyList {\n const computedDeps = useRef<DependencyList>(null);\n if (computedDeps.current == null || !shallowEqual(computedDeps.current, deps)) {\n computedDeps.current = deps ?? [];\n }\n return computedDeps.current;\n}\n\nfunction shallowEqual(a: DependencyList, b: DependencyList): boolean {\n if (a === b) {\n return true;\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return a.length === (b?.length ?? 0) && a.every((v, i) => v === b![i]);\n}\n"],"names":["reactive"],"mappings":";;;AA2CO,SAAS,YAAe,YAAA,EAA2C;AAEtE,EAAA,OAAO,QAAQ,MAAM,QAAA,CAAS,YAAY,CAAA,EAAG,EAAE,CAAA;AACnD;AA+BO,SAAS,WAAA,CAAe,SAAkB,IAAA,EAA2C;AACxF,EAAA,MAAM,UAAA,GAAa,OAAO,OAAO,CAAA;AACjC,EAAA,UAAA,CAAW,OAAA,GAAU,OAAA;AAErB,EAAA,MAAM,YAAA,GAAe,gBAA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AAA;AACxB;AAEA,SAAS,YAAA,CAAa,GAAmB,CAAA,EAA4B;AACjE,EAAA,IAAI,MAAM,CAAA,EAAG;AACT,IAAA,OAAO,IAAA;AAAA,EACX;AAEA,EAAA,OAAO,CAAA,CAAE,MAAA,MAAY,CAAA,EAAG,MAAA,IAAU,CAAA,CAAA,IAAM,CAAA,CAAE,KAAA,CAAM,CAAC,CAAA,EAAG,CAAA,KAAM,CAAA,KAAM,CAAA,CAAG,CAAC,CAAC,CAAA;AACzE;;;;"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@open-pioneer/reactivity",
|
|
4
|
-
"version": "4.
|
|
4
|
+
"version": "4.2.0-dev.20251021072202",
|
|
5
5
|
"description": "Provides integration for the reactivity API.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"open-pioneer-trails"
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"directory": "src/packages/reactivity"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"react": "^19.
|
|
18
|
-
"@conterra/reactivity-core": "^0.
|
|
17
|
+
"react": "^19.2.0",
|
|
18
|
+
"@conterra/reactivity-core": "^0.8.0"
|
|
19
19
|
},
|
|
20
20
|
"exports": {
|
|
21
21
|
"./package.json": "./package.json",
|