solid-js 1.4.0-beta.0 → 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 +5 -1
- package/dist/dev.js +5 -1
- package/dist/server.cjs +6 -0
- package/dist/server.js +6 -0
- package/dist/solid.cjs +5 -1
- package/dist/solid.js +5 -1
- package/package.json +2 -2
- package/store/dist/dev.cjs +35 -3
- package/store/dist/dev.js +34 -4
- package/store/dist/store.cjs +35 -3
- package/store/dist/store.js +34 -4
- package/store/types/modifiers.d.ts +1 -0
- package/store/types/mutable.d.ts +1 -0
- package/types/reactive/signal.d.ts +9 -9
- package/types/render/component.d.ts +56 -3
- package/types/server/reactive.d.ts +1 -1
- package/types/server/rendering.d.ts +23 -9
package/dist/dev.cjs
CHANGED
|
@@ -263,6 +263,7 @@ function createResource(source, fetcher, options) {
|
|
|
263
263
|
id = null,
|
|
264
264
|
loadedUnderTransition = false,
|
|
265
265
|
scheduled = false,
|
|
266
|
+
resolved = ("initialValue" in options),
|
|
266
267
|
dynamic = typeof source === "function" && createMemo(source);
|
|
267
268
|
if (sharedConfig.context) {
|
|
268
269
|
id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
|
|
@@ -271,6 +272,7 @@ function createResource(source, fetcher, options) {
|
|
|
271
272
|
function loadEnd(p, v, e, key) {
|
|
272
273
|
if (pr === p) {
|
|
273
274
|
pr = null;
|
|
275
|
+
resolved = true;
|
|
274
276
|
if (initP && p === initP && options.onHydrated) options.onHydrated(key, {
|
|
275
277
|
value: v
|
|
276
278
|
});
|
|
@@ -357,6 +359,7 @@ function createResource(source, fetcher, options) {
|
|
|
357
359
|
},
|
|
358
360
|
latest: {
|
|
359
361
|
get() {
|
|
362
|
+
if (!resolved) return read();
|
|
360
363
|
if (err) throw err;
|
|
361
364
|
return value();
|
|
362
365
|
}
|
|
@@ -1225,6 +1228,7 @@ function enableHydration() {
|
|
|
1225
1228
|
hydrationEnabled = true;
|
|
1226
1229
|
}
|
|
1227
1230
|
function createComponent(Comp, props) {
|
|
1231
|
+
if (props == null || typeof props !== "object") props = {};
|
|
1228
1232
|
if (hydrationEnabled) {
|
|
1229
1233
|
if (sharedConfig.context) {
|
|
1230
1234
|
const c = sharedConfig.context;
|
|
@@ -1265,7 +1269,7 @@ const propTraps = {
|
|
|
1265
1269
|
}
|
|
1266
1270
|
};
|
|
1267
1271
|
function resolveSource(s) {
|
|
1268
|
-
return typeof s === "function" ? s() : s;
|
|
1272
|
+
return (s = typeof s === "function" ? s() : s) == null || typeof s !== "object" ? {} : s;
|
|
1269
1273
|
}
|
|
1270
1274
|
function mergeProps(...sources) {
|
|
1271
1275
|
return new Proxy({
|
package/dist/dev.js
CHANGED
|
@@ -259,6 +259,7 @@ function createResource(source, fetcher, options) {
|
|
|
259
259
|
id = null,
|
|
260
260
|
loadedUnderTransition = false,
|
|
261
261
|
scheduled = false,
|
|
262
|
+
resolved = ("initialValue" in options),
|
|
262
263
|
dynamic = typeof source === "function" && createMemo(source);
|
|
263
264
|
if (sharedConfig.context) {
|
|
264
265
|
id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
|
|
@@ -267,6 +268,7 @@ function createResource(source, fetcher, options) {
|
|
|
267
268
|
function loadEnd(p, v, e, key) {
|
|
268
269
|
if (pr === p) {
|
|
269
270
|
pr = null;
|
|
271
|
+
resolved = true;
|
|
270
272
|
if (initP && p === initP && options.onHydrated) options.onHydrated(key, {
|
|
271
273
|
value: v
|
|
272
274
|
});
|
|
@@ -353,6 +355,7 @@ function createResource(source, fetcher, options) {
|
|
|
353
355
|
},
|
|
354
356
|
latest: {
|
|
355
357
|
get() {
|
|
358
|
+
if (!resolved) return read();
|
|
356
359
|
if (err) throw err;
|
|
357
360
|
return value();
|
|
358
361
|
}
|
|
@@ -1221,6 +1224,7 @@ function enableHydration() {
|
|
|
1221
1224
|
hydrationEnabled = true;
|
|
1222
1225
|
}
|
|
1223
1226
|
function createComponent(Comp, props) {
|
|
1227
|
+
if (props == null || typeof props !== "object") props = {};
|
|
1224
1228
|
if (hydrationEnabled) {
|
|
1225
1229
|
if (sharedConfig.context) {
|
|
1226
1230
|
const c = sharedConfig.context;
|
|
@@ -1261,7 +1265,7 @@ const propTraps = {
|
|
|
1261
1265
|
}
|
|
1262
1266
|
};
|
|
1263
1267
|
function resolveSource(s) {
|
|
1264
|
-
return typeof s === "function" ? s() : s;
|
|
1268
|
+
return (s = typeof s === "function" ? s() : s) == null || typeof s !== "object" ? {} : s;
|
|
1265
1269
|
}
|
|
1266
1270
|
function mergeProps(...sources) {
|
|
1267
1271
|
return new Proxy({
|
package/dist/server.cjs
CHANGED
|
@@ -246,6 +246,7 @@ function createUniqueId() {
|
|
|
246
246
|
return `${ctx.id}${ctx.count++}`;
|
|
247
247
|
}
|
|
248
248
|
function createComponent(Comp, props) {
|
|
249
|
+
if (props == null || typeof props !== "object") props = {};
|
|
249
250
|
if (sharedConfig.context && !sharedConfig.context.noHydrate) {
|
|
250
251
|
const c = sharedConfig.context;
|
|
251
252
|
setHydrateContext(nextHydrateContext());
|
|
@@ -372,6 +373,11 @@ function createResource(source, fetcher, options = {}) {
|
|
|
372
373
|
};
|
|
373
374
|
read.loading = false;
|
|
374
375
|
read.error = undefined;
|
|
376
|
+
Object.defineProperty(read, "latest", {
|
|
377
|
+
get() {
|
|
378
|
+
return read();
|
|
379
|
+
}
|
|
380
|
+
});
|
|
375
381
|
function load() {
|
|
376
382
|
const ctx = sharedConfig.context;
|
|
377
383
|
if (!ctx.async) return read.loading = !!(typeof source === "function" ? source() : source);
|
package/dist/server.js
CHANGED
|
@@ -242,6 +242,7 @@ function createUniqueId() {
|
|
|
242
242
|
return `${ctx.id}${ctx.count++}`;
|
|
243
243
|
}
|
|
244
244
|
function createComponent(Comp, props) {
|
|
245
|
+
if (props == null || typeof props !== "object") props = {};
|
|
245
246
|
if (sharedConfig.context && !sharedConfig.context.noHydrate) {
|
|
246
247
|
const c = sharedConfig.context;
|
|
247
248
|
setHydrateContext(nextHydrateContext());
|
|
@@ -368,6 +369,11 @@ function createResource(source, fetcher, options = {}) {
|
|
|
368
369
|
};
|
|
369
370
|
read.loading = false;
|
|
370
371
|
read.error = undefined;
|
|
372
|
+
Object.defineProperty(read, "latest", {
|
|
373
|
+
get() {
|
|
374
|
+
return read();
|
|
375
|
+
}
|
|
376
|
+
});
|
|
371
377
|
function load() {
|
|
372
378
|
const ctx = sharedConfig.context;
|
|
373
379
|
if (!ctx.async) return read.loading = !!(typeof source === "function" ? source() : source);
|
package/dist/solid.cjs
CHANGED
|
@@ -260,6 +260,7 @@ function createResource(source, fetcher, options) {
|
|
|
260
260
|
id = null,
|
|
261
261
|
loadedUnderTransition = false,
|
|
262
262
|
scheduled = false,
|
|
263
|
+
resolved = ("initialValue" in options),
|
|
263
264
|
dynamic = typeof source === "function" && createMemo(source);
|
|
264
265
|
if (sharedConfig.context) {
|
|
265
266
|
id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
|
|
@@ -268,6 +269,7 @@ function createResource(source, fetcher, options) {
|
|
|
268
269
|
function loadEnd(p, v, e, key) {
|
|
269
270
|
if (pr === p) {
|
|
270
271
|
pr = null;
|
|
272
|
+
resolved = true;
|
|
271
273
|
if (initP && p === initP && options.onHydrated) options.onHydrated(key, {
|
|
272
274
|
value: v
|
|
273
275
|
});
|
|
@@ -354,6 +356,7 @@ function createResource(source, fetcher, options) {
|
|
|
354
356
|
},
|
|
355
357
|
latest: {
|
|
356
358
|
get() {
|
|
359
|
+
if (!resolved) return read();
|
|
357
360
|
if (err) throw err;
|
|
358
361
|
return value();
|
|
359
362
|
}
|
|
@@ -1144,6 +1147,7 @@ function enableHydration() {
|
|
|
1144
1147
|
hydrationEnabled = true;
|
|
1145
1148
|
}
|
|
1146
1149
|
function createComponent(Comp, props) {
|
|
1150
|
+
if (props == null || typeof props !== "object") props = {};
|
|
1147
1151
|
if (hydrationEnabled) {
|
|
1148
1152
|
if (sharedConfig.context) {
|
|
1149
1153
|
const c = sharedConfig.context;
|
|
@@ -1184,7 +1188,7 @@ const propTraps = {
|
|
|
1184
1188
|
}
|
|
1185
1189
|
};
|
|
1186
1190
|
function resolveSource(s) {
|
|
1187
|
-
return typeof s === "function" ? s() : s;
|
|
1191
|
+
return (s = typeof s === "function" ? s() : s) == null || typeof s !== "object" ? {} : s;
|
|
1188
1192
|
}
|
|
1189
1193
|
function mergeProps(...sources) {
|
|
1190
1194
|
return new Proxy({
|
package/dist/solid.js
CHANGED
|
@@ -256,6 +256,7 @@ function createResource(source, fetcher, options) {
|
|
|
256
256
|
id = null,
|
|
257
257
|
loadedUnderTransition = false,
|
|
258
258
|
scheduled = false,
|
|
259
|
+
resolved = ("initialValue" in options),
|
|
259
260
|
dynamic = typeof source === "function" && createMemo(source);
|
|
260
261
|
if (sharedConfig.context) {
|
|
261
262
|
id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
|
|
@@ -264,6 +265,7 @@ function createResource(source, fetcher, options) {
|
|
|
264
265
|
function loadEnd(p, v, e, key) {
|
|
265
266
|
if (pr === p) {
|
|
266
267
|
pr = null;
|
|
268
|
+
resolved = true;
|
|
267
269
|
if (initP && p === initP && options.onHydrated) options.onHydrated(key, {
|
|
268
270
|
value: v
|
|
269
271
|
});
|
|
@@ -350,6 +352,7 @@ function createResource(source, fetcher, options) {
|
|
|
350
352
|
},
|
|
351
353
|
latest: {
|
|
352
354
|
get() {
|
|
355
|
+
if (!resolved) return read();
|
|
353
356
|
if (err) throw err;
|
|
354
357
|
return value();
|
|
355
358
|
}
|
|
@@ -1140,6 +1143,7 @@ function enableHydration() {
|
|
|
1140
1143
|
hydrationEnabled = true;
|
|
1141
1144
|
}
|
|
1142
1145
|
function createComponent(Comp, props) {
|
|
1146
|
+
if (props == null || typeof props !== "object") props = {};
|
|
1143
1147
|
if (hydrationEnabled) {
|
|
1144
1148
|
if (sharedConfig.context) {
|
|
1145
1149
|
const c = sharedConfig.context;
|
|
@@ -1180,7 +1184,7 @@ const propTraps = {
|
|
|
1180
1184
|
}
|
|
1181
1185
|
};
|
|
1182
1186
|
function resolveSource(s) {
|
|
1183
|
-
return typeof s === "function" ? s() : s;
|
|
1187
|
+
return (s = typeof s === "function" ? s() : s) == null || typeof s !== "object" ? {} : s;
|
|
1184
1188
|
}
|
|
1185
1189
|
function mergeProps(...sources) {
|
|
1186
1190
|
return new Proxy({
|
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.0-beta.
|
|
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
|
@@ -134,6 +134,9 @@ function mergeStoreNode(state, value) {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
function updateArray(current, next) {
|
|
137
|
+
if (typeof next === "function") next = next(current);
|
|
138
|
+
next = unwrap(next);
|
|
139
|
+
if (current === next) return;
|
|
137
140
|
let i = 0,
|
|
138
141
|
len = next.length;
|
|
139
142
|
for (; i < len; i++) {
|
|
@@ -200,7 +203,7 @@ function createStore(store, options) {
|
|
|
200
203
|
}
|
|
201
204
|
function setStore(...args) {
|
|
202
205
|
solidJs.batch(() => {
|
|
203
|
-
isArray && args.length === 1 ? updateArray(unwrappedStore,
|
|
206
|
+
isArray && args.length === 1 ? updateArray(unwrappedStore, args[0]) : updatePath(unwrappedStore, args);
|
|
204
207
|
});
|
|
205
208
|
}
|
|
206
209
|
return [wrappedStore, setStore];
|
|
@@ -216,8 +219,8 @@ const proxyTraps = {
|
|
|
216
219
|
if (solidJs.getListener() && (typeof value !== "function" || target.hasOwnProperty(property))) {
|
|
217
220
|
const nodes = getDataNodes(target);
|
|
218
221
|
(nodes[property] || (nodes[property] = createDataNode()))();
|
|
219
|
-
} else if (value != null && value === Array.prototype[property]) {
|
|
220
|
-
return (...args) => solidJs.batch(() => Array.prototype[property].apply(
|
|
222
|
+
} else if (value != null && typeof value === "function" && value === Array.prototype[property]) {
|
|
223
|
+
return (...args) => solidJs.batch(() => Array.prototype[property].apply(receiver, args));
|
|
221
224
|
}
|
|
222
225
|
return isWrappable(value) ? wrap(value, target[$NAME] && `${target[$NAME]}:${property.toString()}`) : value;
|
|
223
226
|
},
|
|
@@ -274,6 +277,9 @@ function createMutable(state, options) {
|
|
|
274
277
|
}
|
|
275
278
|
return wrappedStore;
|
|
276
279
|
}
|
|
280
|
+
function modifyMutable(state, modifier) {
|
|
281
|
+
solidJs.batch(() => modifier(unwrap(state)));
|
|
282
|
+
}
|
|
277
283
|
|
|
278
284
|
function applyState(target, parent, property, merge, key) {
|
|
279
285
|
const previous = parent[property];
|
|
@@ -378,10 +384,36 @@ function produce(fn) {
|
|
|
378
384
|
return state;
|
|
379
385
|
};
|
|
380
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
|
+
}
|
|
381
411
|
|
|
382
412
|
exports.$RAW = $RAW;
|
|
383
413
|
exports.createMutable = createMutable;
|
|
384
414
|
exports.createStore = createStore;
|
|
415
|
+
exports.modifyMutable = modifyMutable;
|
|
385
416
|
exports.produce = produce;
|
|
386
417
|
exports.reconcile = reconcile;
|
|
418
|
+
exports.splice = splice;
|
|
387
419
|
exports.unwrap = unwrap;
|
package/store/dist/dev.js
CHANGED
|
@@ -130,6 +130,9 @@ function mergeStoreNode(state, value) {
|
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
function updateArray(current, next) {
|
|
133
|
+
if (typeof next === "function") next = next(current);
|
|
134
|
+
next = unwrap(next);
|
|
135
|
+
if (current === next) return;
|
|
133
136
|
let i = 0,
|
|
134
137
|
len = next.length;
|
|
135
138
|
for (; i < len; i++) {
|
|
@@ -196,7 +199,7 @@ function createStore(store, options) {
|
|
|
196
199
|
}
|
|
197
200
|
function setStore(...args) {
|
|
198
201
|
batch(() => {
|
|
199
|
-
isArray && args.length === 1 ? updateArray(unwrappedStore,
|
|
202
|
+
isArray && args.length === 1 ? updateArray(unwrappedStore, args[0]) : updatePath(unwrappedStore, args);
|
|
200
203
|
});
|
|
201
204
|
}
|
|
202
205
|
return [wrappedStore, setStore];
|
|
@@ -212,8 +215,8 @@ const proxyTraps = {
|
|
|
212
215
|
if (getListener() && (typeof value !== "function" || target.hasOwnProperty(property))) {
|
|
213
216
|
const nodes = getDataNodes(target);
|
|
214
217
|
(nodes[property] || (nodes[property] = createDataNode()))();
|
|
215
|
-
} else if (value != null && value === Array.prototype[property]) {
|
|
216
|
-
return (...args) => batch(() => Array.prototype[property].apply(
|
|
218
|
+
} else if (value != null && typeof value === "function" && value === Array.prototype[property]) {
|
|
219
|
+
return (...args) => batch(() => Array.prototype[property].apply(receiver, args));
|
|
217
220
|
}
|
|
218
221
|
return isWrappable(value) ? wrap(value, target[$NAME] && `${target[$NAME]}:${property.toString()}`) : value;
|
|
219
222
|
},
|
|
@@ -270,6 +273,9 @@ function createMutable(state, options) {
|
|
|
270
273
|
}
|
|
271
274
|
return wrappedStore;
|
|
272
275
|
}
|
|
276
|
+
function modifyMutable(state, modifier) {
|
|
277
|
+
batch(() => modifier(unwrap(state)));
|
|
278
|
+
}
|
|
273
279
|
|
|
274
280
|
function applyState(target, parent, property, merge, key) {
|
|
275
281
|
const previous = parent[property];
|
|
@@ -374,5 +380,29 @@ function produce(fn) {
|
|
|
374
380
|
return state;
|
|
375
381
|
};
|
|
376
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
|
+
}
|
|
377
407
|
|
|
378
|
-
export { $RAW, createMutable, createStore, produce, reconcile, unwrap };
|
|
408
|
+
export { $RAW, createMutable, createStore, modifyMutable, produce, reconcile, splice, unwrap };
|
package/store/dist/store.cjs
CHANGED
|
@@ -129,6 +129,9 @@ function mergeStoreNode(state, value) {
|
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
function updateArray(current, next) {
|
|
132
|
+
if (typeof next === "function") next = next(current);
|
|
133
|
+
next = unwrap(next);
|
|
134
|
+
if (current === next) return;
|
|
132
135
|
let i = 0,
|
|
133
136
|
len = next.length;
|
|
134
137
|
for (; i < len; i++) {
|
|
@@ -188,7 +191,7 @@ function createStore(store, options) {
|
|
|
188
191
|
const wrappedStore = wrap$1(unwrappedStore);
|
|
189
192
|
function setStore(...args) {
|
|
190
193
|
solidJs.batch(() => {
|
|
191
|
-
isArray && args.length === 1 ? updateArray(unwrappedStore,
|
|
194
|
+
isArray && args.length === 1 ? updateArray(unwrappedStore, args[0]) : updatePath(unwrappedStore, args);
|
|
192
195
|
});
|
|
193
196
|
}
|
|
194
197
|
return [wrappedStore, setStore];
|
|
@@ -204,8 +207,8 @@ const proxyTraps = {
|
|
|
204
207
|
if (solidJs.getListener() && (typeof value !== "function" || target.hasOwnProperty(property))) {
|
|
205
208
|
const nodes = getDataNodes(target);
|
|
206
209
|
(nodes[property] || (nodes[property] = createDataNode()))();
|
|
207
|
-
} else if (value != null && value === Array.prototype[property]) {
|
|
208
|
-
return (...args) => solidJs.batch(() => Array.prototype[property].apply(
|
|
210
|
+
} else if (value != null && typeof value === "function" && value === Array.prototype[property]) {
|
|
211
|
+
return (...args) => solidJs.batch(() => Array.prototype[property].apply(receiver, args));
|
|
209
212
|
}
|
|
210
213
|
return isWrappable(value) ? wrap(value) : value;
|
|
211
214
|
},
|
|
@@ -252,6 +255,9 @@ function createMutable(state, options) {
|
|
|
252
255
|
const wrappedStore = wrap(unwrappedStore);
|
|
253
256
|
return wrappedStore;
|
|
254
257
|
}
|
|
258
|
+
function modifyMutable(state, modifier) {
|
|
259
|
+
solidJs.batch(() => modifier(unwrap(state)));
|
|
260
|
+
}
|
|
255
261
|
|
|
256
262
|
function applyState(target, parent, property, merge, key) {
|
|
257
263
|
const previous = parent[property];
|
|
@@ -356,10 +362,36 @@ function produce(fn) {
|
|
|
356
362
|
return state;
|
|
357
363
|
};
|
|
358
364
|
}
|
|
365
|
+
function splice(start, deleteCount = 0, ...items) {
|
|
366
|
+
return state => {
|
|
367
|
+
if (Array.isArray(state)) {
|
|
368
|
+
if (start < 0) start = start + state.length;
|
|
369
|
+
if (deleteCount < 0) deleteCount = 0;
|
|
370
|
+
const stop = start + deleteCount;
|
|
371
|
+
if (deleteCount >= items.length) {
|
|
372
|
+
for (let i = stop; i < state.length; i++) {
|
|
373
|
+
setProperty(state, start + i - stop, state[i]);
|
|
374
|
+
}
|
|
375
|
+
} else {
|
|
376
|
+
const offset = items.length - deleteCount;
|
|
377
|
+
for (let i = state.length - 1; i >= stop; i--) {
|
|
378
|
+
setProperty(state, i + offset, state[i]);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
for (let i = 0; i < items.length; i++) {
|
|
382
|
+
setProperty(state, start + i, items[i]);
|
|
383
|
+
}
|
|
384
|
+
setProperty(state, "length", state.length + items.length - deleteCount);
|
|
385
|
+
}
|
|
386
|
+
return state;
|
|
387
|
+
};
|
|
388
|
+
}
|
|
359
389
|
|
|
360
390
|
exports.$RAW = $RAW;
|
|
361
391
|
exports.createMutable = createMutable;
|
|
362
392
|
exports.createStore = createStore;
|
|
393
|
+
exports.modifyMutable = modifyMutable;
|
|
363
394
|
exports.produce = produce;
|
|
364
395
|
exports.reconcile = reconcile;
|
|
396
|
+
exports.splice = splice;
|
|
365
397
|
exports.unwrap = unwrap;
|
package/store/dist/store.js
CHANGED
|
@@ -125,6 +125,9 @@ function mergeStoreNode(state, value) {
|
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
127
|
function updateArray(current, next) {
|
|
128
|
+
if (typeof next === "function") next = next(current);
|
|
129
|
+
next = unwrap(next);
|
|
130
|
+
if (current === next) return;
|
|
128
131
|
let i = 0,
|
|
129
132
|
len = next.length;
|
|
130
133
|
for (; i < len; i++) {
|
|
@@ -184,7 +187,7 @@ function createStore(store, options) {
|
|
|
184
187
|
const wrappedStore = wrap$1(unwrappedStore);
|
|
185
188
|
function setStore(...args) {
|
|
186
189
|
batch(() => {
|
|
187
|
-
isArray && args.length === 1 ? updateArray(unwrappedStore,
|
|
190
|
+
isArray && args.length === 1 ? updateArray(unwrappedStore, args[0]) : updatePath(unwrappedStore, args);
|
|
188
191
|
});
|
|
189
192
|
}
|
|
190
193
|
return [wrappedStore, setStore];
|
|
@@ -200,8 +203,8 @@ const proxyTraps = {
|
|
|
200
203
|
if (getListener() && (typeof value !== "function" || target.hasOwnProperty(property))) {
|
|
201
204
|
const nodes = getDataNodes(target);
|
|
202
205
|
(nodes[property] || (nodes[property] = createDataNode()))();
|
|
203
|
-
} else if (value != null && value === Array.prototype[property]) {
|
|
204
|
-
return (...args) => batch(() => Array.prototype[property].apply(
|
|
206
|
+
} else if (value != null && typeof value === "function" && value === Array.prototype[property]) {
|
|
207
|
+
return (...args) => batch(() => Array.prototype[property].apply(receiver, args));
|
|
205
208
|
}
|
|
206
209
|
return isWrappable(value) ? wrap(value) : value;
|
|
207
210
|
},
|
|
@@ -248,6 +251,9 @@ function createMutable(state, options) {
|
|
|
248
251
|
const wrappedStore = wrap(unwrappedStore);
|
|
249
252
|
return wrappedStore;
|
|
250
253
|
}
|
|
254
|
+
function modifyMutable(state, modifier) {
|
|
255
|
+
batch(() => modifier(unwrap(state)));
|
|
256
|
+
}
|
|
251
257
|
|
|
252
258
|
function applyState(target, parent, property, merge, key) {
|
|
253
259
|
const previous = parent[property];
|
|
@@ -352,5 +358,29 @@ function produce(fn) {
|
|
|
352
358
|
return state;
|
|
353
359
|
};
|
|
354
360
|
}
|
|
361
|
+
function splice(start, deleteCount = 0, ...items) {
|
|
362
|
+
return state => {
|
|
363
|
+
if (Array.isArray(state)) {
|
|
364
|
+
if (start < 0) start = start + state.length;
|
|
365
|
+
if (deleteCount < 0) deleteCount = 0;
|
|
366
|
+
const stop = start + deleteCount;
|
|
367
|
+
if (deleteCount >= items.length) {
|
|
368
|
+
for (let i = stop; i < state.length; i++) {
|
|
369
|
+
setProperty(state, start + i - stop, state[i]);
|
|
370
|
+
}
|
|
371
|
+
} else {
|
|
372
|
+
const offset = items.length - deleteCount;
|
|
373
|
+
for (let i = state.length - 1; i >= stop; i--) {
|
|
374
|
+
setProperty(state, i + offset, state[i]);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
for (let i = 0; i < items.length; i++) {
|
|
378
|
+
setProperty(state, start + i, items[i]);
|
|
379
|
+
}
|
|
380
|
+
setProperty(state, "length", state.length + items.length - deleteCount);
|
|
381
|
+
}
|
|
382
|
+
return state;
|
|
383
|
+
};
|
|
384
|
+
}
|
|
355
385
|
|
|
356
|
-
export { $RAW, createMutable, createStore, produce, reconcile, unwrap };
|
|
386
|
+
export { $RAW, createMutable, createStore, modifyMutable, produce, reconcile, splice, unwrap };
|
|
@@ -5,3 +5,4 @@ export declare type ReconcileOptions = {
|
|
|
5
5
|
};
|
|
6
6
|
export declare function reconcile<T extends U, U>(value: T, options?: ReconcileOptions): (state: U) => T;
|
|
7
7
|
export declare function produce<T>(fn: (state: DeepMutable<T>) => void): (state: T) => T;
|
|
8
|
+
export declare function splice<T extends U, U>(start: number, deleteCount?: number, ...items: T[]): (state: readonly U[]) => T[];
|
package/store/types/mutable.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { requestCallback } from "./scheduler";
|
|
2
2
|
import type { JSX } from "../jsx";
|
|
3
|
+
import type { FlowComponent } from "../render";
|
|
3
4
|
export declare const equalFn: <T>(a: T, b: T) => boolean;
|
|
4
5
|
export declare const $PROXY: unique symbol;
|
|
5
6
|
export declare const $TRACK: unique symbol;
|
|
@@ -123,8 +124,8 @@ export declare type EffectFunction<Prev, Next extends Prev = Prev> = (v: Prev) =
|
|
|
123
124
|
*
|
|
124
125
|
* @description https://www.solidjs.com/docs/latest/api#createcomputed
|
|
125
126
|
*/
|
|
127
|
+
export declare function createComputed<Next>(fn: EffectFunction<undefined | NoInfer<Next>, Next>): void;
|
|
126
128
|
export declare function createComputed<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void;
|
|
127
|
-
export declare function createComputed<Next, Init = undefined>(..._: undefined extends Init ? [fn: EffectFunction<Init | Next, Next>, value?: Init, options?: EffectOptions] : [fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions]): void;
|
|
128
129
|
/**
|
|
129
130
|
* Creates a reactive computation that runs during the render phase as DOM elements are created and updated but not necessarily connected
|
|
130
131
|
* ```typescript
|
|
@@ -140,8 +141,8 @@ export declare function createComputed<Next, Init = undefined>(..._: undefined e
|
|
|
140
141
|
*
|
|
141
142
|
* @description https://www.solidjs.com/docs/latest/api#createrendereffect
|
|
142
143
|
*/
|
|
144
|
+
export declare function createRenderEffect<Next>(fn: EffectFunction<undefined | NoInfer<Next>, Next>): void;
|
|
143
145
|
export declare function createRenderEffect<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void;
|
|
144
|
-
export declare function createRenderEffect<Next, Init = undefined>(..._: undefined extends Init ? [fn: EffectFunction<Init | Next, Next>, value?: Init, options?: EffectOptions] : [fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions]): void;
|
|
145
146
|
/**
|
|
146
147
|
* Creates a reactive computation that runs after the render phase
|
|
147
148
|
* ```typescript
|
|
@@ -157,8 +158,8 @@ export declare function createRenderEffect<Next, Init = undefined>(..._: undefin
|
|
|
157
158
|
*
|
|
158
159
|
* @description https://www.solidjs.com/docs/latest/api#createeffect
|
|
159
160
|
*/
|
|
161
|
+
export declare function createEffect<Next>(fn: EffectFunction<undefined | NoInfer<Next>, Next>): void;
|
|
160
162
|
export declare function createEffect<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void;
|
|
161
|
-
export declare function createEffect<Next, Init = undefined>(..._: undefined extends Init ? [fn: EffectFunction<Init | Next, Next>, value?: Init, options?: EffectOptions] : [fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions]): void;
|
|
162
163
|
/**
|
|
163
164
|
* Creates a reactive computation that runs after the render phase with flexible tracking
|
|
164
165
|
* ```typescript
|
|
@@ -194,8 +195,8 @@ export interface MemoOptions<T> extends EffectOptions {
|
|
|
194
195
|
*
|
|
195
196
|
* @description https://www.solidjs.com/docs/latest/api#creatememo
|
|
196
197
|
*/
|
|
197
|
-
export declare function createMemo<Next extends
|
|
198
|
-
export declare function createMemo<Next extends
|
|
198
|
+
export declare function createMemo<Next extends Prev, Prev = Next>(fn: EffectFunction<undefined | NoInfer<Prev>, Next>): Accessor<Next>;
|
|
199
|
+
export declare function createMemo<Next extends Prev, Init = Next, Prev = Next>(fn: EffectFunction<Init | Prev, Next>, value: Init, options?: MemoOptions<Next>): Accessor<Next>;
|
|
199
200
|
export interface Resource<T> extends Accessor<T> {
|
|
200
201
|
loading: boolean;
|
|
201
202
|
error: any;
|
|
@@ -401,10 +402,9 @@ interface GraphRecord {
|
|
|
401
402
|
[k: string]: GraphRecord | unknown;
|
|
402
403
|
}
|
|
403
404
|
export declare function serializeGraph(owner?: Owner | null): GraphRecord;
|
|
404
|
-
export declare type ContextProviderComponent<T> =
|
|
405
|
+
export declare type ContextProviderComponent<T> = FlowComponent<{
|
|
405
406
|
value: T;
|
|
406
|
-
|
|
407
|
-
}) => any;
|
|
407
|
+
}>;
|
|
408
408
|
export interface Context<T> {
|
|
409
409
|
id: symbol;
|
|
410
410
|
Provider: ContextProviderComponent<T>;
|
|
@@ -415,7 +415,7 @@ export interface Context<T> {
|
|
|
415
415
|
* ```typescript
|
|
416
416
|
* interface Context<T> {
|
|
417
417
|
* id: symbol;
|
|
418
|
-
* Provider:
|
|
418
|
+
* Provider: FlowComponent<{ value: T }>;
|
|
419
419
|
* defaultValue: T;
|
|
420
420
|
* }
|
|
421
421
|
* export function createContext<T>(defaultValue?: T): Context<T | undefined>;
|
|
@@ -1,9 +1,56 @@
|
|
|
1
1
|
import type { JSX } from "../jsx";
|
|
2
2
|
export declare function enableHydration(): void;
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* A general `Component` has no implicit `children` prop. If desired, you can
|
|
5
|
+
* specify one as in `Component<{name: String, children: JSX.Element>}`.
|
|
6
|
+
*/
|
|
7
|
+
export declare type Component<P = {}> = (props: P) => JSX.Element;
|
|
8
|
+
/**
|
|
9
|
+
* Extend props to forbid the `children` prop.
|
|
10
|
+
* Use this to prevent accidentally passing `children` to components that
|
|
11
|
+
* would silently throw them away.
|
|
12
|
+
*/
|
|
13
|
+
export declare type VoidProps<P = {}> = P & {
|
|
14
|
+
children?: never;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* `VoidComponent` forbids the `children` prop.
|
|
18
|
+
* Use this to prevent accidentally passing `children` to components that
|
|
19
|
+
* would silently throw them away.
|
|
20
|
+
*/
|
|
21
|
+
export declare type VoidComponent<P = {}> = Component<VoidProps<P>>;
|
|
22
|
+
/**
|
|
23
|
+
* Extend props to allow an optional `children` prop with the usual
|
|
24
|
+
* type in JSX, `JSX.Element` (which allows elements, arrays, functions, etc.).
|
|
25
|
+
* Use this for components that you want to accept children.
|
|
26
|
+
*/
|
|
27
|
+
export declare type ParentProps<P = {}> = P & {
|
|
4
28
|
children?: JSX.Element;
|
|
5
29
|
};
|
|
6
|
-
|
|
30
|
+
/**
|
|
31
|
+
* `ParentComponent` allows an optional `children` prop with the usual
|
|
32
|
+
* type in JSX, `JSX.Element` (which allows elements, arrays, functions, etc.).
|
|
33
|
+
* Use this for components that you want to accept children.
|
|
34
|
+
*/
|
|
35
|
+
export declare type ParentComponent<P = {}> = Component<ParentProps<P>>;
|
|
36
|
+
/**
|
|
37
|
+
* Extend props to require a `children` prop with the specified type.
|
|
38
|
+
* Use this for components where you need a specific child type,
|
|
39
|
+
* typically a function that receives specific argument types.
|
|
40
|
+
* Note that all JSX <Elements> are of the type `JSX.Element`.
|
|
41
|
+
*/
|
|
42
|
+
export declare type FlowProps<P = {}, C = JSX.Element> = P & {
|
|
43
|
+
children: C;
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* `FlowComponent` requires a `children` prop with the specified type.
|
|
47
|
+
* Use this for components where you need a specific child type,
|
|
48
|
+
* typically a function that receives specific argument types.
|
|
49
|
+
* Note that all JSX <Elements> are of the type `JSX.Element`.
|
|
50
|
+
*/
|
|
51
|
+
export declare type FlowComponent<P = {}, C = JSX.Element> = Component<FlowProps<P, C>>;
|
|
52
|
+
/** @deprecated: use `ParentProps` instead */
|
|
53
|
+
export declare type PropsWithChildren<P = {}> = ParentProps<P>;
|
|
7
54
|
/**
|
|
8
55
|
* Takes the props of the passed component and returns its type
|
|
9
56
|
*
|
|
@@ -12,7 +59,13 @@ export declare type Component<P = {}> = (props: PropsWithChildren<P>) => JSX.Ele
|
|
|
12
59
|
* ComponentProps<'div'> // JSX.HTMLAttributes<HTMLDivElement>
|
|
13
60
|
*/
|
|
14
61
|
export declare type ComponentProps<T extends keyof JSX.IntrinsicElements | Component<any>> = T extends Component<infer P> ? P : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : {};
|
|
15
|
-
|
|
62
|
+
/**
|
|
63
|
+
* Type of `props.ref`, for use in `Component` or `props` typing.
|
|
64
|
+
*
|
|
65
|
+
* @example Component<{ref: Ref<Element>}>
|
|
66
|
+
*/
|
|
67
|
+
export declare type Ref<T> = T | ((val: T) => void);
|
|
68
|
+
export declare function createComponent<T>(Comp: Component<T>, props: T): JSX.Element;
|
|
16
69
|
declare type UnboxLazy<T> = T extends () => infer U ? U : T;
|
|
17
70
|
declare type BoxedTupleTypes<T extends any[]> = {
|
|
18
71
|
[P in keyof T]: [UnboxLazy<T[P]>];
|
|
@@ -42,7 +42,7 @@ export declare function createContext<T>(defaultValue?: T): Context<T>;
|
|
|
42
42
|
export declare function useContext<T>(context: Context<T>): T;
|
|
43
43
|
export declare function getOwner(): Owner | null;
|
|
44
44
|
export declare function children(fn: () => any): () => unknown;
|
|
45
|
-
export declare function runWithOwner(o: Owner, fn: () =>
|
|
45
|
+
export declare function runWithOwner<T>(o: Owner, fn: () => T): T;
|
|
46
46
|
export declare function lookup(owner: Owner | null, key: symbol | string): any;
|
|
47
47
|
export interface Task {
|
|
48
48
|
id: number;
|
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
import { Setter } from "./reactive";
|
|
2
2
|
import type { JSX } from "../jsx";
|
|
3
|
-
declare type
|
|
3
|
+
export declare type Component<P = {}> = (props: P) => JSX.Element;
|
|
4
|
+
export declare type VoidProps<P = {}> = P & {
|
|
5
|
+
children?: never;
|
|
6
|
+
};
|
|
7
|
+
export declare type VoidComponent<P = {}> = Component<VoidProps<P>>;
|
|
8
|
+
export declare type ParentProps<P = {}> = P & {
|
|
4
9
|
children?: JSX.Element;
|
|
5
10
|
};
|
|
6
|
-
export declare type
|
|
7
|
-
declare type
|
|
8
|
-
|
|
11
|
+
export declare type ParentComponent<P = {}> = Component<ParentProps<P>>;
|
|
12
|
+
export declare type FlowProps<P = {}, C = JSX.Element> = P & {
|
|
13
|
+
children: C;
|
|
9
14
|
};
|
|
15
|
+
export declare type FlowComponent<P = {}, C = JSX.Element> = Component<FlowProps<P, C>>;
|
|
16
|
+
export declare type Ref<T> = T | ((val: T) => void);
|
|
17
|
+
export declare type ComponentProps<T extends keyof JSX.IntrinsicElements | Component> = T extends Component<infer P> ? P : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : {};
|
|
10
18
|
declare type SharedConfig = {
|
|
11
19
|
context?: HydrationContext;
|
|
12
20
|
};
|
|
13
21
|
export declare const sharedConfig: SharedConfig;
|
|
14
22
|
export declare function createUniqueId(): string;
|
|
15
|
-
export declare function createComponent<T>(Comp: (props: T) => JSX.Element, props:
|
|
23
|
+
export declare function createComponent<T>(Comp: (props: T) => JSX.Element, props: T): JSX.Element;
|
|
16
24
|
export declare function mergeProps<T, U>(source: T, source1: U): T & U;
|
|
17
25
|
export declare function mergeProps<T, U, V>(source: T, source1: U, source2: V): T & U & V;
|
|
18
26
|
export declare function mergeProps<T, U, V, W>(source: T, source1: U, source2: V, source3: W): T & U & V & W;
|
|
@@ -94,9 +102,13 @@ export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S,
|
|
|
94
102
|
export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>;
|
|
95
103
|
export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>;
|
|
96
104
|
export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>;
|
|
97
|
-
export declare function lazy(fn: () => Promise<{
|
|
98
|
-
default:
|
|
99
|
-
}>):
|
|
105
|
+
export declare function lazy<T extends Component<any>>(fn: () => Promise<{
|
|
106
|
+
default: T;
|
|
107
|
+
}>): T & {
|
|
108
|
+
preload: () => Promise<{
|
|
109
|
+
default: T;
|
|
110
|
+
}>;
|
|
111
|
+
};
|
|
100
112
|
export declare function enableScheduling(): void;
|
|
101
113
|
export declare function enableHydration(): void;
|
|
102
114
|
export declare function startTransition(fn: () => any): void;
|
|
@@ -120,5 +132,7 @@ export declare function SuspenseList(props: {
|
|
|
120
132
|
export declare function Suspense(props: {
|
|
121
133
|
fallback?: string;
|
|
122
134
|
children: string;
|
|
123
|
-
}):
|
|
135
|
+
}): string | number | boolean | Node | JSX.ArrayElement | JSX.FunctionElement | {
|
|
136
|
+
t: string;
|
|
137
|
+
} | null | undefined;
|
|
124
138
|
export {};
|