@solidjs/signals 2.0.0-rc.2 → 2.0.0-rc.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/dev.js +1454 -118
- package/dist/node.cjs +2709 -1396
- package/dist/prod/affects.js +13 -12
- package/dist/prod/boundaries.js +39 -34
- package/dist/prod/core/action.js +3 -3
- package/dist/prod/core/async.js +48 -46
- package/dist/prod/core/core.js +99 -67
- package/dist/prod/core/effect.js +25 -28
- package/dist/prod/core/external.js +2 -2
- package/dist/prod/core/graph.js +85 -49
- package/dist/prod/core/heap.js +10 -10
- package/dist/prod/core/lanes.js +19 -19
- package/dist/prod/core/optimistic.js +66 -41
- package/dist/prod/core/owner.js +13 -13
- package/dist/prod/core/scheduler.js +131 -85
- package/dist/prod/core/verdict.js +36 -15
- package/dist/prod/index.js +4 -0
- package/dist/prod/map.js +101 -101
- package/dist/prod/signals.js +1 -1
- package/dist/prod/store/index.js +2 -0
- package/dist/prod/store/next/optimistic.js +65 -11
- package/dist/prod/store/next/patch-hooks.js +13 -0
- package/dist/prod/store/next/patch.js +614 -0
- package/dist/prod/store/next/projection.js +107 -45
- package/dist/prod/store/next/reconcile.js +307 -120
- package/dist/prod/store/next/store.js +321 -92
- package/dist/prod/store/next/target.js +13 -4
- package/dist/prod/store/store.js +5 -5
- package/dist/types/core/core.d.ts +15 -1
- package/dist/types/core/dev.d.ts +8 -0
- package/dist/types/core/graph.d.ts +22 -0
- package/dist/types/core/invariants.d.ts +1 -1
- package/dist/types/core/scheduler.d.ts +12 -0
- package/dist/types/store/index.d.ts +2 -0
- package/dist/types/store/next/patch-hooks.d.ts +41 -0
- package/dist/types/store/next/patch.d.ts +91 -0
- package/dist/types/store/next/reconcile.d.ts +14 -0
- package/dist/types/store/next/store.d.ts +30 -2
- package/dist/types/store/next/target.d.ts +58 -8
- package/dist/types-cjs/core/core.d.cts +15 -1
- package/dist/types-cjs/core/dev.d.cts +8 -0
- package/dist/types-cjs/core/graph.d.cts +22 -0
- package/dist/types-cjs/core/invariants.d.cts +1 -1
- package/dist/types-cjs/core/scheduler.d.cts +12 -0
- package/dist/types-cjs/store/index.d.cts +2 -0
- package/dist/types-cjs/store/next/patch-hooks.d.cts +41 -0
- package/dist/types-cjs/store/next/patch.d.cts +91 -0
- package/dist/types-cjs/store/next/reconcile.d.cts +14 -0
- package/dist/types-cjs/store/next/store.d.cts +30 -2
- package/dist/types-cjs/store/next/target.d.cts +58 -8
- package/package.json +14 -14
- package/dist/types/store/optimistic.d.ts +0 -45
- package/dist/types/store/projection.d.ts +0 -70
- package/dist/types/store/reconcile.d.ts +0 -46
- package/dist/types-cjs/store/optimistic.d.cts +0 -45
- package/dist/types-cjs/store/projection.d.cts +0 -70
- package/dist/types-cjs/store/reconcile.d.cts +0 -46
|
@@ -33,81 +33,143 @@ import { wrapNext, storeSetterNext } from "./store.js";
|
|
|
33
33
|
* loading windows, handleAsync landings, commit-through-setter) on next
|
|
34
34
|
* primitives; the generic draft write-traps are reused from the legacy
|
|
35
35
|
* module unchanged.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* Wrap a store proxy as a projection DRAFT: every operation carries the write
|
|
39
|
+
* override (the derive is the author — its ops must not hit the §6c firewall
|
|
40
|
+
* gate, even in a continuation after an `await`/`yield` where the sync write
|
|
41
|
+
* scope has closed).
|
|
42
|
+
*
|
|
43
|
+
* FAKE TARGET, not the store proxy itself (#3060): after a proxy trap
|
|
44
|
+
* returns, the engine runs spec invariant validation against the proxy's
|
|
45
|
+
* TARGET — [[OwnPropertyKeys]] after ownKeys, [[GetOwnProperty]] after
|
|
46
|
+
* set/getOwnPropertyDescriptor/defineProperty. With the store proxy as
|
|
47
|
+
* target those checks re-enter the store's traps OUTSIDE the override
|
|
48
|
+
* bracket (the trap's finally has already run), so `Object.keys(state)` in
|
|
49
|
+
* a derive continuation fired the firewall gate and re-threw the
|
|
50
|
+
* projection's own pending NotReadyError into the derive. A dummy of
|
|
51
|
+
* matching kind (array/object, same trick as the store's own TargetShape)
|
|
52
|
+
* keeps invariant validation away from the store entirely; the traps
|
|
53
|
+
* forward to the closed-over inner proxy inside the bracket.
|
|
54
|
+
*
|
|
55
|
+
* Save/restore projectionWriteActive, never hard-reset: the draft can be
|
|
56
|
+
* driven from inside an enclosing authoritative-write scope (next-store
|
|
57
|
+
* optimistic derives), and a hard `false` would clobber it mid-derive.
|
|
58
|
+
*/ function wrapDraft(e, t, r) {
|
|
59
|
+
const i = {
|
|
60
|
+
get(i, o) {
|
|
61
|
+
let n;
|
|
62
|
+
const c = projectionWriteActive;
|
|
44
63
|
setWriteOverride(true);
|
|
45
64
|
setProjectionWriteActive(true);
|
|
46
65
|
try {
|
|
47
|
-
|
|
66
|
+
n = e[o];
|
|
48
67
|
} finally {
|
|
49
68
|
setWriteOverride(false);
|
|
50
|
-
setProjectionWriteActive(
|
|
69
|
+
setProjectionWriteActive(c);
|
|
51
70
|
}
|
|
52
|
-
if (
|
|
53
|
-
return typeof
|
|
71
|
+
if (o === $TARGET) return n;
|
|
72
|
+
return typeof n === "object" && n !== null ? wrapDraft(n, t, r) : n;
|
|
54
73
|
},
|
|
55
|
-
has(
|
|
56
|
-
let
|
|
74
|
+
has(t, r) {
|
|
75
|
+
let i;
|
|
57
76
|
const o = projectionWriteActive;
|
|
58
77
|
setWriteOverride(true);
|
|
59
78
|
setProjectionWriteActive(true);
|
|
60
79
|
try {
|
|
61
|
-
|
|
80
|
+
i = r in e;
|
|
62
81
|
} finally {
|
|
63
82
|
setWriteOverride(false);
|
|
64
83
|
setProjectionWriteActive(o);
|
|
65
84
|
}
|
|
66
|
-
return
|
|
85
|
+
return i;
|
|
86
|
+
},
|
|
87
|
+
set(i, o, n) {
|
|
88
|
+
if (t && !t()) return true;
|
|
89
|
+
const c = projectionWriteActive;
|
|
90
|
+
setWriteOverride(true);
|
|
91
|
+
setProjectionWriteActive(true);
|
|
92
|
+
try {
|
|
93
|
+
e[o] = n;
|
|
94
|
+
r?.();
|
|
95
|
+
} finally {
|
|
96
|
+
setWriteOverride(false);
|
|
97
|
+
setProjectionWriteActive(c);
|
|
98
|
+
}
|
|
99
|
+
return true;
|
|
67
100
|
},
|
|
68
|
-
|
|
69
|
-
if (
|
|
101
|
+
deleteProperty(i, o) {
|
|
102
|
+
if (t && !t()) return true;
|
|
70
103
|
const n = projectionWriteActive;
|
|
71
104
|
setWriteOverride(true);
|
|
72
105
|
setProjectionWriteActive(true);
|
|
73
106
|
try {
|
|
74
|
-
|
|
75
|
-
|
|
107
|
+
delete e[o];
|
|
108
|
+
r?.();
|
|
76
109
|
} finally {
|
|
77
110
|
setWriteOverride(false);
|
|
78
111
|
setProjectionWriteActive(n);
|
|
79
112
|
}
|
|
80
113
|
return true;
|
|
81
114
|
},
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
115
|
+
ownKeys() {
|
|
116
|
+
const t = projectionWriteActive;
|
|
117
|
+
setWriteOverride(true);
|
|
118
|
+
setProjectionWriteActive(true);
|
|
119
|
+
try {
|
|
120
|
+
return Reflect.ownKeys(e);
|
|
121
|
+
} finally {
|
|
122
|
+
setWriteOverride(false);
|
|
123
|
+
setProjectionWriteActive(t);
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
getOwnPropertyDescriptor(t, r) {
|
|
127
|
+
let i;
|
|
128
|
+
const o = projectionWriteActive;
|
|
129
|
+
setWriteOverride(true);
|
|
130
|
+
setProjectionWriteActive(true);
|
|
131
|
+
try {
|
|
132
|
+
i = Reflect.getOwnPropertyDescriptor(e, r);
|
|
133
|
+
} finally {
|
|
134
|
+
setWriteOverride(false);
|
|
135
|
+
setProjectionWriteActive(o);
|
|
136
|
+
}
|
|
137
|
+
// The dummy target doesn't hold the key, so a non-configurable report
|
|
138
|
+
// would violate the proxy invariant. Store descriptors are already
|
|
139
|
+
// normalized configurable; enforce it for raw leaves too.
|
|
140
|
+
if (i) i.configurable = true;
|
|
141
|
+
return i;
|
|
142
|
+
},
|
|
143
|
+
defineProperty(i, o, n) {
|
|
144
|
+
if (t && !t()) return true;
|
|
145
|
+
const c = projectionWriteActive;
|
|
85
146
|
setWriteOverride(true);
|
|
86
147
|
setProjectionWriteActive(true);
|
|
87
148
|
try {
|
|
88
|
-
|
|
89
|
-
|
|
149
|
+
Reflect.defineProperty(e, o, n);
|
|
150
|
+
r?.();
|
|
90
151
|
} finally {
|
|
91
152
|
setWriteOverride(false);
|
|
92
|
-
setProjectionWriteActive(
|
|
153
|
+
setProjectionWriteActive(c);
|
|
93
154
|
}
|
|
94
155
|
return true;
|
|
95
156
|
}
|
|
96
157
|
};
|
|
97
|
-
|
|
158
|
+
// Matching-kind dummy so Array.isArray(draft) answers like the store.
|
|
159
|
+
return new Proxy(Array.isArray(e) ? [] : {}, i);
|
|
98
160
|
}
|
|
99
161
|
|
|
100
162
|
function createProjectionNextInternal(e, t, r) {
|
|
101
|
-
const
|
|
163
|
+
const i = {
|
|
102
164
|
map: new WeakMap,
|
|
103
165
|
node: null,
|
|
104
166
|
shallow: !!r?.shallow
|
|
105
167
|
};
|
|
106
|
-
const
|
|
107
|
-
if (
|
|
168
|
+
const o = wrapNext(t, null, null, i);
|
|
169
|
+
if (i.shallow) {
|
|
108
170
|
// Shallow projection: the root is the only wrapped level — slot values
|
|
109
171
|
// serve raw, ingests sticky raw-mark (same t.s machinery as plain).
|
|
110
|
-
|
|
172
|
+
o[$TARGET].s = true;
|
|
111
173
|
markRawIngest(t);
|
|
112
174
|
}
|
|
113
175
|
let n;
|
|
@@ -115,13 +177,13 @@ function createProjectionNextInternal(e, t, r) {
|
|
|
115
177
|
loadingValue: undefined
|
|
116
178
|
};
|
|
117
179
|
const c = computed(() => {
|
|
118
|
-
if (!
|
|
119
|
-
runProjectionComputedNext(
|
|
180
|
+
if (!i.node) i.node = getOwner();
|
|
181
|
+
runProjectionComputedNext(o, e, r?.key === undefined ? "id" : r.key);
|
|
120
182
|
}, n);
|
|
121
183
|
c.T &= ~CONFIG_AUTO_DISPOSE;
|
|
122
|
-
|
|
184
|
+
i.node = c;
|
|
123
185
|
return {
|
|
124
|
-
store:
|
|
186
|
+
store: o,
|
|
125
187
|
node: c
|
|
126
188
|
};
|
|
127
189
|
}
|
|
@@ -133,15 +195,15 @@ function createProjectionNext(e, t, r) {
|
|
|
133
195
|
/** Derived writable store (legacy parity): a projection whose public setter
|
|
134
196
|
* masks the recompute for the tick (core R31 — the manual write wins over a
|
|
135
197
|
* same-flush dependency change). */ function createStoreDerivedNext(e, t, r) {
|
|
136
|
-
const {store:
|
|
137
|
-
return [
|
|
198
|
+
const {store: i, node: o} = createProjectionNextInternal(e, t, r);
|
|
199
|
+
return [ i, e => {
|
|
138
200
|
// Mark the projection as manually written before notifying nodes.
|
|
139
|
-
suppressComputedRecompute(
|
|
140
|
-
storeSetterNext(
|
|
201
|
+
suppressComputedRecompute(o);
|
|
202
|
+
storeSetterNext(i, e);
|
|
141
203
|
} ];
|
|
142
204
|
}
|
|
143
205
|
|
|
144
|
-
function runProjectionComputedNext(e, t, r,
|
|
206
|
+
function runProjectionComputedNext(e, t, r, i, o) {
|
|
145
207
|
const n = getOwner();
|
|
146
208
|
let c = false;
|
|
147
209
|
let s;
|
|
@@ -150,18 +212,18 @@ function runProjectionComputedNext(e, t, r, o, i) {
|
|
|
150
212
|
// seed so draft writes cannot tear through to readers (#2988). Every commit
|
|
151
213
|
// point reconciles the shadow through the normal commit path.
|
|
152
214
|
const u = n.Ie ? JSON.parse(JSON.stringify(e[$TARGET][STORE_VALUE])) : null;
|
|
153
|
-
const l =
|
|
154
|
-
storeSetterNext(l,
|
|
155
|
-
s = t(u ??
|
|
215
|
+
const l = wrapDraft(e, () => !c || n.o?.Ee === s, o);
|
|
216
|
+
storeSetterNext(l, o => {
|
|
217
|
+
s = t(u ?? o);
|
|
156
218
|
c = true;
|
|
157
219
|
const commit = t => {
|
|
158
220
|
// Shadow run: commit a detached snapshot, never the shadow itself
|
|
159
221
|
// (adoption takes the value by identity — handing it the live shadow
|
|
160
222
|
// would fuse the draft to the observable store).
|
|
161
223
|
if (u && (t === undefined || t === u)) t = JSON.parse(JSON.stringify(u));
|
|
162
|
-
if (t ===
|
|
224
|
+
if (t === o || t === undefined) return;
|
|
163
225
|
const write = () => storeSetterNext(e, e => reconcileNextState(t, e, r, true), false);
|
|
164
|
-
|
|
226
|
+
i ? i(write) : write();
|
|
165
227
|
};
|
|
166
228
|
const l = handleAsync(n, s, commit);
|
|
167
229
|
if (!n.Ie) commit(l);
|