solid-js 1.8.22 → 1.9.0
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.cjs +7 -6
- package/dist/dev.js +567 -325
- package/dist/server.cjs +1 -1
- package/dist/server.js +169 -75
- package/dist/solid.cjs +7 -6
- package/dist/solid.js +494 -283
- package/h/dist/h.js +40 -9
- package/h/jsx-runtime/dist/jsx.js +1 -1
- package/h/jsx-runtime/types/index.d.ts +13 -10
- package/h/jsx-runtime/types/jsx.d.ts +22 -1
- package/h/types/hyperscript.d.ts +11 -11
- package/h/types/index.d.ts +1 -1
- package/html/dist/html.cjs +4 -2
- package/html/dist/html.js +222 -95
- package/html/types/index.d.ts +1 -1
- package/html/types/lit.d.ts +52 -33
- package/package.json +1 -5
- package/store/dist/dev.cjs +1 -1
- package/store/dist/dev.js +123 -43
- package/store/dist/server.cjs +4 -0
- package/store/dist/server.js +23 -8
- package/store/dist/store.cjs +1 -1
- package/store/dist/store.js +114 -40
- package/store/package.json +0 -4
- 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 +26 -5
- package/store/types/store.d.ts +219 -62
- package/types/index.d.ts +75 -10
- package/types/jsx.d.ts +35 -8
- 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 +236 -143
- 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 +15 -15
- package/types/server/index.d.ts +57 -2
- package/types/server/reactive.d.ts +73 -42
- package/types/server/rendering.d.ts +169 -98
- 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 +57 -24
- package/web/dist/dev.js +679 -101
- package/web/dist/server.cjs +96 -15
- package/web/dist/server.js +676 -105
- package/web/dist/web.cjs +53 -23
- package/web/dist/web.js +664 -99
- package/web/package.json +0 -4
- package/web/storage/dist/storage.js +3 -3
- package/web/types/client.d.ts +5 -3
- 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/types/server.d.ts +88 -0
package/html/types/lit.d.ts
CHANGED
|
@@ -1,41 +1,60 @@
|
|
|
1
1
|
type MountableElement = Element | Document | ShadowRoot | DocumentFragment | Node;
|
|
2
2
|
interface Runtime {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
3
|
+
effect<T>(fn: (prev?: T) => T, init?: T): any;
|
|
4
|
+
untrack<T>(fn: () => T): T;
|
|
5
|
+
insert(parent: MountableElement, accessor: any, marker?: Node | null, init?: any): any;
|
|
6
|
+
spread<T>(node: Element, accessor: (() => T) | T, isSVG?: Boolean, skipChildren?: Boolean): void;
|
|
7
|
+
createComponent(Comp: (props: any) => any, props: any): any;
|
|
8
|
+
addEventListener(
|
|
9
|
+
node: Element,
|
|
10
|
+
name: string,
|
|
11
|
+
handler: EventListener | EventListenerObject | (EventListenerObject & AddEventListenerOptions),
|
|
12
|
+
delegate: boolean
|
|
13
|
+
): void;
|
|
14
|
+
delegateEvents(eventNames: string[]): void;
|
|
15
|
+
classList(
|
|
16
|
+
node: Element,
|
|
17
|
+
value: {
|
|
18
|
+
[k: string]: boolean;
|
|
19
|
+
},
|
|
20
|
+
prev?: {
|
|
21
|
+
[k: string]: boolean;
|
|
22
|
+
}
|
|
23
|
+
): {
|
|
24
|
+
[k: string]: boolean;
|
|
25
|
+
};
|
|
26
|
+
style(
|
|
27
|
+
node: Element,
|
|
28
|
+
value: {
|
|
29
|
+
[k: string]: string;
|
|
30
|
+
},
|
|
31
|
+
prev?: {
|
|
32
|
+
[k: string]: string;
|
|
33
|
+
}
|
|
34
|
+
): void;
|
|
35
|
+
mergeProps(...sources: unknown[]): unknown;
|
|
36
|
+
dynamicProperty(props: any, key: string): any;
|
|
37
|
+
setAttribute(node: Element, name: string, value: any): void;
|
|
38
|
+
setAttributeNS(node: Element, namespace: string, name: string, value: any): void;
|
|
39
|
+
Aliases: Record<string, string>;
|
|
40
|
+
getPropAlias(prop: string, tagName: string): string | undefined;
|
|
41
|
+
Properties: Set<string>;
|
|
42
|
+
ChildProperties: Set<string>;
|
|
43
|
+
DelegatedEvents: Set<string>;
|
|
44
|
+
SVGElements: Set<string>;
|
|
45
|
+
SVGNamespace: Record<string, string>;
|
|
33
46
|
}
|
|
34
47
|
export type HTMLTag = {
|
|
35
|
-
|
|
48
|
+
(statics: TemplateStringsArray, ...args: unknown[]): Node | Node[];
|
|
36
49
|
};
|
|
37
|
-
export declare function createHTML(
|
|
50
|
+
export declare function createHTML(
|
|
51
|
+
r: Runtime,
|
|
52
|
+
{
|
|
53
|
+
delegateEvents,
|
|
54
|
+
functionBuilder
|
|
55
|
+
}?: {
|
|
38
56
|
delegateEvents?: boolean;
|
|
39
57
|
functionBuilder?: (...args: string[]) => Function;
|
|
40
|
-
}
|
|
58
|
+
}
|
|
59
|
+
): HTMLTag;
|
|
41
60
|
export {};
|
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.
|
|
4
|
+
"version": "1.9.0",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://solidjs.com",
|
|
@@ -11,10 +11,6 @@
|
|
|
11
11
|
},
|
|
12
12
|
"main": "./dist/server.cjs",
|
|
13
13
|
"module": "./dist/server.js",
|
|
14
|
-
"browser": {
|
|
15
|
-
"./dist/server.cjs": "./dist/solid.cjs",
|
|
16
|
-
"./dist/server.js": "./dist/solid.js"
|
|
17
|
-
},
|
|
18
14
|
"unpkg": "./dist/solid.cjs",
|
|
19
15
|
"types": "types/index.d.ts",
|
|
20
16
|
"sideEffects": false,
|
package/store/dist/dev.cjs
CHANGED
|
@@ -282,7 +282,7 @@ function wrap(value) {
|
|
|
282
282
|
const keys = Object.keys(value),
|
|
283
283
|
desc = Object.getOwnPropertyDescriptors(value);
|
|
284
284
|
const proto = Object.getPrototypeOf(value);
|
|
285
|
-
const isClass = value !== null && typeof value === "object" && !Array.isArray(value) && proto !== Object.prototype;
|
|
285
|
+
const isClass = proto !== null && value !== null && typeof value === "object" && !Array.isArray(value) && proto !== Object.prototype;
|
|
286
286
|
if (isClass) {
|
|
287
287
|
const descriptors = Object.getOwnPropertyDescriptors(proto);
|
|
288
288
|
keys.push(...Object.keys(descriptors));
|
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,12 +318,17 @@ 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);
|
|
282
325
|
const proto = Object.getPrototypeOf(value);
|
|
283
|
-
const isClass =
|
|
326
|
+
const isClass =
|
|
327
|
+
proto !== null &&
|
|
328
|
+
value !== null &&
|
|
329
|
+
typeof value === "object" &&
|
|
330
|
+
!Array.isArray(value) &&
|
|
331
|
+
proto !== Object.prototype;
|
|
284
332
|
if (isClass) {
|
|
285
333
|
const descriptors = Object.getOwnPropertyDescriptors(proto);
|
|
286
334
|
keys.push(...Object.keys(descriptors));
|
|
@@ -310,7 +358,10 @@ function wrap(value) {
|
|
|
310
358
|
}
|
|
311
359
|
function createMutable(state, options) {
|
|
312
360
|
const unwrappedStore = unwrap(state || {});
|
|
313
|
-
if (typeof unwrappedStore !== "object" && typeof unwrappedStore !== "function")
|
|
361
|
+
if (typeof unwrappedStore !== "object" && typeof unwrappedStore !== "function")
|
|
362
|
+
throw new Error(
|
|
363
|
+
`Unexpected type ${typeof unwrappedStore} received when initializing 'createMutable'. Expected an object.`
|
|
364
|
+
);
|
|
314
365
|
const wrappedStore = wrap(unwrappedStore);
|
|
315
366
|
DEV$1.registerGraph({
|
|
316
367
|
value: unwrappedStore,
|
|
@@ -327,19 +378,42 @@ function applyState(target, parent, property, merge, key) {
|
|
|
327
378
|
const previous = parent[property];
|
|
328
379
|
if (target === previous) return;
|
|
329
380
|
const isArray = Array.isArray(target);
|
|
330
|
-
if (
|
|
381
|
+
if (
|
|
382
|
+
property !== $ROOT &&
|
|
383
|
+
(!isWrappable(target) ||
|
|
384
|
+
!isWrappable(previous) ||
|
|
385
|
+
isArray !== Array.isArray(previous) ||
|
|
386
|
+
(key && target[key] !== previous[key]))
|
|
387
|
+
) {
|
|
331
388
|
setProperty(parent, property, target);
|
|
332
389
|
return;
|
|
333
390
|
}
|
|
334
391
|
if (isArray) {
|
|
335
|
-
if (
|
|
392
|
+
if (
|
|
393
|
+
target.length &&
|
|
394
|
+
previous.length &&
|
|
395
|
+
(!merge || (key && target[0] && target[0][key] != null))
|
|
396
|
+
) {
|
|
336
397
|
let i, j, start, end, newEnd, item, newIndicesNext, keyVal;
|
|
337
|
-
for (
|
|
398
|
+
for (
|
|
399
|
+
start = 0, end = Math.min(previous.length, target.length);
|
|
400
|
+
start < end &&
|
|
401
|
+
(previous[start] === target[start] ||
|
|
402
|
+
(key && previous[start] && target[start] && previous[start][key] === target[start][key]));
|
|
403
|
+
start++
|
|
404
|
+
) {
|
|
338
405
|
applyState(target[start], previous, start, merge, key);
|
|
339
406
|
}
|
|
340
407
|
const temp = new Array(target.length),
|
|
341
408
|
newIndices = new Map();
|
|
342
|
-
for (
|
|
409
|
+
for (
|
|
410
|
+
end = previous.length - 1, newEnd = target.length - 1;
|
|
411
|
+
end >= start &&
|
|
412
|
+
newEnd >= start &&
|
|
413
|
+
(previous[end] === target[newEnd] ||
|
|
414
|
+
(key && previous[start] && target[start] && previous[end][key] === target[newEnd][key]));
|
|
415
|
+
end--, newEnd--
|
|
416
|
+
) {
|
|
343
417
|
temp[newEnd] = previous[end];
|
|
344
418
|
}
|
|
345
419
|
if (start > newEnd || start > end) {
|
|
@@ -393,16 +467,19 @@ function applyState(target, parent, property, merge, key) {
|
|
|
393
467
|
}
|
|
394
468
|
}
|
|
395
469
|
function reconcile(value, options = {}) {
|
|
396
|
-
const {
|
|
397
|
-
merge,
|
|
398
|
-
key = "id"
|
|
399
|
-
} = options,
|
|
470
|
+
const { merge, key = "id" } = options,
|
|
400
471
|
v = unwrap(value);
|
|
401
472
|
return state => {
|
|
402
473
|
if (!isWrappable(state) || !isWrappable(v)) return v;
|
|
403
|
-
const res = applyState(
|
|
404
|
-
|
|
405
|
-
|
|
474
|
+
const res = applyState(
|
|
475
|
+
v,
|
|
476
|
+
{
|
|
477
|
+
[$ROOT]: state
|
|
478
|
+
},
|
|
479
|
+
$ROOT,
|
|
480
|
+
merge,
|
|
481
|
+
key
|
|
482
|
+
);
|
|
406
483
|
return res === undefined ? state : res;
|
|
407
484
|
};
|
|
408
485
|
}
|
|
@@ -412,7 +489,10 @@ const setterTraps = {
|
|
|
412
489
|
if (property === $RAW) return target;
|
|
413
490
|
const value = target[property];
|
|
414
491
|
let proxy;
|
|
415
|
-
return isWrappable(value)
|
|
492
|
+
return isWrappable(value)
|
|
493
|
+
? producers.get(value) ||
|
|
494
|
+
(producers.set(value, (proxy = new Proxy(value, setterTraps))), proxy)
|
|
495
|
+
: value;
|
|
416
496
|
},
|
|
417
497
|
set(target, property, value) {
|
|
418
498
|
setProperty(target, property, unwrap(value));
|
|
@@ -428,7 +508,7 @@ function produce(fn) {
|
|
|
428
508
|
if (isWrappable(state)) {
|
|
429
509
|
let proxy;
|
|
430
510
|
if (!(proxy = producers.get(state))) {
|
|
431
|
-
producers.set(state, proxy = new Proxy(state, setterTraps));
|
|
511
|
+
producers.set(state, (proxy = new Proxy(state, setterTraps)));
|
|
432
512
|
}
|
|
433
513
|
fn(proxy);
|
|
434
514
|
}
|
|
@@ -440,6 +520,6 @@ const DEV = {
|
|
|
440
520
|
$NODE,
|
|
441
521
|
isWrappable,
|
|
442
522
|
hooks: DevHooks
|
|
443
|
-
}
|
|
523
|
+
};
|
|
444
524
|
|
|
445
525
|
export { $RAW, DEV, createMutable, createStore, modifyMutable, produce, reconcile, unwrap };
|
package/store/dist/server.cjs
CHANGED
|
@@ -87,6 +87,9 @@ function createStore(state) {
|
|
|
87
87
|
function createMutable(state) {
|
|
88
88
|
return state;
|
|
89
89
|
}
|
|
90
|
+
function modifyMutable(state, modifier) {
|
|
91
|
+
modifier(state);
|
|
92
|
+
}
|
|
90
93
|
function reconcile(value, options = {}) {
|
|
91
94
|
return state => {
|
|
92
95
|
if (!isWrappable(state) || !isWrappable(value)) return value;
|
|
@@ -115,6 +118,7 @@ exports.DEV = DEV;
|
|
|
115
118
|
exports.createMutable = createMutable;
|
|
116
119
|
exports.createStore = createStore;
|
|
117
120
|
exports.isWrappable = isWrappable;
|
|
121
|
+
exports.modifyMutable = modifyMutable;
|
|
118
122
|
exports.produce = produce;
|
|
119
123
|
exports.reconcile = reconcile;
|
|
120
124
|
exports.setProperty = setProperty;
|
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
|
}
|
|
@@ -85,6 +85,9 @@ function createStore(state) {
|
|
|
85
85
|
function createMutable(state) {
|
|
86
86
|
return state;
|
|
87
87
|
}
|
|
88
|
+
function modifyMutable(state, modifier) {
|
|
89
|
+
modifier(state);
|
|
90
|
+
}
|
|
88
91
|
function reconcile(value, options = {}) {
|
|
89
92
|
return state => {
|
|
90
93
|
if (!isWrappable(state) || !isWrappable(value)) return value;
|
|
@@ -108,4 +111,16 @@ function produce(fn) {
|
|
|
108
111
|
}
|
|
109
112
|
const DEV = undefined;
|
|
110
113
|
|
|
111
|
-
export {
|
|
114
|
+
export {
|
|
115
|
+
$RAW,
|
|
116
|
+
DEV,
|
|
117
|
+
createMutable,
|
|
118
|
+
createStore,
|
|
119
|
+
isWrappable,
|
|
120
|
+
modifyMutable,
|
|
121
|
+
produce,
|
|
122
|
+
reconcile,
|
|
123
|
+
setProperty,
|
|
124
|
+
unwrap,
|
|
125
|
+
updatePath
|
|
126
|
+
};
|
package/store/dist/store.cjs
CHANGED
|
@@ -271,7 +271,7 @@ function wrap(value) {
|
|
|
271
271
|
const keys = Object.keys(value),
|
|
272
272
|
desc = Object.getOwnPropertyDescriptors(value);
|
|
273
273
|
const proto = Object.getPrototypeOf(value);
|
|
274
|
-
const isClass = value !== null && typeof value === "object" && !Array.isArray(value) && proto !== Object.prototype;
|
|
274
|
+
const isClass = proto !== null && value !== null && typeof value === "object" && !Array.isArray(value) && proto !== Object.prototype;
|
|
275
275
|
if (isClass) {
|
|
276
276
|
const descriptors = Object.getOwnPropertyDescriptors(proto);
|
|
277
277
|
keys.push(...Object.keys(descriptors));
|