@volynets/reflex-store 0.0.0-stage → 0.0.2
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/LICENSE +21 -0
- package/README.md +237 -2
- package/SPECIFICATION.md +137 -0
- package/dist/advanced.d.ts +12 -0
- package/dist/advanced.js +10 -0
- package/dist/chunks/collections-yHy0wH0f.js +268 -0
- package/dist/chunks/compiler-Dsb3E2ck.js +2516 -0
- package/dist/chunks/createStore-DHj16Ehk.js +12 -0
- package/dist/chunks/hydrate-DMnHCI5q.js +138 -0
- package/dist/chunks/keyed-CQKtL8a7.js +383 -0
- package/dist/chunks/names-Cx4YcvsH.js +11 -0
- package/dist/chunks/values-DCB6zyMz.js +142 -0
- package/dist/compiled-store.d.ts +4 -0
- package/dist/compiled-store.js +4 -0
- package/dist/compiler/swc.wasm +0 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +8 -0
- package/dist/licenses/NOTICE.txt +1 -0
- package/dist/licenses/SWC-APACHE-2.0.txt +202 -0
- package/dist/runtime/core.d.ts +2 -0
- package/dist/runtime/core.js +1 -0
- package/dist/runtime/internal.d.ts +3 -0
- package/dist/runtime/internal.js +41 -0
- package/dist/runtime.d.ts +29 -0
- package/dist/runtime.js +88 -0
- package/dist/selectors/index.d.ts +13 -0
- package/dist/selectors/index.js +16 -0
- package/dist/selectors/shared.d.ts +3 -0
- package/dist/selectors/shared.js +64 -0
- package/dist/store.d.ts +9 -0
- package/dist/store.js +4 -0
- package/dist/types/contracts-BCsRPdQb.d.ts +78 -0
- package/dist/types/createStore-BJ66-pfq.d.ts +43 -0
- package/dist/types/internal-BIzJSPwN.d.ts +18 -0
- package/dist/types/keyed-CdSYzIOc.d.ts +18 -0
- package/dist/types/shared-CdTKzvLe.d.ts +114 -0
- package/dist/vite.d.ts +68 -0
- package/dist/vite.js +87 -0
- package/examples/task-board/README.md +15 -0
- package/examples/task-board/src/reactivity.ts +33 -0
- package/examples/task-board/src/task-board.ts +159 -0
- package/examples/task-board/vite.config.ts +6 -0
- package/package.json +119 -4
- package/src/store/README.md +59 -0
- package/src/store/TRANSFORM_SPEC.md +85 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# Compiled static stores
|
|
2
|
+
|
|
3
|
+
The root createStore API requires the compiler. Import the plugin from
|
|
4
|
+
@volynets/reflex-store/vite or use compileStore from /store.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import {
|
|
8
|
+
createStore,
|
|
9
|
+
leaf,
|
|
10
|
+
opaque,
|
|
11
|
+
snapshot,
|
|
12
|
+
hydrate,
|
|
13
|
+
} from "@volynets/reflex-store";
|
|
14
|
+
|
|
15
|
+
export function createCounter() {
|
|
16
|
+
const state = createStore(
|
|
17
|
+
{
|
|
18
|
+
count: 0,
|
|
19
|
+
history: leaf<readonly number[]>([]),
|
|
20
|
+
engine: opaque(new Engine()),
|
|
21
|
+
get doubled() {
|
|
22
|
+
return this.count * 2;
|
|
23
|
+
},
|
|
24
|
+
increment() {
|
|
25
|
+
this.count++;
|
|
26
|
+
this.history = [...this.history, this.count];
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{ name: "Counter" },
|
|
30
|
+
);
|
|
31
|
+
return state;
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Factories allocate independent cells, computed getters and action methods.
|
|
36
|
+
Static data accesses lower to direct cell calls. Root methods are bound actions;
|
|
37
|
+
getters are owned lazy computeds. Snapshot extraction excludes methods/getters.
|
|
38
|
+
Hydration validates the complete data schema before batched restoration.
|
|
39
|
+
|
|
40
|
+
The compiler accepts data properties with unique static keys. Literal objects
|
|
41
|
+
form branches; leaf/opaque imports (including aliases) define single replaceable
|
|
42
|
+
locations. Arrays use replacement semantics.
|
|
43
|
+
|
|
44
|
+
Unsupported syntax is diagnosed: spreads, shorthand, **proto**, reserved lifecycle
|
|
45
|
+
names, setter properties, nested methods/getters, async/generator methods, dynamic
|
|
46
|
+
paths, branch aliases, delete, optional chaining, structural replacement and
|
|
47
|
+
arbitrary root reflection. Getters must not write store state.
|
|
48
|
+
|
|
49
|
+
Use eraseFacade to remove objects proven unnecessary for direct data-cell uses.
|
|
50
|
+
Returned stores, computed getters, action methods and lifecycle/data boundaries
|
|
51
|
+
retain their facade.
|
|
52
|
+
|
|
53
|
+
The default lowering imports createStoreScope from /runtime and cells from
|
|
54
|
+
/runtime/internal. The scope uses the shared Framework LifecycleScope for resource
|
|
55
|
+
ownership and rollback, and adds the Store action boundary. It has no model
|
|
56
|
+
shape validation or capability brands. Custom scope/signal lowering remains
|
|
57
|
+
available for data-only stores through loweringTarget; the legacy model option
|
|
58
|
+
is a compatibility alias for curried factory targets.
|
|
59
|
+
See [TRANSFORM_SPEC.md](./TRANSFORM_SPEC.md).
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Compiled store transform contract
|
|
2
|
+
|
|
3
|
+
## Recognition and declarations
|
|
4
|
+
|
|
5
|
+
Recognize createStore imports from @volynets/reflex-store, /advanced, /store and
|
|
6
|
+
/compiled-store, including aliases. Match binding identity, not text alone.
|
|
7
|
+
The compiler API may recognize unresolved bare createStore calls; the Vite plugin
|
|
8
|
+
requires a matching import unless compileBareCreateStore is enabled.
|
|
9
|
+
|
|
10
|
+
Lexical module/function/block declarations are supported. Each execution of a
|
|
11
|
+
local declaration allocates independent store resources. Inline return
|
|
12
|
+
createStore(...) and loop-header declarations remain diagnosed.
|
|
13
|
+
|
|
14
|
+
## Shape and boundaries
|
|
15
|
+
|
|
16
|
+
Accept unique static data keys, root method declarations and root getter
|
|
17
|
+
declarations. Literal data objects become branches. Imported leaf(value) and
|
|
18
|
+
opaque(value) calls define one replaceable location. Preserve opaque marking.
|
|
19
|
+
Optional options require a static name string.
|
|
20
|
+
|
|
21
|
+
Data initializers execute once in source order for each declaration execution.
|
|
22
|
+
Data leaf reads are direct address calls. Producers materialize on tracked reads.
|
|
23
|
+
|
|
24
|
+
## Methods and getters
|
|
25
|
+
|
|
26
|
+
Root methods become bound ctx.action callbacks. Rewrite their store this
|
|
27
|
+
references to the declaration binding, preserving lexical-arrow this and leaving
|
|
28
|
+
nested ordinary function/class receivers intact. Lower static leaf reads/writes
|
|
29
|
+
inside the callbacks as usual. Multi-write methods close one outer host/runtime
|
|
30
|
+
batch.
|
|
31
|
+
|
|
32
|
+
Root getters become owned createDisposableComputed accessors. Their this
|
|
33
|
+
references lower to store locations. Clean reads cache; writes invalidate and
|
|
34
|
+
pull reads compute current data. Getters cannot write store state or suspend.
|
|
35
|
+
Async/generator methods, setters and nested methods/getters are unsupported.
|
|
36
|
+
|
|
37
|
+
## Writes and JavaScript order
|
|
38
|
+
|
|
39
|
+
Support =, +=, -=, prefix/postfix ++ and -- on declared data leaves.
|
|
40
|
+
Evaluate the previous value before a compound RHS, evaluate the RHS once and
|
|
41
|
+
then commit the result. Update operators preserve JavaScript ToNumeric,
|
|
42
|
+
including strings, undefined, NaN, signed zero and BigInt. Exceptions before
|
|
43
|
+
commit preserve the previous value; action exceptions close batches.
|
|
44
|
+
|
|
45
|
+
## Facade, ownership and extraction
|
|
46
|
+
|
|
47
|
+
The generated facade contains data accessors, getter accessors, bound actions,
|
|
48
|
+
dispose and Symbol.dispose. A Store scope owns cells and computed getter resources
|
|
49
|
+
through Framework's LifecycleScope. Cells are allocated and adopted inside the
|
|
50
|
+
scope setup callback, preserving initializer order. Setup failures roll back all
|
|
51
|
+
resources already owned and rethrow the original cause. Actions reject terminal
|
|
52
|
+
use in production and development; raw cells expose Symbol.dispose.
|
|
53
|
+
Static hidden control callbacks extract only data fields and restore values to
|
|
54
|
+
known cells. Returning a facade (also within a factory return object) is supported.
|
|
55
|
+
|
|
56
|
+
snapshot/hydrate imports are recognized intrinsic data boundaries. own(ctx, state)
|
|
57
|
+
and getStoreName(state) are recognized ownership/diagnostic boundaries. Runtime
|
|
58
|
+
snapshot invokes the generated extraction untracked, preserving structural graph
|
|
59
|
+
semantics. Hydration validates the exact compiled branch/leaf schema before one
|
|
60
|
+
batched write. Empty branches are represented explicitly.
|
|
61
|
+
|
|
62
|
+
eraseFacade is opt-in. Omit a facade only if every use can lower to declared data
|
|
63
|
+
cells and no method/getter/escape/lifecycle/data boundary needs the object.
|
|
64
|
+
|
|
65
|
+
## Runtime and tooling
|
|
66
|
+
|
|
67
|
+
Default imports use createStoreScope from @volynets/reflex-store/runtime and
|
|
68
|
+
createStoreCell from /runtime/internal. The compiler does not call createModel
|
|
69
|
+
or defineModel. The target delegates lifecycle policy to the shared Framework
|
|
70
|
+
package, and keeps host/runtime imports external. The Vite plugin preserves
|
|
71
|
+
application package resolution.
|
|
72
|
+
|
|
73
|
+
Custom data-only lowering targets configure scope/signal names and generated
|
|
74
|
+
identifiers. Scope targets return the constructed value directly; curried: true
|
|
75
|
+
supports factories returning a zero-argument constructor. The deprecated model
|
|
76
|
+
option remains an alias with curried: true for existing custom targets.
|
|
77
|
+
Getter/method lowering requires the default Store scope target.
|
|
78
|
+
The compiler includes portable SWC WASM and validates its normalized function AST
|
|
79
|
+
before printing. Names are store metadata and never modify kernel hot paths.
|
|
80
|
+
|
|
81
|
+
## Diagnostics
|
|
82
|
+
|
|
83
|
+
Diagnose unsupported shapes and mutations before erasure. Collect mode returns
|
|
84
|
+
the original code when diagnostics exist. No partial transform is published for
|
|
85
|
+
an unsupported source module.
|