solid-js 1.3.16 → 1.4.0-beta.1
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 +30 -25
- package/dist/dev.js +30 -25
- package/dist/server.cjs +15 -9
- package/dist/server.js +16 -9
- package/dist/solid.cjs +30 -25
- package/dist/solid.js +30 -25
- package/package.json +2 -2
- package/store/dist/dev.cjs +63 -28
- package/store/dist/dev.js +63 -30
- package/store/dist/store.cjs +63 -28
- package/store/dist/store.js +63 -30
- package/store/types/modifiers.d.ts +1 -0
- package/store/types/mutable.d.ts +1 -0
- package/store/types/store.d.ts +1 -0
- package/types/index.d.ts +1 -1
- package/types/jsx.d.ts +19 -6
- package/types/reactive/signal.d.ts +12 -13
- package/types/render/component.d.ts +62 -14
- package/types/server/index.d.ts +1 -1
- package/types/server/reactive.d.ts +1 -1
- package/types/server/rendering.d.ts +26 -18
- package/web/dist/dev.cjs +5 -1
- package/web/dist/dev.js +5 -2
- package/web/dist/server.cjs +11 -6
- package/web/dist/server.js +11 -6
- package/web/dist/web.cjs +5 -1
- package/web/dist/web.js +5 -2
- package/web/types/client.d.ts +1 -0
package/dist/solid.js
CHANGED
|
@@ -127,6 +127,7 @@ function nextHydrateContext() {
|
|
|
127
127
|
|
|
128
128
|
const equalFn = (a, b) => a === b;
|
|
129
129
|
const $PROXY = Symbol("solid-proxy");
|
|
130
|
+
const $TRACK = Symbol("solid-track");
|
|
130
131
|
const $DEVCOMP = Symbol("solid-dev-component");
|
|
131
132
|
const signalOptions = {
|
|
132
133
|
equals: equalFn
|
|
@@ -201,7 +202,7 @@ function createEffect(fn, value, options) {
|
|
|
201
202
|
s = SuspenseContext && lookup(Owner, SuspenseContext.id);
|
|
202
203
|
if (s) c.suspense = s;
|
|
203
204
|
c.user = true;
|
|
204
|
-
Effects ? Effects.push(c) :
|
|
205
|
+
Effects ? Effects.push(c) : updateComputation(c);
|
|
205
206
|
}
|
|
206
207
|
function createReaction(onInvalidate, options) {
|
|
207
208
|
let fn;
|
|
@@ -242,13 +243,8 @@ function createResource(source, fetcher, options) {
|
|
|
242
243
|
source = true;
|
|
243
244
|
}
|
|
244
245
|
options || (options = {});
|
|
245
|
-
if (options.globalRefetch !== false) {
|
|
246
|
-
Resources || (Resources = new Set());
|
|
247
|
-
Resources.add(load);
|
|
248
|
-
Owner && onCleanup(() => Resources.delete(load));
|
|
249
|
-
}
|
|
250
246
|
const contexts = new Set(),
|
|
251
|
-
[
|
|
247
|
+
[value, setValue] = createSignal(options.initialValue),
|
|
252
248
|
[track, trigger] = createSignal(undefined, {
|
|
253
249
|
equals: false
|
|
254
250
|
}),
|
|
@@ -260,7 +256,8 @@ function createResource(source, fetcher, options) {
|
|
|
260
256
|
id = null,
|
|
261
257
|
loadedUnderTransition = false,
|
|
262
258
|
scheduled = false,
|
|
263
|
-
|
|
259
|
+
resolved = ("initialValue" in options),
|
|
260
|
+
dynamic = typeof source === "function" && createMemo(source);
|
|
264
261
|
if (sharedConfig.context) {
|
|
265
262
|
id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
|
|
266
263
|
if (sharedConfig.load) initP = sharedConfig.load(id);
|
|
@@ -268,6 +265,7 @@ function createResource(source, fetcher, options) {
|
|
|
268
265
|
function loadEnd(p, v, e, key) {
|
|
269
266
|
if (pr === p) {
|
|
270
267
|
pr = null;
|
|
268
|
+
resolved = true;
|
|
271
269
|
if (initP && p === initP && options.onHydrated) options.onHydrated(key, {
|
|
272
270
|
value: v
|
|
273
271
|
});
|
|
@@ -290,7 +288,7 @@ function createResource(source, fetcher, options) {
|
|
|
290
288
|
}
|
|
291
289
|
function completeLoad(v) {
|
|
292
290
|
batch(() => {
|
|
293
|
-
|
|
291
|
+
setValue(() => v);
|
|
294
292
|
setLoading(false);
|
|
295
293
|
for (const c of contexts.keys()) c.decrement();
|
|
296
294
|
contexts.clear();
|
|
@@ -298,7 +296,7 @@ function createResource(source, fetcher, options) {
|
|
|
298
296
|
}
|
|
299
297
|
function read() {
|
|
300
298
|
const c = SuspenseContext && lookup(Owner, SuspenseContext.id),
|
|
301
|
-
v =
|
|
299
|
+
v = value();
|
|
302
300
|
if (err) throw err;
|
|
303
301
|
if (Listener && !Listener.user && c) {
|
|
304
302
|
createComputed(() => {
|
|
@@ -317,15 +315,15 @@ function createResource(source, fetcher, options) {
|
|
|
317
315
|
if (refetching && scheduled) return;
|
|
318
316
|
scheduled = false;
|
|
319
317
|
setError(err = undefined);
|
|
320
|
-
const lookup = dynamic ?
|
|
318
|
+
const lookup = dynamic ? dynamic() : source;
|
|
321
319
|
loadedUnderTransition = Transition && Transition.running;
|
|
322
320
|
if (lookup == null || lookup === false) {
|
|
323
|
-
loadEnd(pr, untrack(
|
|
321
|
+
loadEnd(pr, untrack(value));
|
|
324
322
|
return;
|
|
325
323
|
}
|
|
326
324
|
if (Transition && pr) Transition.promises.delete(pr);
|
|
327
325
|
const p = initP || untrack(() => fetcher(lookup, {
|
|
328
|
-
value:
|
|
326
|
+
value: value(),
|
|
329
327
|
refetching
|
|
330
328
|
}));
|
|
331
329
|
if (typeof p !== "object" || !("then" in p)) {
|
|
@@ -351,18 +349,21 @@ function createResource(source, fetcher, options) {
|
|
|
351
349
|
get() {
|
|
352
350
|
return error();
|
|
353
351
|
}
|
|
352
|
+
},
|
|
353
|
+
latest: {
|
|
354
|
+
get() {
|
|
355
|
+
if (!resolved) return read();
|
|
356
|
+
if (err) throw err;
|
|
357
|
+
return value();
|
|
358
|
+
}
|
|
354
359
|
}
|
|
355
360
|
});
|
|
356
361
|
if (dynamic) createComputed(() => load(false));else load(false);
|
|
357
362
|
return [read, {
|
|
358
363
|
refetch: load,
|
|
359
|
-
mutate:
|
|
364
|
+
mutate: setValue
|
|
360
365
|
}];
|
|
361
366
|
}
|
|
362
|
-
let Resources;
|
|
363
|
-
function refetchResources(info) {
|
|
364
|
-
return Resources && Promise.all([...Resources].map(fn => fn(info)));
|
|
365
|
-
}
|
|
366
367
|
function createDeferred(source, options) {
|
|
367
368
|
let t,
|
|
368
369
|
timeout = options ? options.timeoutMs : undefined;
|
|
@@ -736,11 +737,14 @@ function runUpdates(fn, init) {
|
|
|
736
737
|
if (Effects) wait = true;else Effects = [];
|
|
737
738
|
ExecCount++;
|
|
738
739
|
try {
|
|
739
|
-
|
|
740
|
+
const res = fn();
|
|
741
|
+
completeUpdates(wait);
|
|
742
|
+
return res;
|
|
740
743
|
} catch (err) {
|
|
741
744
|
handleError(err);
|
|
742
745
|
} finally {
|
|
743
|
-
|
|
746
|
+
Updates = null;
|
|
747
|
+
if (!wait) Effects = null;
|
|
744
748
|
}
|
|
745
749
|
}
|
|
746
750
|
function completeUpdates(wait) {
|
|
@@ -981,6 +985,7 @@ function mapArray(list, mapFn, options = {}) {
|
|
|
981
985
|
let newItems = list() || [],
|
|
982
986
|
i,
|
|
983
987
|
j;
|
|
988
|
+
newItems[$TRACK];
|
|
984
989
|
return untrack(() => {
|
|
985
990
|
let newLen = newItems.length,
|
|
986
991
|
newIndices,
|
|
@@ -1082,6 +1087,7 @@ function indexArray(list, mapFn, options = {}) {
|
|
|
1082
1087
|
onCleanup(() => dispose(disposers));
|
|
1083
1088
|
return () => {
|
|
1084
1089
|
const newItems = list() || [];
|
|
1090
|
+
newItems[$TRACK];
|
|
1085
1091
|
return untrack(() => {
|
|
1086
1092
|
if (newItems.length === 0) {
|
|
1087
1093
|
if (len !== 0) {
|
|
@@ -1137,6 +1143,7 @@ function enableHydration() {
|
|
|
1137
1143
|
hydrationEnabled = true;
|
|
1138
1144
|
}
|
|
1139
1145
|
function createComponent(Comp, props) {
|
|
1146
|
+
if (props == null || typeof props !== "object") props = {};
|
|
1140
1147
|
if (hydrationEnabled) {
|
|
1141
1148
|
if (sharedConfig.context) {
|
|
1142
1149
|
const c = sharedConfig.context;
|
|
@@ -1177,7 +1184,7 @@ const propTraps = {
|
|
|
1177
1184
|
}
|
|
1178
1185
|
};
|
|
1179
1186
|
function resolveSource(s) {
|
|
1180
|
-
return typeof s === "function" ? s() : s;
|
|
1187
|
+
return (s = typeof s === "function" ? s() : s) == null || typeof s !== "object" ? {} : s;
|
|
1181
1188
|
}
|
|
1182
1189
|
function mergeProps(...sources) {
|
|
1183
1190
|
return new Proxy({
|
|
@@ -1245,9 +1252,7 @@ function lazy(fn) {
|
|
|
1245
1252
|
});
|
|
1246
1253
|
comp = s;
|
|
1247
1254
|
} else if (!comp) {
|
|
1248
|
-
const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default)
|
|
1249
|
-
globalRefetch: false
|
|
1250
|
-
});
|
|
1255
|
+
const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default));
|
|
1251
1256
|
comp = s;
|
|
1252
1257
|
} else {
|
|
1253
1258
|
const c = comp();
|
|
@@ -1499,4 +1504,4 @@ function Suspense(props) {
|
|
|
1499
1504
|
|
|
1500
1505
|
let DEV;
|
|
1501
1506
|
|
|
1502
|
-
export { $DEVCOMP, $PROXY, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, cancelCallback, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createReaction, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount,
|
|
1507
|
+
export { $DEVCOMP, $PROXY, $TRACK, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, cancelCallback, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createReaction, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, resetErrorBoundaries, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
|
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.4.0-beta.1",
|
|
5
5
|
"author": "Ryan Carniato",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://solidjs.com",
|
|
@@ -144,5 +144,5 @@
|
|
|
144
144
|
"compiler",
|
|
145
145
|
"performance"
|
|
146
146
|
],
|
|
147
|
-
"gitHead": "
|
|
147
|
+
"gitHead": "34628200f7c8e0a329905688a455848096a3e429"
|
|
148
148
|
}
|
package/store/dist/dev.cjs
CHANGED
|
@@ -71,11 +71,14 @@ function proxyDescriptor(target, property) {
|
|
|
71
71
|
desc.get = () => target[solidJs.$PROXY][property];
|
|
72
72
|
return desc;
|
|
73
73
|
}
|
|
74
|
-
function
|
|
74
|
+
function trackSelf(target) {
|
|
75
75
|
if (solidJs.getListener()) {
|
|
76
76
|
const nodes = getDataNodes(target);
|
|
77
77
|
(nodes._ || (nodes._ = createDataNode()))();
|
|
78
78
|
}
|
|
79
|
+
}
|
|
80
|
+
function ownKeys(target) {
|
|
81
|
+
trackSelf(target);
|
|
79
82
|
return Reflect.ownKeys(target);
|
|
80
83
|
}
|
|
81
84
|
function createDataNode() {
|
|
@@ -92,18 +95,12 @@ const proxyTraps$1 = {
|
|
|
92
95
|
if (property === solidJs.$PROXY) return receiver;
|
|
93
96
|
const value = target[property];
|
|
94
97
|
if (property === $NODE || property === "__proto__") return value;
|
|
95
|
-
|
|
98
|
+
if (property === solidJs.$TRACK) return trackSelf(target);
|
|
96
99
|
if (solidJs.getListener() && (typeof value !== "function" || target.hasOwnProperty(property))) {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
node = nodes._ || (nodes._ = createDataNode());
|
|
100
|
-
node();
|
|
101
|
-
}
|
|
102
|
-
nodes = getDataNodes(target);
|
|
103
|
-
node = nodes[property] || (nodes[property] = createDataNode());
|
|
104
|
-
node();
|
|
100
|
+
const nodes = getDataNodes(target);
|
|
101
|
+
(nodes[property] || (nodes[property] = createDataNode()))();
|
|
105
102
|
}
|
|
106
|
-
return
|
|
103
|
+
return isWrappable(value) ? wrap$1(value, target[$NAME] && `${target[$NAME]}:${property.toString()}`) : value;
|
|
107
104
|
},
|
|
108
105
|
set() {
|
|
109
106
|
console.warn("Cannot mutate a Store directly");
|
|
@@ -120,16 +117,14 @@ function setProperty(state, property, value) {
|
|
|
120
117
|
if (state[property] === value) return;
|
|
121
118
|
const array = Array.isArray(state);
|
|
122
119
|
const len = state.length;
|
|
123
|
-
|
|
124
|
-
const notify = array || isUndefined === property in state;
|
|
125
|
-
if (isUndefined) {
|
|
120
|
+
if (value === undefined) {
|
|
126
121
|
delete state[property];
|
|
127
122
|
} else state[property] = value;
|
|
128
123
|
let nodes = getDataNodes(state),
|
|
129
124
|
node;
|
|
130
125
|
(node = nodes[property]) && node.$();
|
|
131
126
|
if (array && state.length !== len) (node = nodes.length) && node.$();
|
|
132
|
-
|
|
127
|
+
(node = nodes._) && node.$();
|
|
133
128
|
}
|
|
134
129
|
function mergeStoreNode(state, value) {
|
|
135
130
|
const keys = Object.keys(value);
|
|
@@ -138,6 +133,18 @@ function mergeStoreNode(state, value) {
|
|
|
138
133
|
setProperty(state, key, value[key]);
|
|
139
134
|
}
|
|
140
135
|
}
|
|
136
|
+
function updateArray(current, next) {
|
|
137
|
+
if (typeof next === "function") next = next(current);
|
|
138
|
+
next = unwrap(next);
|
|
139
|
+
if (current === next) return;
|
|
140
|
+
let i = 0,
|
|
141
|
+
len = next.length;
|
|
142
|
+
for (; i < len; i++) {
|
|
143
|
+
const value = next[i];
|
|
144
|
+
if (current[i] !== value) setProperty(current, i, value);
|
|
145
|
+
}
|
|
146
|
+
setProperty(current, "length", len);
|
|
147
|
+
}
|
|
141
148
|
function updatePath(current, path, traversed = []) {
|
|
142
149
|
let part,
|
|
143
150
|
prev = current;
|
|
@@ -185,6 +192,7 @@ function updatePath(current, path, traversed = []) {
|
|
|
185
192
|
}
|
|
186
193
|
function createStore(store, options) {
|
|
187
194
|
const unwrappedStore = unwrap(store || {});
|
|
195
|
+
const isArray = Array.isArray(unwrappedStore);
|
|
188
196
|
if (typeof unwrappedStore !== "object" && typeof unwrappedStore !== "function") throw new Error(`Unexpected type ${typeof unwrappedStore} received when initializing 'createStore'. Expected an object.`);
|
|
189
197
|
const wrappedStore = wrap$1(unwrappedStore, (options && options.name || solidJs.DEV.hashValue(unwrappedStore)));
|
|
190
198
|
{
|
|
@@ -194,7 +202,9 @@ function createStore(store, options) {
|
|
|
194
202
|
});
|
|
195
203
|
}
|
|
196
204
|
function setStore(...args) {
|
|
197
|
-
solidJs.batch(() =>
|
|
205
|
+
solidJs.batch(() => {
|
|
206
|
+
isArray && args.length === 1 ? updateArray(unwrappedStore, args[0]) : updatePath(unwrappedStore, args);
|
|
207
|
+
});
|
|
198
208
|
}
|
|
199
209
|
return [wrappedStore, setStore];
|
|
200
210
|
}
|
|
@@ -205,18 +215,14 @@ const proxyTraps = {
|
|
|
205
215
|
if (property === solidJs.$PROXY) return receiver;
|
|
206
216
|
const value = target[property];
|
|
207
217
|
if (property === $NODE || property === "__proto__") return value;
|
|
208
|
-
|
|
218
|
+
if (property === solidJs.$TRACK) return trackSelf(target);
|
|
209
219
|
if (solidJs.getListener() && (typeof value !== "function" || target.hasOwnProperty(property))) {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
nodes = getDataNodes(target);
|
|
216
|
-
node = nodes[property] || (nodes[property] = createDataNode());
|
|
217
|
-
node();
|
|
220
|
+
const nodes = getDataNodes(target);
|
|
221
|
+
(nodes[property] || (nodes[property] = createDataNode()))();
|
|
222
|
+
} else if (value != null && typeof value === "function" && value === Array.prototype[property]) {
|
|
223
|
+
return (...args) => solidJs.batch(() => Array.prototype[property].apply(receiver, args));
|
|
218
224
|
}
|
|
219
|
-
return
|
|
225
|
+
return isWrappable(value) ? wrap(value, target[$NAME] && `${target[$NAME]}:${property.toString()}`) : value;
|
|
220
226
|
},
|
|
221
227
|
set(target, property, value) {
|
|
222
228
|
setProperty(target, property, unwrap(value));
|
|
@@ -271,6 +277,9 @@ function createMutable(state, options) {
|
|
|
271
277
|
}
|
|
272
278
|
return wrappedStore;
|
|
273
279
|
}
|
|
280
|
+
function modifyMutable(state, modifier) {
|
|
281
|
+
solidJs.batch(() => modifier(unwrap(state)));
|
|
282
|
+
}
|
|
274
283
|
|
|
275
284
|
function applyState(target, parent, property, merge, key) {
|
|
276
285
|
const previous = parent[property];
|
|
@@ -348,9 +357,9 @@ function reconcile(value, options = {}) {
|
|
|
348
357
|
v = unwrap(value);
|
|
349
358
|
return state => {
|
|
350
359
|
if (!isWrappable(state) || !isWrappable(v)) return v;
|
|
351
|
-
applyState(v, {
|
|
360
|
+
solidJs.batch(() => applyState(v, {
|
|
352
361
|
state
|
|
353
|
-
}, "state", merge, key);
|
|
362
|
+
}, "state", merge, key));
|
|
354
363
|
return state;
|
|
355
364
|
};
|
|
356
365
|
}
|
|
@@ -375,10 +384,36 @@ function produce(fn) {
|
|
|
375
384
|
return state;
|
|
376
385
|
};
|
|
377
386
|
}
|
|
387
|
+
function splice(start, deleteCount = 0, ...items) {
|
|
388
|
+
return state => {
|
|
389
|
+
if (Array.isArray(state)) {
|
|
390
|
+
if (start < 0) start = start + state.length;
|
|
391
|
+
if (deleteCount < 0) deleteCount = 0;
|
|
392
|
+
const stop = start + deleteCount;
|
|
393
|
+
if (deleteCount >= items.length) {
|
|
394
|
+
for (let i = stop; i < state.length; i++) {
|
|
395
|
+
setProperty(state, start + i - stop, state[i]);
|
|
396
|
+
}
|
|
397
|
+
} else {
|
|
398
|
+
const offset = items.length - deleteCount;
|
|
399
|
+
for (let i = state.length - 1; i >= stop; i--) {
|
|
400
|
+
setProperty(state, i + offset, state[i]);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
for (let i = 0; i < items.length; i++) {
|
|
404
|
+
setProperty(state, start + i, items[i]);
|
|
405
|
+
}
|
|
406
|
+
setProperty(state, "length", state.length + items.length - deleteCount);
|
|
407
|
+
}
|
|
408
|
+
return state;
|
|
409
|
+
};
|
|
410
|
+
}
|
|
378
411
|
|
|
379
412
|
exports.$RAW = $RAW;
|
|
380
413
|
exports.createMutable = createMutable;
|
|
381
414
|
exports.createStore = createStore;
|
|
415
|
+
exports.modifyMutable = modifyMutable;
|
|
382
416
|
exports.produce = produce;
|
|
383
417
|
exports.reconcile = reconcile;
|
|
418
|
+
exports.splice = splice;
|
|
384
419
|
exports.unwrap = unwrap;
|
package/store/dist/dev.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $PROXY, DEV, getListener, batch, createSignal } from 'solid-js';
|
|
1
|
+
import { $PROXY, DEV, $TRACK, getListener, batch, createSignal } from 'solid-js';
|
|
2
2
|
|
|
3
3
|
const $RAW = Symbol("store-raw"),
|
|
4
4
|
$NODE = Symbol("store-node"),
|
|
@@ -67,11 +67,14 @@ function proxyDescriptor(target, property) {
|
|
|
67
67
|
desc.get = () => target[$PROXY][property];
|
|
68
68
|
return desc;
|
|
69
69
|
}
|
|
70
|
-
function
|
|
70
|
+
function trackSelf(target) {
|
|
71
71
|
if (getListener()) {
|
|
72
72
|
const nodes = getDataNodes(target);
|
|
73
73
|
(nodes._ || (nodes._ = createDataNode()))();
|
|
74
74
|
}
|
|
75
|
+
}
|
|
76
|
+
function ownKeys(target) {
|
|
77
|
+
trackSelf(target);
|
|
75
78
|
return Reflect.ownKeys(target);
|
|
76
79
|
}
|
|
77
80
|
function createDataNode() {
|
|
@@ -88,18 +91,12 @@ const proxyTraps$1 = {
|
|
|
88
91
|
if (property === $PROXY) return receiver;
|
|
89
92
|
const value = target[property];
|
|
90
93
|
if (property === $NODE || property === "__proto__") return value;
|
|
91
|
-
|
|
94
|
+
if (property === $TRACK) return trackSelf(target);
|
|
92
95
|
if (getListener() && (typeof value !== "function" || target.hasOwnProperty(property))) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
node = nodes._ || (nodes._ = createDataNode());
|
|
96
|
-
node();
|
|
97
|
-
}
|
|
98
|
-
nodes = getDataNodes(target);
|
|
99
|
-
node = nodes[property] || (nodes[property] = createDataNode());
|
|
100
|
-
node();
|
|
96
|
+
const nodes = getDataNodes(target);
|
|
97
|
+
(nodes[property] || (nodes[property] = createDataNode()))();
|
|
101
98
|
}
|
|
102
|
-
return
|
|
99
|
+
return isWrappable(value) ? wrap$1(value, target[$NAME] && `${target[$NAME]}:${property.toString()}`) : value;
|
|
103
100
|
},
|
|
104
101
|
set() {
|
|
105
102
|
console.warn("Cannot mutate a Store directly");
|
|
@@ -116,16 +113,14 @@ function setProperty(state, property, value) {
|
|
|
116
113
|
if (state[property] === value) return;
|
|
117
114
|
const array = Array.isArray(state);
|
|
118
115
|
const len = state.length;
|
|
119
|
-
|
|
120
|
-
const notify = array || isUndefined === property in state;
|
|
121
|
-
if (isUndefined) {
|
|
116
|
+
if (value === undefined) {
|
|
122
117
|
delete state[property];
|
|
123
118
|
} else state[property] = value;
|
|
124
119
|
let nodes = getDataNodes(state),
|
|
125
120
|
node;
|
|
126
121
|
(node = nodes[property]) && node.$();
|
|
127
122
|
if (array && state.length !== len) (node = nodes.length) && node.$();
|
|
128
|
-
|
|
123
|
+
(node = nodes._) && node.$();
|
|
129
124
|
}
|
|
130
125
|
function mergeStoreNode(state, value) {
|
|
131
126
|
const keys = Object.keys(value);
|
|
@@ -134,6 +129,18 @@ function mergeStoreNode(state, value) {
|
|
|
134
129
|
setProperty(state, key, value[key]);
|
|
135
130
|
}
|
|
136
131
|
}
|
|
132
|
+
function updateArray(current, next) {
|
|
133
|
+
if (typeof next === "function") next = next(current);
|
|
134
|
+
next = unwrap(next);
|
|
135
|
+
if (current === next) return;
|
|
136
|
+
let i = 0,
|
|
137
|
+
len = next.length;
|
|
138
|
+
for (; i < len; i++) {
|
|
139
|
+
const value = next[i];
|
|
140
|
+
if (current[i] !== value) setProperty(current, i, value);
|
|
141
|
+
}
|
|
142
|
+
setProperty(current, "length", len);
|
|
143
|
+
}
|
|
137
144
|
function updatePath(current, path, traversed = []) {
|
|
138
145
|
let part,
|
|
139
146
|
prev = current;
|
|
@@ -181,6 +188,7 @@ function updatePath(current, path, traversed = []) {
|
|
|
181
188
|
}
|
|
182
189
|
function createStore(store, options) {
|
|
183
190
|
const unwrappedStore = unwrap(store || {});
|
|
191
|
+
const isArray = Array.isArray(unwrappedStore);
|
|
184
192
|
if (typeof unwrappedStore !== "object" && typeof unwrappedStore !== "function") throw new Error(`Unexpected type ${typeof unwrappedStore} received when initializing 'createStore'. Expected an object.`);
|
|
185
193
|
const wrappedStore = wrap$1(unwrappedStore, (options && options.name || DEV.hashValue(unwrappedStore)));
|
|
186
194
|
{
|
|
@@ -190,7 +198,9 @@ function createStore(store, options) {
|
|
|
190
198
|
});
|
|
191
199
|
}
|
|
192
200
|
function setStore(...args) {
|
|
193
|
-
batch(() =>
|
|
201
|
+
batch(() => {
|
|
202
|
+
isArray && args.length === 1 ? updateArray(unwrappedStore, args[0]) : updatePath(unwrappedStore, args);
|
|
203
|
+
});
|
|
194
204
|
}
|
|
195
205
|
return [wrappedStore, setStore];
|
|
196
206
|
}
|
|
@@ -201,18 +211,14 @@ const proxyTraps = {
|
|
|
201
211
|
if (property === $PROXY) return receiver;
|
|
202
212
|
const value = target[property];
|
|
203
213
|
if (property === $NODE || property === "__proto__") return value;
|
|
204
|
-
|
|
214
|
+
if (property === $TRACK) return trackSelf(target);
|
|
205
215
|
if (getListener() && (typeof value !== "function" || target.hasOwnProperty(property))) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
}
|
|
211
|
-
nodes = getDataNodes(target);
|
|
212
|
-
node = nodes[property] || (nodes[property] = createDataNode());
|
|
213
|
-
node();
|
|
216
|
+
const nodes = getDataNodes(target);
|
|
217
|
+
(nodes[property] || (nodes[property] = createDataNode()))();
|
|
218
|
+
} else if (value != null && typeof value === "function" && value === Array.prototype[property]) {
|
|
219
|
+
return (...args) => batch(() => Array.prototype[property].apply(receiver, args));
|
|
214
220
|
}
|
|
215
|
-
return
|
|
221
|
+
return isWrappable(value) ? wrap(value, target[$NAME] && `${target[$NAME]}:${property.toString()}`) : value;
|
|
216
222
|
},
|
|
217
223
|
set(target, property, value) {
|
|
218
224
|
setProperty(target, property, unwrap(value));
|
|
@@ -267,6 +273,9 @@ function createMutable(state, options) {
|
|
|
267
273
|
}
|
|
268
274
|
return wrappedStore;
|
|
269
275
|
}
|
|
276
|
+
function modifyMutable(state, modifier) {
|
|
277
|
+
batch(() => modifier(unwrap(state)));
|
|
278
|
+
}
|
|
270
279
|
|
|
271
280
|
function applyState(target, parent, property, merge, key) {
|
|
272
281
|
const previous = parent[property];
|
|
@@ -344,9 +353,9 @@ function reconcile(value, options = {}) {
|
|
|
344
353
|
v = unwrap(value);
|
|
345
354
|
return state => {
|
|
346
355
|
if (!isWrappable(state) || !isWrappable(v)) return v;
|
|
347
|
-
applyState(v, {
|
|
356
|
+
batch(() => applyState(v, {
|
|
348
357
|
state
|
|
349
|
-
}, "state", merge, key);
|
|
358
|
+
}, "state", merge, key));
|
|
350
359
|
return state;
|
|
351
360
|
};
|
|
352
361
|
}
|
|
@@ -371,5 +380,29 @@ function produce(fn) {
|
|
|
371
380
|
return state;
|
|
372
381
|
};
|
|
373
382
|
}
|
|
383
|
+
function splice(start, deleteCount = 0, ...items) {
|
|
384
|
+
return state => {
|
|
385
|
+
if (Array.isArray(state)) {
|
|
386
|
+
if (start < 0) start = start + state.length;
|
|
387
|
+
if (deleteCount < 0) deleteCount = 0;
|
|
388
|
+
const stop = start + deleteCount;
|
|
389
|
+
if (deleteCount >= items.length) {
|
|
390
|
+
for (let i = stop; i < state.length; i++) {
|
|
391
|
+
setProperty(state, start + i - stop, state[i]);
|
|
392
|
+
}
|
|
393
|
+
} else {
|
|
394
|
+
const offset = items.length - deleteCount;
|
|
395
|
+
for (let i = state.length - 1; i >= stop; i--) {
|
|
396
|
+
setProperty(state, i + offset, state[i]);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
for (let i = 0; i < items.length; i++) {
|
|
400
|
+
setProperty(state, start + i, items[i]);
|
|
401
|
+
}
|
|
402
|
+
setProperty(state, "length", state.length + items.length - deleteCount);
|
|
403
|
+
}
|
|
404
|
+
return state;
|
|
405
|
+
};
|
|
406
|
+
}
|
|
374
407
|
|
|
375
|
-
export { $RAW, createMutable, createStore, produce, reconcile, unwrap };
|
|
408
|
+
export { $RAW, createMutable, createStore, modifyMutable, produce, reconcile, splice, unwrap };
|