@solidjs/signals 2.0.0-beta.26 → 2.0.0-beta.27
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 +258 -67
- package/dist/node.cjs +1117 -915
- package/dist/prod/core/action.js +11 -6
- package/dist/prod/core/async.js +42 -11
- package/dist/prod/core/core.js +83 -69
- package/dist/prod/core/external.js +2 -2
- package/dist/prod/core/graph.js +4 -4
- package/dist/prod/core/lanes.js +1 -1
- package/dist/prod/core/optimistic.js +5 -5
- package/dist/prod/core/owner.js +1 -1
- package/dist/prod/core/scheduler.js +53 -32
- package/dist/prod/core/verdict.js +26 -26
- package/dist/prod/map.js +2 -2
- package/dist/prod/store/optimistic.js +52 -33
- package/dist/prod/store/projection.js +38 -33
- package/dist/prod/store/reconcile.js +299 -243
- package/dist/prod/store/store.js +98 -47
- package/dist/types/core/async.d.ts +1 -0
- package/dist/types/core/scheduler.d.ts +1 -0
- package/dist/types/store/optimistic.d.ts +2 -2
- package/dist/types/store/projection.d.ts +7 -2
- package/dist/types/store/reconcile.d.ts +14 -0
- package/dist/types/store/store.d.ts +2 -2
- package/dist/types-cjs/core/async.d.cts +1 -0
- package/dist/types-cjs/core/scheduler.d.cts +1 -0
- package/dist/types-cjs/store/optimistic.d.cts +2 -2
- package/dist/types-cjs/store/projection.d.cts +7 -2
- package/dist/types-cjs/store/reconcile.d.cts +14 -0
- package/dist/types-cjs/store/store.d.cts +2 -2
- package/package.json +1 -1
|
@@ -12,16 +12,16 @@ import "../core/effect.js";
|
|
|
12
12
|
|
|
13
13
|
import { CONFIG_AUTO_DISPOSE } from "../core/constants.js";
|
|
14
14
|
|
|
15
|
-
import {
|
|
15
|
+
import { reconcileState } from "./reconcile.js";
|
|
16
16
|
|
|
17
17
|
import { storeSetter, $TARGET, STORE_WRAP, createStoreProxy, storeTraps, setWriteOverride, STORE_LOOKUP, STORE_SHALLOW, markRawIngest, STORE_VALUE, STORE_FIREWALL } from "./store.js";
|
|
18
18
|
|
|
19
|
-
function createProjectionInternal(e,
|
|
19
|
+
function createProjectionInternal(e, t, r) {
|
|
20
20
|
let o;
|
|
21
21
|
const n = new WeakMap;
|
|
22
22
|
// A shallow projection's children are raw and never wrapped, so the
|
|
23
23
|
// wrapper only ever runs for the root — flagging unconditionally is safe.
|
|
24
|
-
const i = !!
|
|
24
|
+
const i = !!r?.shallow;
|
|
25
25
|
const wrapper = e => {
|
|
26
26
|
e[STORE_WRAP] = wrapProjection;
|
|
27
27
|
e[STORE_LOOKUP] = n;
|
|
@@ -39,14 +39,14 @@ function createProjectionInternal(e, r, t) {
|
|
|
39
39
|
const wrapProjection = e => {
|
|
40
40
|
if (n.has(e)) return n.get(e);
|
|
41
41
|
if (e[$TARGET]?.[STORE_WRAP] === wrapProjection) return e;
|
|
42
|
-
const
|
|
43
|
-
n.set(e,
|
|
44
|
-
return
|
|
42
|
+
const t = createStoreProxy(e, storeTraps, wrapper);
|
|
43
|
+
n.set(e, t);
|
|
44
|
+
return t;
|
|
45
45
|
};
|
|
46
|
-
const c = wrapProjection(
|
|
46
|
+
const c = wrapProjection(t);
|
|
47
47
|
o = computed(() => {
|
|
48
48
|
if (!o) o = getOwner();
|
|
49
|
-
runProjectionComputed(c, e,
|
|
49
|
+
runProjectionComputed(c, e, r?.key === undefined ? "id" : r.key);
|
|
50
50
|
}, undefined);
|
|
51
51
|
o.T &= ~CONFIG_AUTO_DISPOSE;
|
|
52
52
|
return {
|
|
@@ -63,6 +63,10 @@ function createProjectionInternal(e, r, t) {
|
|
|
63
63
|
* items keep their proxy identity — only added/removed items are
|
|
64
64
|
* created/disposed.
|
|
65
65
|
*
|
|
66
|
+
* If the derive returns a different entity than the one currently held (the
|
|
67
|
+
* `/users/1` → `/users/2` shape), the store swaps to it rather than merging,
|
|
68
|
+
* and nothing below it is treated as surviving.
|
|
69
|
+
*
|
|
66
70
|
* Returns the projected store directly (no setter — reads only).
|
|
67
71
|
*
|
|
68
72
|
* Use this when you want the structural-sharing / per-property tracking
|
|
@@ -75,7 +79,8 @@ function createProjectionInternal(e, r, t) {
|
|
|
75
79
|
* @param seed the backing store value to wrap and reconcile into
|
|
76
80
|
* @param options `ProjectionOptions` — `name`, `key`. `key` defaults to
|
|
77
81
|
* `"id"`; specify it only when your data uses a different identity field
|
|
78
|
-
* (e.g. `{ key: "uuid" }` or `{ key: u => u.slug }`)
|
|
82
|
+
* (e.g. `{ key: "uuid" }` or `{ key: u => u.slug }`), or `null` to merge
|
|
83
|
+
* positionally with no keyed pass.
|
|
79
84
|
*
|
|
80
85
|
* @example
|
|
81
86
|
* ```ts
|
|
@@ -97,8 +102,8 @@ function createProjectionInternal(e, r, t) {
|
|
|
97
102
|
* ```
|
|
98
103
|
*
|
|
99
104
|
* @see {@link https://github.com/solidjs/x-reactivity#createprojection}
|
|
100
|
-
*/ function createProjection(e,
|
|
101
|
-
return createProjectionInternal(e,
|
|
105
|
+
*/ function createProjection(e, t, r) {
|
|
106
|
+
return createProjectionInternal(e, t, r).store;
|
|
102
107
|
}
|
|
103
108
|
|
|
104
109
|
/**
|
|
@@ -113,17 +118,17 @@ function createProjectionInternal(e, r, t) {
|
|
|
113
118
|
* re-enters `setProjectionWriteActive` so reconciles target `STORE_OVERRIDE`
|
|
114
119
|
* instead of `STORE_OPTIMISTIC_OVERRIDE` even when an async yield fires outside
|
|
115
120
|
* the outer `setProjectionWriteActive` scope.
|
|
116
|
-
*/ function runProjectionComputed(e,
|
|
121
|
+
*/ function runProjectionComputed(e, t, r, o, n) {
|
|
117
122
|
const i = getOwner();
|
|
118
123
|
let c = false;
|
|
119
124
|
let s;
|
|
120
125
|
const u = new Proxy(e, createWriteTraps(() => !c || i.Te === s, n));
|
|
121
126
|
storeSetter(u, n => {
|
|
122
|
-
s =
|
|
127
|
+
s = t(n);
|
|
123
128
|
c = true;
|
|
124
|
-
const commit =
|
|
125
|
-
if (
|
|
126
|
-
const write = () => storeSetter(e,
|
|
129
|
+
const commit = t => {
|
|
130
|
+
if (t === n || t === undefined) return;
|
|
131
|
+
const write = () => storeSetter(e, e => reconcileState(t, e, r, true));
|
|
127
132
|
o ? o(write) : write();
|
|
128
133
|
};
|
|
129
134
|
commit(handleAsync(i, s, commit));
|
|
@@ -131,53 +136,53 @@ function createProjectionInternal(e, r, t) {
|
|
|
131
136
|
return i;
|
|
132
137
|
}
|
|
133
138
|
|
|
134
|
-
function createWriteTraps(e,
|
|
135
|
-
const
|
|
136
|
-
get(e,
|
|
139
|
+
function createWriteTraps(e, t) {
|
|
140
|
+
const r = {
|
|
141
|
+
get(e, t) {
|
|
137
142
|
let o;
|
|
138
143
|
setWriteOverride(true);
|
|
139
144
|
setProjectionWriteActive(true);
|
|
140
145
|
try {
|
|
141
|
-
o = e[
|
|
146
|
+
o = e[t];
|
|
142
147
|
} finally {
|
|
143
148
|
setWriteOverride(false);
|
|
144
149
|
setProjectionWriteActive(false);
|
|
145
150
|
}
|
|
146
|
-
if (
|
|
147
|
-
return typeof o === "object" && o !== null ? new Proxy(o,
|
|
151
|
+
if (t === $TARGET) return o;
|
|
152
|
+
return typeof o === "object" && o !== null ? new Proxy(o, r) : o;
|
|
148
153
|
},
|
|
149
|
-
has(e,
|
|
150
|
-
let
|
|
154
|
+
has(e, t) {
|
|
155
|
+
let r;
|
|
151
156
|
setWriteOverride(true);
|
|
152
157
|
setProjectionWriteActive(true);
|
|
153
158
|
try {
|
|
154
|
-
|
|
159
|
+
r = t in e;
|
|
155
160
|
} finally {
|
|
156
161
|
setWriteOverride(false);
|
|
157
162
|
setProjectionWriteActive(false);
|
|
158
163
|
}
|
|
159
|
-
return
|
|
164
|
+
return r;
|
|
160
165
|
},
|
|
161
|
-
set(
|
|
166
|
+
set(r, o, n) {
|
|
162
167
|
if (e && !e()) return true;
|
|
163
168
|
setWriteOverride(true);
|
|
164
169
|
setProjectionWriteActive(true);
|
|
165
170
|
try {
|
|
166
|
-
|
|
167
|
-
|
|
171
|
+
r[o] = n;
|
|
172
|
+
t?.();
|
|
168
173
|
} finally {
|
|
169
174
|
setWriteOverride(false);
|
|
170
175
|
setProjectionWriteActive(false);
|
|
171
176
|
}
|
|
172
177
|
return true;
|
|
173
178
|
},
|
|
174
|
-
deleteProperty(
|
|
179
|
+
deleteProperty(r, o) {
|
|
175
180
|
if (e && !e()) return true;
|
|
176
181
|
setWriteOverride(true);
|
|
177
182
|
setProjectionWriteActive(true);
|
|
178
183
|
try {
|
|
179
|
-
delete
|
|
180
|
-
|
|
184
|
+
delete r[o];
|
|
185
|
+
t?.();
|
|
181
186
|
} finally {
|
|
182
187
|
setWriteOverride(false);
|
|
183
188
|
setProjectionWriteActive(false);
|
|
@@ -185,7 +190,7 @@ function createWriteTraps(e, r) {
|
|
|
185
190
|
return true;
|
|
186
191
|
}
|
|
187
192
|
};
|
|
188
|
-
return
|
|
193
|
+
return r;
|
|
189
194
|
}
|
|
190
195
|
|
|
191
196
|
export { createProjection, createProjectionInternal, createWriteTraps, runProjectionComputed };
|