@signal-tree/vue 15.1.1 → 15.1.3
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/README.md +59 -0
- package/dist/index.js +1 -1
- package/dist/lib/construction-input.js +1 -0
- package/package.json +2 -2
- package/src/index.d.ts +3 -2
- package/src/lib/construction-input.d.ts +9 -0
package/README.md
CHANGED
|
@@ -35,3 +35,62 @@ console.log(tree.$.greeting.value); // Hello, Grace
|
|
|
35
35
|
The ref can be passed directly to `watch()`, `computed()`, or `v-model`.
|
|
36
36
|
Object branches and the root `$` remain callable whole-value accessors. Vue owns
|
|
37
37
|
dependency tracking; the kernel remains the only state and write authority.
|
|
38
|
+
|
|
39
|
+
## Initial values and external reactivity
|
|
40
|
+
|
|
41
|
+
Pass plain initial values to `signalTree()`. Existing Vue refs, computed refs,
|
|
42
|
+
and reactive or readonly proxies at the root or a nested branch are rejected
|
|
43
|
+
with a path-specific error. Ref types are also rejected by TypeScript; proxies
|
|
44
|
+
require runtime checks because their types can look like ordinary objects.
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { ref } from 'vue';
|
|
48
|
+
import { leaf, signalTree } from '@signal-tree/vue';
|
|
49
|
+
|
|
50
|
+
const existing = ref(1);
|
|
51
|
+
const tree = signalTree({ count: leaf(existing.value) });
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
This takes an independent scalar snapshot. For objects, copy the needed values
|
|
55
|
+
into plain data; `toRaw()` alone shares the underlying object and is not an
|
|
56
|
+
independent copy. `leaf(existing)` explicitly stores a ref or proxy as data.
|
|
57
|
+
Its inner mutations remain outside tree transactions and restoration.
|
|
58
|
+
|
|
59
|
+
Validation stops at explicit `leaf(...)`, marker definitions, arrays and built-in
|
|
60
|
+
terminal values. Their contents remain data, not separately owned tree locations.
|
|
61
|
+
Ordinary functions remain valid callable data. These checks apply to initial
|
|
62
|
+
construction, not arbitrary later writes or foreign reactivity from other libraries.
|
|
63
|
+
|
|
64
|
+
## Ownership and disposal
|
|
65
|
+
|
|
66
|
+
`signalTree()` constructs a tree; it does not register scope cleanup. A tree owns
|
|
67
|
+
runtime resources until `destroy()` is called. Dropping its last reference is not
|
|
68
|
+
prompt resource reclamation.
|
|
69
|
+
|
|
70
|
+
For a component- or composable-owned tree, construct it inside the active Vue
|
|
71
|
+
scope and register its disposal there:
|
|
72
|
+
|
|
73
|
+
```ts
|
|
74
|
+
import { onScopeDispose } from 'vue';
|
|
75
|
+
import { signalTree } from '@signal-tree/vue';
|
|
76
|
+
|
|
77
|
+
// Call synchronously during setup() or inside an active effectScope().
|
|
78
|
+
function useCounter() {
|
|
79
|
+
const tree = signalTree({ count: 0 });
|
|
80
|
+
onScopeDispose(() => tree.destroy());
|
|
81
|
+
return tree;
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Stopping the owning scope destroys the tree. A component that receives a tree
|
|
86
|
+
through props or `inject()` only borrows it: do not register destruction in that
|
|
87
|
+
consumer's scope. Shared application stores belong to the application owner,
|
|
88
|
+
which can use ordinary `provide()`/`inject()` to distribute them and call
|
|
89
|
+
`destroy()` after unmounting the application.
|
|
90
|
+
|
|
91
|
+
For SSR, construct a fresh tree for each request, provide it to that request's
|
|
92
|
+
application, and destroy it in `finally` after awaited rendering finishes. Do not
|
|
93
|
+
rely on component unmount hooks for request cleanup or share a module-level tree
|
|
94
|
+
between requests. With streaming rendering, wait for completion or abort before
|
|
95
|
+
destroying the request owner. Construct the client tree from the same initial
|
|
96
|
+
state used for the server output before hydration.
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{asReadonly as asReadonly$1}from"@signal-tree/kernel";export*from"@signal-tree/kernel";import{createSignalTreeFactory}from"@signal-tree/kernel/adapter";import{createVueObservationAdapter}from"./lib/vue-observation.js";const signalTree=(initialState,config)=>createSignalTreeFactory(createVueObservationAdapter())(initialState,config);const asReadonly=asReadonly$1;export{asReadonly,signalTree};
|
|
1
|
+
import{asReadonly as asReadonly$1}from"@signal-tree/kernel";export*from"@signal-tree/kernel";import{createSignalTreeFactory}from"@signal-tree/kernel/adapter";import{prepareConstructionInput}from"./lib/construction-input.js";import{createVueObservationAdapter}from"./lib/vue-observation.js";const signalTree=(initialState,config)=>createSignalTreeFactory(createVueObservationAdapter())(prepareConstructionInput(initialState),config);const asReadonly=asReadonly$1;export{asReadonly,signalTree};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isRef,isProxy}from"vue";import{isConstructionBranch}from"@signal-tree/kernel/adapter";function prepareConstructionInput(initialState){const branches=new WeakMap;const visit=(value,path)=>{if(isRef(value)||isProxy(value)){throw new TypeError(`SignalTree: Vue ref or proxy at ${path}. Pass plain initial values (copy ref.value into an independent snapshot). Use leaf(existing) only to store the reactive object as data; its writes remain external to the tree.`)}if(!isConstructionBranch(value))return value;const previous=branches.get(value);if(previous)return previous;const prepared=Object.create(null);branches.set(value,prepared);for(const key of Object.getOwnPropertySymbols(value)){const descriptor=Object.getOwnPropertyDescriptor(value,key);if(descriptor)Object.defineProperty(prepared,key,descriptor)}for(const[key,child]of Object.entries(value)){prepared[key]=key==="__proto__"?child:visit(child,`${path}[${JSON.stringify(key)}]`)}return prepared};return visit(initialState,"$")}export{prepareConstructionInput};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@signal-tree/vue",
|
|
3
|
-
"version": "15.1.
|
|
3
|
+
"version": "15.1.3",
|
|
4
4
|
"description": "Vue observation for SignalTree.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"llms.txt"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@signal-tree/kernel": "15.1.
|
|
28
|
+
"@signal-tree/kernel": "15.1.3"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"tslib": "^2.0.0",
|
package/src/index.d.ts
CHANGED
|
@@ -6,9 +6,10 @@
|
|
|
6
6
|
* @packageDocumentation
|
|
7
7
|
*/
|
|
8
8
|
import './lib/carrier.js';
|
|
9
|
-
import { type AccessibleNodeOf, type EntityNodeOf, type EntitySignalOf, type EntitySignalWithSlicesOf, type ISignalTreeOf, type LeafOf, type ReadonlyStoreOf, type ReadonlyViewOf, type
|
|
9
|
+
import { type AccessibleNodeOf, type EntityNodeOf, type EntitySignalOf, type EntitySignalWithSlicesOf, type ISignalTreeOf, type LeafOf, type ReadonlyStoreOf, type ReadonlyViewOf, type TreeNodeOf } from '@signal-tree/kernel/adapter';
|
|
10
|
+
import { type FrameworkSignalTreeFactory } from './lib/construction-input.js';
|
|
10
11
|
/** Construct a SignalTree whose leaves are native Vue refs. */
|
|
11
|
-
export declare const signalTree:
|
|
12
|
+
export declare const signalTree: FrameworkSignalTreeFactory;
|
|
12
13
|
export type TreeNode<T> = TreeNodeOf<T, 'vue'>;
|
|
13
14
|
export type WritableLeaf<T> = LeafOf<T, 'vue'>;
|
|
14
15
|
export type AccessibleNode<T> = AccessibleNodeOf<T, 'vue'>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type Ref } from 'vue';
|
|
2
|
+
import type { SignalTreeFactoryOf } from '@signal-tree/kernel/adapter';
|
|
3
|
+
export type FrameworkSignalTreeFactory = SignalTreeFactoryOf<'vue', Ref<unknown>>;
|
|
4
|
+
/**
|
|
5
|
+
* Read each branch property once, so accessor-backed definitions cannot change
|
|
6
|
+
* between validation and construction. Terminal data retains its identity.
|
|
7
|
+
* No reactive primitive is read, subscribed to, or adopted here.
|
|
8
|
+
*/
|
|
9
|
+
export declare function prepareConstructionInput(initialState: object): object;
|