solid-js 1.8.11 → 1.8.13
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 +544 -307
- package/dist/server.js +170 -75
- package/dist/solid.js +471 -265
- package/h/dist/h.js +34 -8
- package/h/jsx-runtime/dist/jsx.js +1 -1
- package/h/jsx-runtime/types/index.d.ts +11 -8
- package/h/types/hyperscript.d.ts +11 -11
- package/html/dist/html.js +216 -94
- package/html/types/lit.d.ts +47 -33
- package/package.json +9 -4
- package/store/dist/dev.cjs +12 -2
- package/store/dist/dev.js +133 -44
- package/store/dist/server.js +19 -8
- package/store/dist/store.cjs +12 -2
- package/store/dist/store.js +124 -41
- package/store/types/index.d.ts +21 -7
- package/store/types/modifiers.d.ts +6 -3
- package/store/types/mutable.d.ts +5 -2
- package/store/types/server.d.ts +12 -4
- package/store/types/store.d.ts +218 -61
- package/types/index.d.ts +75 -10
- package/types/reactive/array.d.ts +12 -4
- package/types/reactive/observable.d.ts +25 -17
- package/types/reactive/scheduler.d.ts +9 -6
- package/types/reactive/signal.d.ts +233 -142
- package/types/render/Suspense.d.ts +5 -5
- package/types/render/component.d.ts +64 -33
- package/types/render/flow.d.ts +43 -31
- package/types/render/hydration.d.ts +13 -13
- package/types/server/index.d.ts +57 -2
- package/types/server/reactive.d.ts +73 -42
- package/types/server/rendering.d.ts +167 -96
- package/universal/dist/dev.js +28 -12
- package/universal/dist/universal.js +28 -12
- package/universal/types/index.d.ts +3 -1
- package/universal/types/universal.d.ts +0 -1
- package/web/dist/dev.cjs +3 -0
- package/web/dist/dev.js +625 -81
- package/web/dist/server.cjs +10 -15
- package/web/dist/server.js +216 -107
- package/web/dist/web.js +614 -80
- package/web/storage/dist/storage.js +10 -0
- package/web/storage/package.json +15 -0
- package/web/storage/types/index.d.ts +2 -0
- package/web/storage/types/index.js +13 -0
- package/web/types/client.d.ts +2 -2
- package/web/types/core.d.ts +10 -1
- package/web/types/index.d.ts +27 -10
- package/web/types/server-mock.d.ts +47 -32
- package/web/dist/storage.js +0 -10
- package/web/types/storage.d.ts +0 -2
- /package/web/{dist → storage/dist}/storage.cjs +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solid-js",
|
|
3
3
|
"description": "A declarative JavaScript library for building user interfaces.",
|
|
4
|
-
"version": "1.8.
|
|
4
|
+
"version": "1.8.13",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://solidjs.com",
|
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
"web/dist",
|
|
28
28
|
"web/types",
|
|
29
29
|
"web/package.json",
|
|
30
|
+
"web/storage/dist",
|
|
31
|
+
"web/storage/types",
|
|
32
|
+
"web/storage/package.json",
|
|
30
33
|
"h/dist",
|
|
31
34
|
"h/types",
|
|
32
35
|
"h/package.json",
|
|
@@ -162,8 +165,9 @@
|
|
|
162
165
|
"require": "./web/dist/web.cjs"
|
|
163
166
|
},
|
|
164
167
|
"./web/storage": {
|
|
165
|
-
"
|
|
166
|
-
"
|
|
168
|
+
"types": "./web/storage/types/index.d.ts",
|
|
169
|
+
"import": "./web/storage/dist/index.js",
|
|
170
|
+
"require": "./web/storage/dist/index.cjs"
|
|
167
171
|
},
|
|
168
172
|
"./web/dist/*": "./web/dist/*",
|
|
169
173
|
"./web/types/*": "./web/types/*",
|
|
@@ -227,7 +231,8 @@
|
|
|
227
231
|
"types:copy": "ncp ../../node_modules/dom-expressions/src/jsx.d.ts ./src/jsx.d.ts && ncp ../../node_modules/dom-expressions/src/jsx-h.d.ts ./h/jsx-runtime/src/jsx.d.ts",
|
|
228
232
|
"types:src": "tsc --project ./tsconfig.build.json && ncp ../../node_modules/dom-expressions/src/jsx.d.ts ./types/jsx.d.ts",
|
|
229
233
|
"types:web": "tsc --project ./web/tsconfig.build.json",
|
|
230
|
-
"types:
|
|
234
|
+
"types:web-storage": "tsc --project ./web/storage/tsconfig.build.json",
|
|
235
|
+
"types:copy-web": "ncp ../../node_modules/dom-expressions/src/client.d.ts ./web/types/client.d.ts && ncp ../../node_modules/dom-expressions/src/server.d.ts ./web/types/server.d.ts",
|
|
231
236
|
"types:store": "tsc --project ./store/tsconfig.build.json",
|
|
232
237
|
"types:html": "tsc --project ./html/tsconfig.json && ncp ../../node_modules/lit-dom-expressions/types/index.d.ts ./html/types/lit.d.ts",
|
|
233
238
|
"types:h": "tsc --project ./h/tsconfig.json && ncp ../../node_modules/hyper-dom-expressions/types/index.d.ts ./h/types/hyperscript.d.ts",
|
package/store/dist/dev.cjs
CHANGED
|
@@ -281,19 +281,29 @@ function wrap(value) {
|
|
|
281
281
|
});
|
|
282
282
|
const keys = Object.keys(value),
|
|
283
283
|
desc = Object.getOwnPropertyDescriptors(value);
|
|
284
|
+
const proto = Object.getPrototypeOf(value);
|
|
285
|
+
const isClass = value !== null && typeof value === "object" && !Array.isArray(value) && proto !== Object.prototype;
|
|
286
|
+
if (isClass) {
|
|
287
|
+
const descriptors = Object.getOwnPropertyDescriptors(proto);
|
|
288
|
+
keys.push(...Object.keys(descriptors));
|
|
289
|
+
Object.assign(desc, descriptors);
|
|
290
|
+
}
|
|
284
291
|
for (let i = 0, l = keys.length; i < l; i++) {
|
|
285
292
|
const prop = keys[i];
|
|
293
|
+
if (isClass && prop === "constructor") continue;
|
|
286
294
|
if (desc[prop].get) {
|
|
287
295
|
const get = desc[prop].get.bind(p);
|
|
288
296
|
Object.defineProperty(value, prop, {
|
|
289
|
-
get
|
|
297
|
+
get,
|
|
298
|
+
configurable: true
|
|
290
299
|
});
|
|
291
300
|
}
|
|
292
301
|
if (desc[prop].set) {
|
|
293
302
|
const og = desc[prop].set,
|
|
294
303
|
set = v => solidJs.batch(() => og.call(p, v));
|
|
295
304
|
Object.defineProperty(value, prop, {
|
|
296
|
-
set
|
|
305
|
+
set,
|
|
306
|
+
configurable: true
|
|
297
307
|
});
|
|
298
308
|
}
|
|
299
309
|
}
|
package/store/dist/dev.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DEV as DEV$1, $PROXY, $TRACK, getListener, batch, createSignal } from
|
|
1
|
+
import { DEV as DEV$1, $PROXY, $TRACK, getListener, batch, createSignal } from "solid-js";
|
|
2
2
|
|
|
3
3
|
const $RAW = Symbol("store-raw"),
|
|
4
4
|
$NODE = Symbol("store-node"),
|
|
@@ -11,7 +11,7 @@ function wrap$1(value) {
|
|
|
11
11
|
let p = value[$PROXY];
|
|
12
12
|
if (!p) {
|
|
13
13
|
Object.defineProperty(value, $PROXY, {
|
|
14
|
-
value: p = new Proxy(value, proxyTraps$1)
|
|
14
|
+
value: (p = new Proxy(value, proxyTraps$1))
|
|
15
15
|
});
|
|
16
16
|
if (!Array.isArray(value)) {
|
|
17
17
|
const keys = Object.keys(value),
|
|
@@ -31,20 +31,29 @@ function wrap$1(value) {
|
|
|
31
31
|
}
|
|
32
32
|
function isWrappable(obj) {
|
|
33
33
|
let proto;
|
|
34
|
-
return
|
|
34
|
+
return (
|
|
35
|
+
obj != null &&
|
|
36
|
+
typeof obj === "object" &&
|
|
37
|
+
(obj[$PROXY] ||
|
|
38
|
+
!(proto = Object.getPrototypeOf(obj)) ||
|
|
39
|
+
proto === Object.prototype ||
|
|
40
|
+
Array.isArray(obj))
|
|
41
|
+
);
|
|
35
42
|
}
|
|
36
43
|
function unwrap(item, set = new Set()) {
|
|
37
44
|
let result, unwrapped, v, prop;
|
|
38
|
-
if (result = item != null && item[$RAW]) return result;
|
|
45
|
+
if ((result = item != null && item[$RAW])) return result;
|
|
39
46
|
if (!isWrappable(item) || set.has(item)) return item;
|
|
40
47
|
if (Array.isArray(item)) {
|
|
41
|
-
if (Object.isFrozen(item)) item = item.slice(0);
|
|
48
|
+
if (Object.isFrozen(item)) item = item.slice(0);
|
|
49
|
+
else set.add(item);
|
|
42
50
|
for (let i = 0, l = item.length; i < l; i++) {
|
|
43
51
|
v = item[i];
|
|
44
52
|
if ((unwrapped = unwrap(v, set)) !== v) item[i] = unwrapped;
|
|
45
53
|
}
|
|
46
54
|
} else {
|
|
47
|
-
if (Object.isFrozen(item)) item = Object.assign({}, item);
|
|
55
|
+
if (Object.isFrozen(item)) item = Object.assign({}, item);
|
|
56
|
+
else set.add(item);
|
|
48
57
|
const keys = Object.keys(item),
|
|
49
58
|
desc = Object.getOwnPropertyDescriptors(item);
|
|
50
59
|
for (let i = 0, l = keys.length; i < l; i++) {
|
|
@@ -58,9 +67,10 @@ function unwrap(item, set = new Set()) {
|
|
|
58
67
|
}
|
|
59
68
|
function getNodes(target, symbol) {
|
|
60
69
|
let nodes = target[symbol];
|
|
61
|
-
if (!nodes)
|
|
62
|
-
|
|
63
|
-
|
|
70
|
+
if (!nodes)
|
|
71
|
+
Object.defineProperty(target, symbol, {
|
|
72
|
+
value: (nodes = Object.create(null))
|
|
73
|
+
});
|
|
64
74
|
return nodes;
|
|
65
75
|
}
|
|
66
76
|
function getNode(nodes, property, value) {
|
|
@@ -70,11 +80,12 @@ function getNode(nodes, property, value) {
|
|
|
70
80
|
internal: true
|
|
71
81
|
});
|
|
72
82
|
s.$ = set;
|
|
73
|
-
return nodes[property] = s;
|
|
83
|
+
return (nodes[property] = s);
|
|
74
84
|
}
|
|
75
85
|
function proxyDescriptor$1(target, property) {
|
|
76
86
|
const desc = Reflect.getOwnPropertyDescriptor(target, property);
|
|
77
|
-
if (!desc || desc.get || !desc.configurable || property === $PROXY || property === $NODE)
|
|
87
|
+
if (!desc || desc.get || !desc.configurable || property === $PROXY || property === $NODE)
|
|
88
|
+
return desc;
|
|
78
89
|
delete desc.value;
|
|
79
90
|
delete desc.writable;
|
|
80
91
|
desc.get = () => target[$PROXY][property];
|
|
@@ -101,12 +112,25 @@ const proxyTraps$1 = {
|
|
|
101
112
|
if (property === $NODE || property === $HAS || property === "__proto__") return value;
|
|
102
113
|
if (!tracked) {
|
|
103
114
|
const desc = Object.getOwnPropertyDescriptor(target, property);
|
|
104
|
-
if (
|
|
115
|
+
if (
|
|
116
|
+
getListener() &&
|
|
117
|
+
(typeof value !== "function" || target.hasOwnProperty(property)) &&
|
|
118
|
+
!(desc && desc.get)
|
|
119
|
+
)
|
|
120
|
+
value = getNode(nodes, property, value)();
|
|
105
121
|
}
|
|
106
122
|
return isWrappable(value) ? wrap$1(value) : value;
|
|
107
123
|
},
|
|
108
124
|
has(target, property) {
|
|
109
|
-
if (
|
|
125
|
+
if (
|
|
126
|
+
property === $RAW ||
|
|
127
|
+
property === $PROXY ||
|
|
128
|
+
property === $TRACK ||
|
|
129
|
+
property === $NODE ||
|
|
130
|
+
property === $HAS ||
|
|
131
|
+
property === "__proto__"
|
|
132
|
+
)
|
|
133
|
+
return true;
|
|
110
134
|
getListener() && getNode(getNodes(target, $HAS), property)();
|
|
111
135
|
return property in target;
|
|
112
136
|
},
|
|
@@ -135,7 +159,7 @@ function setProperty(state, property, value, deleting = false) {
|
|
|
135
159
|
}
|
|
136
160
|
let nodes = getNodes(state, $NODE),
|
|
137
161
|
node;
|
|
138
|
-
if (node = getNode(nodes, property, prev)) node.$(() => value);
|
|
162
|
+
if ((node = getNode(nodes, property, prev))) node.$(() => value);
|
|
139
163
|
if (Array.isArray(state) && state.length !== len) {
|
|
140
164
|
for (let i = state.length; i < len; i++) (node = nodes[i]) && node.$();
|
|
141
165
|
(node = getNode(nodes, "length", len)) && node.$(state.length);
|
|
@@ -181,11 +205,7 @@ function updatePath(current, path, traversed = []) {
|
|
|
181
205
|
}
|
|
182
206
|
return;
|
|
183
207
|
} else if (isArray && partType === "object") {
|
|
184
|
-
const {
|
|
185
|
-
from = 0,
|
|
186
|
-
to = current.length - 1,
|
|
187
|
-
by = 1
|
|
188
|
-
} = part;
|
|
208
|
+
const { from = 0, to = current.length - 1, by = 1 } = part;
|
|
189
209
|
for (let i = from; i <= to; i += by) {
|
|
190
210
|
updatePath(current, [i].concat(path), traversed);
|
|
191
211
|
}
|
|
@@ -204,14 +224,17 @@ function updatePath(current, path, traversed = []) {
|
|
|
204
224
|
}
|
|
205
225
|
if (part === undefined && value == undefined) return;
|
|
206
226
|
value = unwrap(value);
|
|
207
|
-
if (part === undefined || isWrappable(prev) && isWrappable(value) && !Array.isArray(value)) {
|
|
227
|
+
if (part === undefined || (isWrappable(prev) && isWrappable(value) && !Array.isArray(value))) {
|
|
208
228
|
mergeStoreNode(prev, value);
|
|
209
229
|
} else setProperty(current, part, value);
|
|
210
230
|
}
|
|
211
231
|
function createStore(...[store, options]) {
|
|
212
232
|
const unwrappedStore = unwrap(store || {});
|
|
213
233
|
const isArray = Array.isArray(unwrappedStore);
|
|
214
|
-
if (typeof unwrappedStore !== "object" && typeof unwrappedStore !== "function")
|
|
234
|
+
if (typeof unwrappedStore !== "object" && typeof unwrappedStore !== "function")
|
|
235
|
+
throw new Error(
|
|
236
|
+
`Unexpected type ${typeof unwrappedStore} received when initializing 'createStore'. Expected an object.`
|
|
237
|
+
);
|
|
215
238
|
const wrappedStore = wrap$1(unwrappedStore);
|
|
216
239
|
DEV$1.registerGraph({
|
|
217
240
|
value: unwrappedStore,
|
|
@@ -219,7 +242,9 @@ function createStore(...[store, options]) {
|
|
|
219
242
|
});
|
|
220
243
|
function setStore(...args) {
|
|
221
244
|
batch(() => {
|
|
222
|
-
isArray && args.length === 1
|
|
245
|
+
isArray && args.length === 1
|
|
246
|
+
? updateArray(unwrappedStore, args[0])
|
|
247
|
+
: updatePath(unwrappedStore, args);
|
|
223
248
|
});
|
|
224
249
|
}
|
|
225
250
|
return [wrappedStore, setStore];
|
|
@@ -227,11 +252,19 @@ function createStore(...[store, options]) {
|
|
|
227
252
|
|
|
228
253
|
function proxyDescriptor(target, property) {
|
|
229
254
|
const desc = Reflect.getOwnPropertyDescriptor(target, property);
|
|
230
|
-
if (
|
|
255
|
+
if (
|
|
256
|
+
!desc ||
|
|
257
|
+
desc.get ||
|
|
258
|
+
desc.set ||
|
|
259
|
+
!desc.configurable ||
|
|
260
|
+
property === $PROXY ||
|
|
261
|
+
property === $NODE
|
|
262
|
+
)
|
|
263
|
+
return desc;
|
|
231
264
|
delete desc.value;
|
|
232
265
|
delete desc.writable;
|
|
233
266
|
desc.get = () => target[$PROXY][property];
|
|
234
|
-
desc.set = v => target[$PROXY][property] = v;
|
|
267
|
+
desc.set = v => (target[$PROXY][property] = v);
|
|
235
268
|
return desc;
|
|
236
269
|
}
|
|
237
270
|
const proxyTraps = {
|
|
@@ -249,14 +282,24 @@ const proxyTraps = {
|
|
|
249
282
|
if (!tracked) {
|
|
250
283
|
const desc = Object.getOwnPropertyDescriptor(target, property);
|
|
251
284
|
const isFunction = typeof value === "function";
|
|
252
|
-
if (getListener() && (!isFunction || target.hasOwnProperty(property)) && !(desc && desc.get))
|
|
285
|
+
if (getListener() && (!isFunction || target.hasOwnProperty(property)) && !(desc && desc.get))
|
|
286
|
+
value = getNode(nodes, property, value)();
|
|
287
|
+
else if (value != null && isFunction && value === Array.prototype[property]) {
|
|
253
288
|
return (...args) => batch(() => Array.prototype[property].apply(receiver, args));
|
|
254
289
|
}
|
|
255
290
|
}
|
|
256
291
|
return isWrappable(value) ? wrap(value) : value;
|
|
257
292
|
},
|
|
258
293
|
has(target, property) {
|
|
259
|
-
if (
|
|
294
|
+
if (
|
|
295
|
+
property === $RAW ||
|
|
296
|
+
property === $PROXY ||
|
|
297
|
+
property === $TRACK ||
|
|
298
|
+
property === $NODE ||
|
|
299
|
+
property === $HAS ||
|
|
300
|
+
property === "__proto__"
|
|
301
|
+
)
|
|
302
|
+
return true;
|
|
260
303
|
getListener() && getNode(getNodes(target, $HAS), property)();
|
|
261
304
|
return property in target;
|
|
262
305
|
},
|
|
@@ -275,23 +318,37 @@ function wrap(value) {
|
|
|
275
318
|
let p = value[$PROXY];
|
|
276
319
|
if (!p) {
|
|
277
320
|
Object.defineProperty(value, $PROXY, {
|
|
278
|
-
value: p = new Proxy(value, proxyTraps)
|
|
321
|
+
value: (p = new Proxy(value, proxyTraps))
|
|
279
322
|
});
|
|
280
323
|
const keys = Object.keys(value),
|
|
281
324
|
desc = Object.getOwnPropertyDescriptors(value);
|
|
325
|
+
const proto = Object.getPrototypeOf(value);
|
|
326
|
+
const isClass =
|
|
327
|
+
value !== null &&
|
|
328
|
+
typeof value === "object" &&
|
|
329
|
+
!Array.isArray(value) &&
|
|
330
|
+
proto !== Object.prototype;
|
|
331
|
+
if (isClass) {
|
|
332
|
+
const descriptors = Object.getOwnPropertyDescriptors(proto);
|
|
333
|
+
keys.push(...Object.keys(descriptors));
|
|
334
|
+
Object.assign(desc, descriptors);
|
|
335
|
+
}
|
|
282
336
|
for (let i = 0, l = keys.length; i < l; i++) {
|
|
283
337
|
const prop = keys[i];
|
|
338
|
+
if (isClass && prop === "constructor") continue;
|
|
284
339
|
if (desc[prop].get) {
|
|
285
340
|
const get = desc[prop].get.bind(p);
|
|
286
341
|
Object.defineProperty(value, prop, {
|
|
287
|
-
get
|
|
342
|
+
get,
|
|
343
|
+
configurable: true
|
|
288
344
|
});
|
|
289
345
|
}
|
|
290
346
|
if (desc[prop].set) {
|
|
291
347
|
const og = desc[prop].set,
|
|
292
348
|
set = v => batch(() => og.call(p, v));
|
|
293
349
|
Object.defineProperty(value, prop, {
|
|
294
|
-
set
|
|
350
|
+
set,
|
|
351
|
+
configurable: true
|
|
295
352
|
});
|
|
296
353
|
}
|
|
297
354
|
}
|
|
@@ -300,7 +357,10 @@ function wrap(value) {
|
|
|
300
357
|
}
|
|
301
358
|
function createMutable(state, options) {
|
|
302
359
|
const unwrappedStore = unwrap(state || {});
|
|
303
|
-
if (typeof unwrappedStore !== "object" && typeof unwrappedStore !== "function")
|
|
360
|
+
if (typeof unwrappedStore !== "object" && typeof unwrappedStore !== "function")
|
|
361
|
+
throw new Error(
|
|
362
|
+
`Unexpected type ${typeof unwrappedStore} received when initializing 'createMutable'. Expected an object.`
|
|
363
|
+
);
|
|
304
364
|
const wrappedStore = wrap(unwrappedStore);
|
|
305
365
|
DEV$1.registerGraph({
|
|
306
366
|
value: unwrappedStore,
|
|
@@ -317,19 +377,42 @@ function applyState(target, parent, property, merge, key) {
|
|
|
317
377
|
const previous = parent[property];
|
|
318
378
|
if (target === previous) return;
|
|
319
379
|
const isArray = Array.isArray(target);
|
|
320
|
-
if (
|
|
380
|
+
if (
|
|
381
|
+
property !== $ROOT &&
|
|
382
|
+
(!isWrappable(target) ||
|
|
383
|
+
!isWrappable(previous) ||
|
|
384
|
+
isArray !== Array.isArray(previous) ||
|
|
385
|
+
(key && target[key] !== previous[key]))
|
|
386
|
+
) {
|
|
321
387
|
setProperty(parent, property, target);
|
|
322
388
|
return;
|
|
323
389
|
}
|
|
324
390
|
if (isArray) {
|
|
325
|
-
if (
|
|
391
|
+
if (
|
|
392
|
+
target.length &&
|
|
393
|
+
previous.length &&
|
|
394
|
+
(!merge || (key && target[0] && target[0][key] != null))
|
|
395
|
+
) {
|
|
326
396
|
let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
|
|
327
|
-
for (
|
|
397
|
+
for (
|
|
398
|
+
start = 0, end = Math.min(previous.length, target.length);
|
|
399
|
+
start < end &&
|
|
400
|
+
(previous[start] === target[start] ||
|
|
401
|
+
(key && previous[start] && target[start] && previous[start][key] === target[start][key]));
|
|
402
|
+
start++
|
|
403
|
+
) {
|
|
328
404
|
applyState(target[start], previous, start, merge, key);
|
|
329
405
|
}
|
|
330
406
|
const temp = new Array(target.length),
|
|
331
407
|
newIndices = new Map();
|
|
332
|
-
for (
|
|
408
|
+
for (
|
|
409
|
+
end = previous.length - 1, newEnd = target.length - 1;
|
|
410
|
+
end >= start &&
|
|
411
|
+
newEnd >= start &&
|
|
412
|
+
(previous[end] === target[newEnd] ||
|
|
413
|
+
(key && previous[start] && target[start] && previous[end][key] === target[newEnd][key]));
|
|
414
|
+
end--, newEnd--
|
|
415
|
+
) {
|
|
333
416
|
temp[newEnd] = previous[end];
|
|
334
417
|
}
|
|
335
418
|
if (start > newEnd || start > end) {
|
|
@@ -383,16 +466,19 @@ function applyState(target, parent, property, merge, key) {
|
|
|
383
466
|
}
|
|
384
467
|
}
|
|
385
468
|
function reconcile(value, options = {}) {
|
|
386
|
-
const {
|
|
387
|
-
merge,
|
|
388
|
-
key = "id"
|
|
389
|
-
} = options,
|
|
469
|
+
const { merge, key = "id" } = options,
|
|
390
470
|
v = unwrap(value);
|
|
391
471
|
return state => {
|
|
392
472
|
if (!isWrappable(state) || !isWrappable(v)) return v;
|
|
393
|
-
const res = applyState(
|
|
394
|
-
|
|
395
|
-
|
|
473
|
+
const res = applyState(
|
|
474
|
+
v,
|
|
475
|
+
{
|
|
476
|
+
[$ROOT]: state
|
|
477
|
+
},
|
|
478
|
+
$ROOT,
|
|
479
|
+
merge,
|
|
480
|
+
key
|
|
481
|
+
);
|
|
396
482
|
return res === undefined ? state : res;
|
|
397
483
|
};
|
|
398
484
|
}
|
|
@@ -402,7 +488,10 @@ const setterTraps = {
|
|
|
402
488
|
if (property === $RAW) return target;
|
|
403
489
|
const value = target[property];
|
|
404
490
|
let proxy;
|
|
405
|
-
return isWrappable(value)
|
|
491
|
+
return isWrappable(value)
|
|
492
|
+
? producers.get(value) ||
|
|
493
|
+
(producers.set(value, (proxy = new Proxy(value, setterTraps))), proxy)
|
|
494
|
+
: value;
|
|
406
495
|
},
|
|
407
496
|
set(target, property, value) {
|
|
408
497
|
setProperty(target, property, unwrap(value));
|
|
@@ -418,7 +507,7 @@ function produce(fn) {
|
|
|
418
507
|
if (isWrappable(state)) {
|
|
419
508
|
let proxy;
|
|
420
509
|
if (!(proxy = producers.get(state))) {
|
|
421
|
-
producers.set(state, proxy = new Proxy(state, setterTraps));
|
|
510
|
+
producers.set(state, (proxy = new Proxy(state, setterTraps)));
|
|
422
511
|
}
|
|
423
512
|
fn(proxy);
|
|
424
513
|
}
|
|
@@ -430,6 +519,6 @@ const DEV = {
|
|
|
430
519
|
$NODE,
|
|
431
520
|
isWrappable,
|
|
432
521
|
hooks: DevHooks
|
|
433
|
-
}
|
|
522
|
+
};
|
|
434
523
|
|
|
435
524
|
export { $RAW, DEV, createMutable, createStore, modifyMutable, produce, reconcile, unwrap };
|
package/store/dist/server.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
const $RAW = Symbol("state-raw");
|
|
2
2
|
function isWrappable(obj) {
|
|
3
|
-
return
|
|
3
|
+
return (
|
|
4
|
+
obj != null &&
|
|
5
|
+
typeof obj === "object" &&
|
|
6
|
+
(Object.getPrototypeOf(obj) === Object.prototype || Array.isArray(obj))
|
|
7
|
+
);
|
|
4
8
|
}
|
|
5
9
|
function unwrap(item) {
|
|
6
10
|
return item;
|
|
@@ -49,11 +53,7 @@ function updatePath(current, path, traversed = []) {
|
|
|
49
53
|
}
|
|
50
54
|
return;
|
|
51
55
|
} else if (isArray && partType === "object") {
|
|
52
|
-
const {
|
|
53
|
-
from = 0,
|
|
54
|
-
to = current.length - 1,
|
|
55
|
-
by = 1
|
|
56
|
-
} = part;
|
|
56
|
+
const { from = 0, to = current.length - 1, by = 1 } = part;
|
|
57
57
|
for (let i = from; i <= to; i += by) {
|
|
58
58
|
updatePath(current, [i].concat(path), traversed);
|
|
59
59
|
}
|
|
@@ -71,7 +71,7 @@ function updatePath(current, path, traversed = []) {
|
|
|
71
71
|
if (value === next) return;
|
|
72
72
|
}
|
|
73
73
|
if (part === undefined && value == undefined) return;
|
|
74
|
-
if (part === undefined || isWrappable(next) && isWrappable(value) && !Array.isArray(value)) {
|
|
74
|
+
if (part === undefined || (isWrappable(next) && isWrappable(value) && !Array.isArray(value))) {
|
|
75
75
|
mergeStoreNode(next, value);
|
|
76
76
|
} else setProperty(current, part, value);
|
|
77
77
|
}
|
|
@@ -108,4 +108,15 @@ function produce(fn) {
|
|
|
108
108
|
}
|
|
109
109
|
const DEV = undefined;
|
|
110
110
|
|
|
111
|
-
export {
|
|
111
|
+
export {
|
|
112
|
+
$RAW,
|
|
113
|
+
DEV,
|
|
114
|
+
createMutable,
|
|
115
|
+
createStore,
|
|
116
|
+
isWrappable,
|
|
117
|
+
produce,
|
|
118
|
+
reconcile,
|
|
119
|
+
setProperty,
|
|
120
|
+
unwrap,
|
|
121
|
+
updatePath
|
|
122
|
+
};
|
package/store/dist/store.cjs
CHANGED
|
@@ -270,19 +270,29 @@ function wrap(value) {
|
|
|
270
270
|
});
|
|
271
271
|
const keys = Object.keys(value),
|
|
272
272
|
desc = Object.getOwnPropertyDescriptors(value);
|
|
273
|
+
const proto = Object.getPrototypeOf(value);
|
|
274
|
+
const isClass = value !== null && typeof value === "object" && !Array.isArray(value) && proto !== Object.prototype;
|
|
275
|
+
if (isClass) {
|
|
276
|
+
const descriptors = Object.getOwnPropertyDescriptors(proto);
|
|
277
|
+
keys.push(...Object.keys(descriptors));
|
|
278
|
+
Object.assign(desc, descriptors);
|
|
279
|
+
}
|
|
273
280
|
for (let i = 0, l = keys.length; i < l; i++) {
|
|
274
281
|
const prop = keys[i];
|
|
282
|
+
if (isClass && prop === "constructor") continue;
|
|
275
283
|
if (desc[prop].get) {
|
|
276
284
|
const get = desc[prop].get.bind(p);
|
|
277
285
|
Object.defineProperty(value, prop, {
|
|
278
|
-
get
|
|
286
|
+
get,
|
|
287
|
+
configurable: true
|
|
279
288
|
});
|
|
280
289
|
}
|
|
281
290
|
if (desc[prop].set) {
|
|
282
291
|
const og = desc[prop].set,
|
|
283
292
|
set = v => solidJs.batch(() => og.call(p, v));
|
|
284
293
|
Object.defineProperty(value, prop, {
|
|
285
|
-
set
|
|
294
|
+
set,
|
|
295
|
+
configurable: true
|
|
286
296
|
});
|
|
287
297
|
}
|
|
288
298
|
}
|