solid-js 1.2.5 → 1.3.0-beta.10

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/solid.js CHANGED
@@ -145,6 +145,7 @@ const [transPending, setTransPending] = /*@__PURE__*/createSignal(false);
145
145
  var Owner = null;
146
146
  let Transition = null;
147
147
  let Scheduler = null;
148
+ let ExternalSourceFactory = null;
148
149
  let Listener = null;
149
150
  let Pending = null;
150
151
  let Updates = null;
@@ -180,12 +181,13 @@ function createSignal(value, options) {
180
181
  pending: NOTPENDING,
181
182
  comparator: options.equals || undefined
182
183
  };
183
- return [readSignal.bind(s), value => {
184
+ const setter = value => {
184
185
  if (typeof value === "function") {
185
186
  if (Transition && Transition.running && Transition.sources.has(s)) value = value(s.pending !== NOTPENDING ? s.pending : s.tValue);else value = value(s.pending !== NOTPENDING ? s.pending : s.value);
186
187
  }
187
188
  return writeSignal(s, value);
188
- }];
189
+ };
190
+ return [readSignal.bind(s), setter];
189
191
  }
190
192
  function createComputed(fn, value, options) {
191
193
  const c = createComputation(fn, value, true, STALE);
@@ -227,6 +229,9 @@ function createResource(source, fetcher, options) {
227
229
  fetcher = source;
228
230
  source = true;
229
231
  }
232
+ Resources || (Resources = new Set());
233
+ Resources.add(load);
234
+ onCleanup(() => Resources.delete(load));
230
235
  const contexts = new Set(),
231
236
  [s, set] = createSignal((options || {}).initialValue),
232
237
  [track, trigger] = createSignal(undefined, {
@@ -242,12 +247,7 @@ function createResource(source, fetcher, options) {
242
247
  dynamic = typeof source === "function";
243
248
  if (sharedConfig.context) {
244
249
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
245
- if (sharedConfig.context.loadResource) {
246
- initP = sharedConfig.context.loadResource(id);
247
- } else if (sharedConfig.resources && id && id in sharedConfig.resources) {
248
- initP = sharedConfig.resources[id];
249
- delete sharedConfig.resources[id];
250
- }
250
+ if (sharedConfig.load) initP = sharedConfig.load(id);
251
251
  }
252
252
  function loadEnd(p, v, e) {
253
253
  if (pr === p) {
@@ -293,7 +293,7 @@ function createResource(source, fetcher, options) {
293
293
  }
294
294
  return v;
295
295
  }
296
- function load() {
296
+ function load(refetching = true) {
297
297
  setError(err = undefined);
298
298
  const lookup = dynamic ? source() : source;
299
299
  loadedUnderTransition = Transition && Transition.running;
@@ -302,7 +302,10 @@ function createResource(source, fetcher, options) {
302
302
  return;
303
303
  }
304
304
  if (Transition && pr) Transition.promises.delete(pr);
305
- const p = initP || untrack(() => fetcher(lookup, s));
305
+ const p = initP || untrack(() => fetcher(lookup, {
306
+ value: s(),
307
+ refetching
308
+ }));
306
309
  initP = null;
307
310
  if (typeof p !== "object" || !("then" in p)) {
308
311
  loadEnd(pr, p);
@@ -327,12 +330,16 @@ function createResource(source, fetcher, options) {
327
330
  }
328
331
  }
329
332
  });
330
- if (dynamic) createComputed(load);else load();
333
+ if (dynamic) createComputed(() => load(false));else load(false);
331
334
  return [read, {
332
335
  refetch: load,
333
336
  mutate: set
334
337
  }];
335
338
  }
339
+ let Resources;
340
+ function refetchResources(info) {
341
+ Resources && Resources.forEach(fn => fn(info));
342
+ }
336
343
  function createDeferred(source, options) {
337
344
  let t,
338
345
  timeout = options ? options.timeoutMs : undefined;
@@ -351,7 +358,7 @@ function createSelector(source, fn = equalFn, options) {
351
358
  const subs = new Map();
352
359
  const node = createComputation(p => {
353
360
  const v = source();
354
- for (const key of subs.keys()) if (fn(key, v) || p !== undefined && fn(key, p)) {
361
+ for (const key of subs.keys()) if (fn(key, v) !== (p !== undefined && fn(key, p))) {
355
362
  const l = subs.get(key);
356
363
  for (const c of l.values()) {
357
364
  c.state = STALE;
@@ -402,7 +409,8 @@ function untrack(fn) {
402
409
  Listener = listener;
403
410
  return result;
404
411
  }
405
- function on(deps, fn, options) {
412
+ function on(deps, fn,
413
+ options) {
406
414
  const isArray = Array.isArray(deps);
407
415
  let prevInput;
408
416
  let defer = options && options.defer;
@@ -502,6 +510,24 @@ let SuspenseContext;
502
510
  function getSuspenseContext() {
503
511
  return SuspenseContext || (SuspenseContext = createContext({}));
504
512
  }
513
+ function enableExternalSource(factory) {
514
+ if (ExternalSourceFactory) {
515
+ const oldFactory = ExternalSourceFactory;
516
+ ExternalSourceFactory = (fn, trigger) => {
517
+ const oldSource = oldFactory(fn, trigger);
518
+ const source = factory(x => oldSource.track(x), trigger);
519
+ return {
520
+ track: x => source.track(x),
521
+ dispose() {
522
+ source.dispose();
523
+ oldSource.dispose();
524
+ }
525
+ };
526
+ };
527
+ } else {
528
+ ExternalSourceFactory = factory;
529
+ }
530
+ }
505
531
  function readSignal() {
506
532
  const runningTransition = Transition && Transition.running;
507
533
  if (this.sources && (!runningTransition && this.state || runningTransition && this.tState)) {
@@ -629,6 +655,19 @@ function createComputation(fn, init, pure, state = STALE, options) {
629
655
  if (!Owner.owned) Owner.owned = [c];else Owner.owned.push(c);
630
656
  }
631
657
  }
658
+ if (ExternalSourceFactory) {
659
+ const [track, trigger] = createSignal(undefined, {
660
+ equals: false
661
+ });
662
+ const ordinary = ExternalSourceFactory(c.fn, trigger);
663
+ onCleanup(() => ordinary.dispose());
664
+ const triggerInTransition = () => startTransition(trigger, () => inTransition.dispose());
665
+ const inTransition = ExternalSourceFactory(c.fn, triggerInTransition);
666
+ c.fn = x => {
667
+ track();
668
+ return Transition && Transition.running ? inTransition.track(x) : ordinary.track(x);
669
+ };
670
+ }
632
671
  return c;
633
672
  }
634
673
  function runTop(node) {
@@ -655,7 +694,7 @@ function runTop(node) {
655
694
  } else if (!runningTransition && node.state === PENDING || runningTransition && node.tState === PENDING) {
656
695
  const updates = Updates;
657
696
  Updates = null;
658
- lookDownstream(node);
697
+ lookDownstream(node, ancestors[0]);
659
698
  Updates = updates;
660
699
  }
661
700
  }
@@ -753,13 +792,15 @@ function runUserEffects(queue) {
753
792
  for (i = 0; i < userLength; i++) runTop(queue[i]);
754
793
  for (i = resume; i < queue.length; i++) runTop(queue[i]);
755
794
  }
756
- function lookDownstream(node) {
795
+ function lookDownstream(node, ignore) {
757
796
  node.state = 0;
758
797
  const runningTransition = Transition && Transition.running;
759
798
  for (let i = 0; i < node.sources.length; i += 1) {
760
799
  const source = node.sources[i];
761
800
  if (source.sources) {
762
- if (!runningTransition && source.state === STALE || runningTransition && source.tState === STALE) runTop(source);else if (!runningTransition && source.state === PENDING || runningTransition && source.tState === PENDING) lookDownstream(source);
801
+ if (!runningTransition && source.state === STALE || runningTransition && source.tState === STALE) {
802
+ if (source !== ignore) runTop(source);
803
+ } else if (!runningTransition && source.state === PENDING || runningTransition && source.tState === PENDING) lookDownstream(source, ignore);
763
804
  }
764
805
  }
765
806
  }
@@ -1060,13 +1101,19 @@ function indexArray(list, mapFn, options = {}) {
1060
1101
  };
1061
1102
  }
1062
1103
 
1104
+ let hydrationEnabled = false;
1105
+ function enableHydration() {
1106
+ hydrationEnabled = true;
1107
+ }
1063
1108
  function createComponent(Comp, props) {
1064
- if (sharedConfig.context) {
1065
- const c = sharedConfig.context;
1066
- setHydrateContext(nextHydrateContext());
1067
- const r = untrack(() => Comp(props));
1068
- setHydrateContext(c);
1069
- return r;
1109
+ if (hydrationEnabled) {
1110
+ if (sharedConfig.context) {
1111
+ const c = sharedConfig.context;
1112
+ setHydrateContext(nextHydrateContext());
1113
+ const r = untrack(() => Comp(props));
1114
+ setHydrateContext(c);
1115
+ return r;
1116
+ }
1070
1117
  }
1071
1118
  return untrack(() => Comp(props));
1072
1119
  }
@@ -1155,19 +1202,20 @@ function splitProps(props, ...keys) {
1155
1202
  }
1156
1203
  function lazy(fn) {
1157
1204
  let comp;
1205
+ let p;
1158
1206
  const wrap = props => {
1159
1207
  const ctx = sharedConfig.context;
1160
- if (ctx && sharedConfig.resources) {
1208
+ if (ctx) {
1161
1209
  ctx.count++;
1162
1210
  const [s, set] = createSignal();
1163
- fn().then(mod => {
1211
+ (p || (p = fn())).then(mod => {
1164
1212
  setHydrateContext(ctx);
1165
1213
  set(() => mod.default);
1166
- setHydrateContext(undefined);
1214
+ setHydrateContext();
1167
1215
  });
1168
1216
  comp = s;
1169
1217
  } else if (!comp) {
1170
- const [s] = createResource(() => fn().then(mod => mod.default));
1218
+ const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default));
1171
1219
  comp = s;
1172
1220
  } else {
1173
1221
  const c = comp();
@@ -1183,7 +1231,7 @@ function lazy(fn) {
1183
1231
  return r;
1184
1232
  }));
1185
1233
  };
1186
- wrap.preload = () => comp || fn().then(mod => comp = () => mod.default);
1234
+ wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
1187
1235
  return wrap;
1188
1236
  }
1189
1237
  let counter = 0;
@@ -1230,7 +1278,7 @@ function Switch(props) {
1230
1278
  }
1231
1279
  return [-1];
1232
1280
  }, undefined, {
1233
- equals: (a, b) => a && a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
1281
+ equals: (a, b) => a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
1234
1282
  });
1235
1283
  return createMemo(() => {
1236
1284
  const [index, when, cond] = evalConditions();
@@ -1243,7 +1291,11 @@ function Match(props) {
1243
1291
  return props;
1244
1292
  }
1245
1293
  function ErrorBoundary(props) {
1246
- const [errored, setErrored] = createSignal();
1294
+ let err = undefined;
1295
+ if (sharedConfig.context && sharedConfig.load) {
1296
+ err = sharedConfig.load(sharedConfig.context.id + sharedConfig.context.count);
1297
+ }
1298
+ const [errored, setErrored] = createSignal(err);
1247
1299
  let e;
1248
1300
  return createMemo(() => {
1249
1301
  if ((e = errored()) != null) {
@@ -1324,7 +1376,11 @@ function SuspenseList(props) {
1324
1376
  function Suspense(props) {
1325
1377
  let counter = 0,
1326
1378
  showContent,
1327
- showFallback;
1379
+ showFallback,
1380
+ ctx,
1381
+ p,
1382
+ flicker,
1383
+ error;
1328
1384
  const [inFallback, setFallback] = createSignal(false),
1329
1385
  SuspenseContext = getSuspenseContext(),
1330
1386
  store = {
@@ -1339,6 +1395,24 @@ function Suspense(props) {
1339
1395
  resolved: false
1340
1396
  },
1341
1397
  owner = getOwner();
1398
+ if (sharedConfig.context) {
1399
+ const key = sharedConfig.context.id + sharedConfig.context.count;
1400
+ p = sharedConfig.load(key);
1401
+ if (p && typeof p === "object") {
1402
+ const [s, set] = createSignal(undefined, {
1403
+ equals: false
1404
+ });
1405
+ flicker = s;
1406
+ p.then(err => {
1407
+ if (error = err) return set();
1408
+ sharedConfig.gather(key);
1409
+ setHydrateContext(ctx);
1410
+ set();
1411
+ setHydrateContext();
1412
+ p = undefined;
1413
+ });
1414
+ }
1415
+ }
1342
1416
  const listContext = useContext(SuspenseListContext);
1343
1417
  if (listContext) [showContent, showFallback] = listContext.register(store.inFallback);
1344
1418
  let dispose;
@@ -1346,28 +1420,43 @@ function Suspense(props) {
1346
1420
  return createComponent(SuspenseContext.Provider, {
1347
1421
  value: store,
1348
1422
  get children() {
1349
- const rendered = untrack(() => props.children);
1350
1423
  return createMemo(() => {
1351
- const inFallback = store.inFallback(),
1352
- visibleContent = showContent ? showContent() : true,
1353
- visibleFallback = showFallback ? showFallback() : true;
1354
- dispose && dispose();
1355
- if (!inFallback && visibleContent) {
1356
- store.resolved = true;
1357
- resumeEffects(store.effects);
1358
- return rendered;
1424
+ if (error) throw error;
1425
+ ctx = sharedConfig.context;
1426
+ if (flicker) {
1427
+ flicker();
1428
+ return flicker = undefined;
1359
1429
  }
1360
- if (!visibleFallback) return;
1361
- return createRoot(disposer => {
1362
- dispose = disposer;
1363
- return props.fallback;
1364
- }, owner);
1430
+ if (ctx && p === undefined) setHydrateContext();
1431
+ const rendered = untrack(() => props.children);
1432
+ return createMemo(() => {
1433
+ const inFallback = store.inFallback(),
1434
+ visibleContent = showContent ? showContent() : true,
1435
+ visibleFallback = showFallback ? showFallback() : true;
1436
+ dispose && dispose();
1437
+ if ((!inFallback || p !== undefined) && visibleContent) {
1438
+ store.resolved = true;
1439
+ resumeEffects(store.effects);
1440
+ return rendered;
1441
+ }
1442
+ if (!visibleFallback) return;
1443
+ return createRoot(disposer => {
1444
+ dispose = disposer;
1445
+ if (ctx) {
1446
+ setHydrateContext({
1447
+ id: ctx.id + "f",
1448
+ count: 0
1449
+ });
1450
+ ctx = undefined;
1451
+ }
1452
+ return props.fallback;
1453
+ }, owner);
1454
+ });
1365
1455
  });
1366
1456
  }
1367
1457
  });
1368
1458
  }
1369
1459
 
1370
- function awaitSuspense() {}
1371
1460
  let DEV;
1372
1461
 
1373
- export { $PROXY, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, awaitSuspense, batch, cancelCallback, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
1462
+ export { $PROXY, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, cancelCallback, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, refetchResources, requestCallback, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "solid-js",
3
3
  "description": "A declarative JavaScript library for building user interfaces.",
4
- "version": "1.2.5",
4
+ "version": "1.3.0-beta.10",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
- "homepage": "https://github.com/solidjs/solid#readme",
7
+ "homepage": "https://solidjs.com",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/solidjs/solid"
@@ -36,11 +36,11 @@
36
36
  ],
37
37
  "exports": {
38
38
  ".": {
39
- "development": {
40
- "import": "./dist/dev.js",
41
- "require": "./dist/dev.cjs"
42
- },
43
39
  "browser": {
40
+ "development": {
41
+ "import": "./dist/dev.js",
42
+ "require": "./dist/dev.cjs"
43
+ },
44
44
  "import": "./dist/solid.js",
45
45
  "require": "./dist/solid.cjs"
46
46
  },
@@ -48,16 +48,20 @@
48
48
  "import": "./dist/server.js",
49
49
  "require": "./dist/server.cjs"
50
50
  },
51
+ "development": {
52
+ "import": "./dist/dev.js",
53
+ "require": "./dist/dev.cjs"
54
+ },
51
55
  "import": "./dist/solid.js",
52
56
  "require": "./dist/solid.cjs"
53
57
  },
54
58
  "./dist/*": "./dist/*",
55
59
  "./store": {
56
- "development": {
57
- "import": "./store/dist/dev.js",
58
- "require": "./store/dist/dev.cjs"
59
- },
60
60
  "browser": {
61
+ "development": {
62
+ "import": "./store/dist/dev.js",
63
+ "require": "./store/dist/dev.cjs"
64
+ },
61
65
  "import": "./store/dist/store.js",
62
66
  "require": "./store/dist/store.cjs"
63
67
  },
@@ -65,16 +69,20 @@
65
69
  "import": "./store/dist/server.js",
66
70
  "require": "./store/dist/server.cjs"
67
71
  },
72
+ "development": {
73
+ "import": "./store/dist/dev.js",
74
+ "require": "./store/dist/dev.cjs"
75
+ },
68
76
  "import": "./store/dist/store.js",
69
77
  "require": "./store/dist/store.cjs"
70
78
  },
71
79
  "./store/dist/*": "./store/dist/*",
72
80
  "./web": {
73
- "development": {
74
- "import": "./web/dist/dev.js",
75
- "require": "./web/dist/dev.cjs"
76
- },
77
81
  "browser": {
82
+ "development": {
83
+ "import": "./web/dist/dev.js",
84
+ "require": "./web/dist/dev.cjs"
85
+ },
78
86
  "import": "./web/dist/web.js",
79
87
  "require": "./web/dist/web.cjs"
80
88
  },
@@ -82,6 +90,10 @@
82
90
  "import": "./web/dist/server.js",
83
91
  "require": "./web/dist/server.cjs"
84
92
  },
93
+ "development": {
94
+ "import": "./web/dist/dev.js",
95
+ "require": "./web/dist/dev.cjs"
96
+ },
85
97
  "import": "./web/dist/web.js",
86
98
  "require": "./web/dist/web.cjs"
87
99
  },
@@ -132,5 +144,5 @@
132
144
  "compiler",
133
145
  "performance"
134
146
  ],
135
- "gitHead": "faf884b19acc078f1e202030bbd6b22c49a5ae6b"
147
+ "gitHead": "58fd1f992d5ce333a8803cc6880cb431155fda5c"
136
148
  }
package/types/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export { createRoot, createSignal, createEffect, createRenderEffect, createComputed, createDeferred, createSelector, createMemo, createResource, onMount, onCleanup, onError, untrack, batch, on, enableScheduling, startTransition, useTransition, createContext, useContext, children, getListener, getOwner, runWithOwner, equalFn, $PROXY } from "./reactive/signal";
2
- export type { Accessor, Setter, Resource, ResourceReturn, Context, ReturnTypes } from "./reactive/signal";
1
+ export { createRoot, createSignal, createEffect, createRenderEffect, createComputed, createDeferred, createSelector, createMemo, createResource, onMount, onCleanup, onError, untrack, batch, on, enableScheduling, enableExternalSource, startTransition, useTransition, refetchResources, createContext, useContext, children, getListener, getOwner, runWithOwner, equalFn, $PROXY } from "./reactive/signal";
2
+ export type { Accessor, Setter, Resource, ResourceReturn, ResourceFetcher, ResourceFetcherInfo, Context, ReturnTypes } from "./reactive/signal";
3
3
  export * from "./reactive/observable";
4
4
  export * from "./reactive/scheduler";
5
5
  export * from "./reactive/array";
@@ -7,7 +7,6 @@ export * from "./render";
7
7
  import type { JSX } from "./jsx";
8
8
  declare type JSXElement = JSX.Element;
9
9
  export type { JSXElement, JSX };
10
- export declare function awaitSuspense(): void;
11
10
  import { writeSignal, serializeGraph, registerGraph, hashValue } from "./reactive/signal";
12
11
  declare let DEV: {
13
12
  writeSignal: typeof writeSignal;