solid-js 1.3.17 → 1.4.0-beta.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 CHANGED
@@ -131,6 +131,7 @@ function nextHydrateContext() {
131
131
 
132
132
  const equalFn = (a, b) => a === b;
133
133
  const $PROXY = Symbol("solid-proxy");
134
+ const $TRACK = Symbol("solid-track");
134
135
  const $DEVCOMP = Symbol("solid-dev-component");
135
136
  const signalOptions = {
136
137
  equals: equalFn
@@ -208,7 +209,7 @@ function createEffect(fn, value, options) {
208
209
  s = SuspenseContext && lookup(Owner, SuspenseContext.id);
209
210
  if (s) c.suspense = s;
210
211
  c.user = true;
211
- Effects ? Effects.push(c) : queueMicrotask(() => updateComputation(c));
212
+ Effects ? Effects.push(c) : updateComputation(c);
212
213
  }
213
214
  function createReaction(onInvalidate, options) {
214
215
  let fn;
@@ -249,13 +250,8 @@ function createResource(source, fetcher, options) {
249
250
  source = true;
250
251
  }
251
252
  options || (options = {});
252
- if (options.globalRefetch !== false) {
253
- Resources || (Resources = new Set());
254
- Resources.add(load);
255
- Owner && onCleanup(() => Resources.delete(load));
256
- }
257
253
  const contexts = new Set(),
258
- [s, set] = createSignal(options.initialValue),
254
+ [value, setValue] = createSignal(options.initialValue),
259
255
  [track, trigger] = createSignal(undefined, {
260
256
  equals: false
261
257
  }),
@@ -267,7 +263,7 @@ function createResource(source, fetcher, options) {
267
263
  id = null,
268
264
  loadedUnderTransition = false,
269
265
  scheduled = false,
270
- dynamic = typeof source === "function";
266
+ dynamic = typeof source === "function" && createMemo(source);
271
267
  if (sharedConfig.context) {
272
268
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
273
269
  if (sharedConfig.load) initP = sharedConfig.load(id);
@@ -297,7 +293,7 @@ function createResource(source, fetcher, options) {
297
293
  }
298
294
  function completeLoad(v) {
299
295
  batch(() => {
300
- set(() => v);
296
+ setValue(() => v);
301
297
  setLoading(false);
302
298
  for (const c of contexts.keys()) c.decrement();
303
299
  contexts.clear();
@@ -305,7 +301,7 @@ function createResource(source, fetcher, options) {
305
301
  }
306
302
  function read() {
307
303
  const c = SuspenseContext && lookup(Owner, SuspenseContext.id),
308
- v = s();
304
+ v = value();
309
305
  if (err) throw err;
310
306
  if (Listener && !Listener.user && c) {
311
307
  createComputed(() => {
@@ -324,15 +320,15 @@ function createResource(source, fetcher, options) {
324
320
  if (refetching && scheduled) return;
325
321
  scheduled = false;
326
322
  setError(err = undefined);
327
- const lookup = dynamic ? source() : source;
323
+ const lookup = dynamic ? dynamic() : source;
328
324
  loadedUnderTransition = Transition && Transition.running;
329
325
  if (lookup == null || lookup === false) {
330
- loadEnd(pr, untrack(s));
326
+ loadEnd(pr, untrack(value));
331
327
  return;
332
328
  }
333
329
  if (Transition && pr) Transition.promises.delete(pr);
334
330
  const p = initP || untrack(() => fetcher(lookup, {
335
- value: s(),
331
+ value: value(),
336
332
  refetching
337
333
  }));
338
334
  if (typeof p !== "object" || !("then" in p)) {
@@ -358,18 +354,20 @@ function createResource(source, fetcher, options) {
358
354
  get() {
359
355
  return error();
360
356
  }
357
+ },
358
+ latest: {
359
+ get() {
360
+ if (err) throw err;
361
+ return value();
362
+ }
361
363
  }
362
364
  });
363
365
  if (dynamic) createComputed(() => load(false));else load(false);
364
366
  return [read, {
365
367
  refetch: load,
366
- mutate: set
368
+ mutate: setValue
367
369
  }];
368
370
  }
369
- let Resources;
370
- function refetchResources(info) {
371
- return Resources && Promise.all([...Resources].map(fn => fn(info)));
372
- }
373
371
  function createDeferred(source, options) {
374
372
  let t,
375
373
  timeout = options ? options.timeoutMs : undefined;
@@ -797,11 +795,14 @@ function runUpdates(fn, init) {
797
795
  if (Effects) wait = true;else Effects = [];
798
796
  ExecCount++;
799
797
  try {
800
- return fn();
798
+ const res = fn();
799
+ completeUpdates(wait);
800
+ return res;
801
801
  } catch (err) {
802
802
  handleError(err);
803
803
  } finally {
804
- completeUpdates(wait);
804
+ Updates = null;
805
+ if (!wait) Effects = null;
805
806
  }
806
807
  }
807
808
  function completeUpdates(wait) {
@@ -1066,6 +1067,7 @@ function mapArray(list, mapFn, options = {}) {
1066
1067
  let newItems = list() || [],
1067
1068
  i,
1068
1069
  j;
1070
+ newItems[$TRACK];
1069
1071
  return untrack(() => {
1070
1072
  let newLen = newItems.length,
1071
1073
  newIndices,
@@ -1167,6 +1169,7 @@ function indexArray(list, mapFn, options = {}) {
1167
1169
  onCleanup(() => dispose(disposers));
1168
1170
  return () => {
1169
1171
  const newItems = list() || [];
1172
+ newItems[$TRACK];
1170
1173
  return untrack(() => {
1171
1174
  if (newItems.length === 0) {
1172
1175
  if (len !== 0) {
@@ -1330,9 +1333,7 @@ function lazy(fn) {
1330
1333
  });
1331
1334
  comp = s;
1332
1335
  } else if (!comp) {
1333
- const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default), {
1334
- globalRefetch: false
1335
- });
1336
+ const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default));
1336
1337
  comp = s;
1337
1338
  } else {
1338
1339
  const c = comp();
@@ -1601,6 +1602,7 @@ if (globalThis) {
1601
1602
 
1602
1603
  exports.$DEVCOMP = $DEVCOMP;
1603
1604
  exports.$PROXY = $PROXY;
1605
+ exports.$TRACK = $TRACK;
1604
1606
  exports.ErrorBoundary = ErrorBoundary;
1605
1607
  exports.For = For;
1606
1608
  exports.Index = Index;
@@ -1641,7 +1643,6 @@ exports.on = on;
1641
1643
  exports.onCleanup = onCleanup;
1642
1644
  exports.onError = onError;
1643
1645
  exports.onMount = onMount;
1644
- exports.refetchResources = refetchResources;
1645
1646
  exports.requestCallback = requestCallback;
1646
1647
  exports.resetErrorBoundaries = resetErrorBoundaries;
1647
1648
  exports.runWithOwner = runWithOwner;
package/dist/dev.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
@@ -204,7 +205,7 @@ function createEffect(fn, value, options) {
204
205
  s = SuspenseContext && lookup(Owner, SuspenseContext.id);
205
206
  if (s) c.suspense = s;
206
207
  c.user = true;
207
- Effects ? Effects.push(c) : queueMicrotask(() => updateComputation(c));
208
+ Effects ? Effects.push(c) : updateComputation(c);
208
209
  }
209
210
  function createReaction(onInvalidate, options) {
210
211
  let fn;
@@ -245,13 +246,8 @@ function createResource(source, fetcher, options) {
245
246
  source = true;
246
247
  }
247
248
  options || (options = {});
248
- if (options.globalRefetch !== false) {
249
- Resources || (Resources = new Set());
250
- Resources.add(load);
251
- Owner && onCleanup(() => Resources.delete(load));
252
- }
253
249
  const contexts = new Set(),
254
- [s, set] = createSignal(options.initialValue),
250
+ [value, setValue] = createSignal(options.initialValue),
255
251
  [track, trigger] = createSignal(undefined, {
256
252
  equals: false
257
253
  }),
@@ -263,7 +259,7 @@ function createResource(source, fetcher, options) {
263
259
  id = null,
264
260
  loadedUnderTransition = false,
265
261
  scheduled = false,
266
- dynamic = typeof source === "function";
262
+ dynamic = typeof source === "function" && createMemo(source);
267
263
  if (sharedConfig.context) {
268
264
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
269
265
  if (sharedConfig.load) initP = sharedConfig.load(id);
@@ -293,7 +289,7 @@ function createResource(source, fetcher, options) {
293
289
  }
294
290
  function completeLoad(v) {
295
291
  batch(() => {
296
- set(() => v);
292
+ setValue(() => v);
297
293
  setLoading(false);
298
294
  for (const c of contexts.keys()) c.decrement();
299
295
  contexts.clear();
@@ -301,7 +297,7 @@ function createResource(source, fetcher, options) {
301
297
  }
302
298
  function read() {
303
299
  const c = SuspenseContext && lookup(Owner, SuspenseContext.id),
304
- v = s();
300
+ v = value();
305
301
  if (err) throw err;
306
302
  if (Listener && !Listener.user && c) {
307
303
  createComputed(() => {
@@ -320,15 +316,15 @@ function createResource(source, fetcher, options) {
320
316
  if (refetching && scheduled) return;
321
317
  scheduled = false;
322
318
  setError(err = undefined);
323
- const lookup = dynamic ? source() : source;
319
+ const lookup = dynamic ? dynamic() : source;
324
320
  loadedUnderTransition = Transition && Transition.running;
325
321
  if (lookup == null || lookup === false) {
326
- loadEnd(pr, untrack(s));
322
+ loadEnd(pr, untrack(value));
327
323
  return;
328
324
  }
329
325
  if (Transition && pr) Transition.promises.delete(pr);
330
326
  const p = initP || untrack(() => fetcher(lookup, {
331
- value: s(),
327
+ value: value(),
332
328
  refetching
333
329
  }));
334
330
  if (typeof p !== "object" || !("then" in p)) {
@@ -354,18 +350,20 @@ function createResource(source, fetcher, options) {
354
350
  get() {
355
351
  return error();
356
352
  }
353
+ },
354
+ latest: {
355
+ get() {
356
+ if (err) throw err;
357
+ return value();
358
+ }
357
359
  }
358
360
  });
359
361
  if (dynamic) createComputed(() => load(false));else load(false);
360
362
  return [read, {
361
363
  refetch: load,
362
- mutate: set
364
+ mutate: setValue
363
365
  }];
364
366
  }
365
- let Resources;
366
- function refetchResources(info) {
367
- return Resources && Promise.all([...Resources].map(fn => fn(info)));
368
- }
369
367
  function createDeferred(source, options) {
370
368
  let t,
371
369
  timeout = options ? options.timeoutMs : undefined;
@@ -793,11 +791,14 @@ function runUpdates(fn, init) {
793
791
  if (Effects) wait = true;else Effects = [];
794
792
  ExecCount++;
795
793
  try {
796
- return fn();
794
+ const res = fn();
795
+ completeUpdates(wait);
796
+ return res;
797
797
  } catch (err) {
798
798
  handleError(err);
799
799
  } finally {
800
- completeUpdates(wait);
800
+ Updates = null;
801
+ if (!wait) Effects = null;
801
802
  }
802
803
  }
803
804
  function completeUpdates(wait) {
@@ -1062,6 +1063,7 @@ function mapArray(list, mapFn, options = {}) {
1062
1063
  let newItems = list() || [],
1063
1064
  i,
1064
1065
  j;
1066
+ newItems[$TRACK];
1065
1067
  return untrack(() => {
1066
1068
  let newLen = newItems.length,
1067
1069
  newIndices,
@@ -1163,6 +1165,7 @@ function indexArray(list, mapFn, options = {}) {
1163
1165
  onCleanup(() => dispose(disposers));
1164
1166
  return () => {
1165
1167
  const newItems = list() || [];
1168
+ newItems[$TRACK];
1166
1169
  return untrack(() => {
1167
1170
  if (newItems.length === 0) {
1168
1171
  if (len !== 0) {
@@ -1326,9 +1329,7 @@ function lazy(fn) {
1326
1329
  });
1327
1330
  comp = s;
1328
1331
  } else if (!comp) {
1329
- const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default), {
1330
- globalRefetch: false
1331
- });
1332
+ const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default));
1332
1333
  comp = s;
1333
1334
  } else {
1334
1335
  const c = comp();
@@ -1595,4 +1596,4 @@ if (globalThis) {
1595
1596
  if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
1596
1597
  }
1597
1598
 
1598
- 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, refetchResources, requestCallback, resetErrorBoundaries, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
1599
+ 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/dist/server.cjs CHANGED
@@ -419,7 +419,6 @@ function createResource(source, fetcher, options = {}) {
419
419
  mutate: v => value = v
420
420
  }];
421
421
  }
422
- function refetchResources(info) {}
423
422
  function lazy(fn) {
424
423
  let resolved;
425
424
  const p = fn();
@@ -567,7 +566,6 @@ exports.on = on;
567
566
  exports.onCleanup = onCleanup;
568
567
  exports.onError = onError;
569
568
  exports.onMount = onMount;
570
- exports.refetchResources = refetchResources;
571
569
  exports.requestCallback = requestCallback;
572
570
  exports.resetErrorBoundaries = resetErrorBoundaries;
573
571
  exports.runWithOwner = runWithOwner;
package/dist/server.js CHANGED
@@ -415,7 +415,6 @@ function createResource(source, fetcher, options = {}) {
415
415
  mutate: v => value = v
416
416
  }];
417
417
  }
418
- function refetchResources(info) {}
419
418
  function lazy(fn) {
420
419
  let resolved;
421
420
  const p = fn();
@@ -522,4 +521,4 @@ function Suspense(props) {
522
521
  return props.fallback;
523
522
  }
524
523
 
525
- export { $DEVCOMP, $PROXY, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createReaction, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, refetchResources, requestCallback, resetErrorBoundaries, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
524
+ export { $DEVCOMP, $PROXY, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createReaction, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableExternalSource, enableHydration, enableScheduling, equalFn, from, getListener, getOwner, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, resetErrorBoundaries, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
package/dist/solid.cjs CHANGED
@@ -131,6 +131,7 @@ function nextHydrateContext() {
131
131
 
132
132
  const equalFn = (a, b) => a === b;
133
133
  const $PROXY = Symbol("solid-proxy");
134
+ const $TRACK = Symbol("solid-track");
134
135
  const $DEVCOMP = Symbol("solid-dev-component");
135
136
  const signalOptions = {
136
137
  equals: equalFn
@@ -205,7 +206,7 @@ function createEffect(fn, value, options) {
205
206
  s = SuspenseContext && lookup(Owner, SuspenseContext.id);
206
207
  if (s) c.suspense = s;
207
208
  c.user = true;
208
- Effects ? Effects.push(c) : queueMicrotask(() => updateComputation(c));
209
+ Effects ? Effects.push(c) : updateComputation(c);
209
210
  }
210
211
  function createReaction(onInvalidate, options) {
211
212
  let fn;
@@ -246,13 +247,8 @@ function createResource(source, fetcher, options) {
246
247
  source = true;
247
248
  }
248
249
  options || (options = {});
249
- if (options.globalRefetch !== false) {
250
- Resources || (Resources = new Set());
251
- Resources.add(load);
252
- Owner && onCleanup(() => Resources.delete(load));
253
- }
254
250
  const contexts = new Set(),
255
- [s, set] = createSignal(options.initialValue),
251
+ [value, setValue] = createSignal(options.initialValue),
256
252
  [track, trigger] = createSignal(undefined, {
257
253
  equals: false
258
254
  }),
@@ -264,7 +260,7 @@ function createResource(source, fetcher, options) {
264
260
  id = null,
265
261
  loadedUnderTransition = false,
266
262
  scheduled = false,
267
- dynamic = typeof source === "function";
263
+ dynamic = typeof source === "function" && createMemo(source);
268
264
  if (sharedConfig.context) {
269
265
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
270
266
  if (sharedConfig.load) initP = sharedConfig.load(id);
@@ -294,7 +290,7 @@ function createResource(source, fetcher, options) {
294
290
  }
295
291
  function completeLoad(v) {
296
292
  batch(() => {
297
- set(() => v);
293
+ setValue(() => v);
298
294
  setLoading(false);
299
295
  for (const c of contexts.keys()) c.decrement();
300
296
  contexts.clear();
@@ -302,7 +298,7 @@ function createResource(source, fetcher, options) {
302
298
  }
303
299
  function read() {
304
300
  const c = SuspenseContext && lookup(Owner, SuspenseContext.id),
305
- v = s();
301
+ v = value();
306
302
  if (err) throw err;
307
303
  if (Listener && !Listener.user && c) {
308
304
  createComputed(() => {
@@ -321,15 +317,15 @@ function createResource(source, fetcher, options) {
321
317
  if (refetching && scheduled) return;
322
318
  scheduled = false;
323
319
  setError(err = undefined);
324
- const lookup = dynamic ? source() : source;
320
+ const lookup = dynamic ? dynamic() : source;
325
321
  loadedUnderTransition = Transition && Transition.running;
326
322
  if (lookup == null || lookup === false) {
327
- loadEnd(pr, untrack(s));
323
+ loadEnd(pr, untrack(value));
328
324
  return;
329
325
  }
330
326
  if (Transition && pr) Transition.promises.delete(pr);
331
327
  const p = initP || untrack(() => fetcher(lookup, {
332
- value: s(),
328
+ value: value(),
333
329
  refetching
334
330
  }));
335
331
  if (typeof p !== "object" || !("then" in p)) {
@@ -355,18 +351,20 @@ function createResource(source, fetcher, options) {
355
351
  get() {
356
352
  return error();
357
353
  }
354
+ },
355
+ latest: {
356
+ get() {
357
+ if (err) throw err;
358
+ return value();
359
+ }
358
360
  }
359
361
  });
360
362
  if (dynamic) createComputed(() => load(false));else load(false);
361
363
  return [read, {
362
364
  refetch: load,
363
- mutate: set
365
+ mutate: setValue
364
366
  }];
365
367
  }
366
- let Resources;
367
- function refetchResources(info) {
368
- return Resources && Promise.all([...Resources].map(fn => fn(info)));
369
- }
370
368
  function createDeferred(source, options) {
371
369
  let t,
372
370
  timeout = options ? options.timeoutMs : undefined;
@@ -740,11 +738,14 @@ function runUpdates(fn, init) {
740
738
  if (Effects) wait = true;else Effects = [];
741
739
  ExecCount++;
742
740
  try {
743
- return fn();
741
+ const res = fn();
742
+ completeUpdates(wait);
743
+ return res;
744
744
  } catch (err) {
745
745
  handleError(err);
746
746
  } finally {
747
- completeUpdates(wait);
747
+ Updates = null;
748
+ if (!wait) Effects = null;
748
749
  }
749
750
  }
750
751
  function completeUpdates(wait) {
@@ -985,6 +986,7 @@ function mapArray(list, mapFn, options = {}) {
985
986
  let newItems = list() || [],
986
987
  i,
987
988
  j;
989
+ newItems[$TRACK];
988
990
  return untrack(() => {
989
991
  let newLen = newItems.length,
990
992
  newIndices,
@@ -1086,6 +1088,7 @@ function indexArray(list, mapFn, options = {}) {
1086
1088
  onCleanup(() => dispose(disposers));
1087
1089
  return () => {
1088
1090
  const newItems = list() || [];
1091
+ newItems[$TRACK];
1089
1092
  return untrack(() => {
1090
1093
  if (newItems.length === 0) {
1091
1094
  if (len !== 0) {
@@ -1249,9 +1252,7 @@ function lazy(fn) {
1249
1252
  });
1250
1253
  comp = s;
1251
1254
  } else if (!comp) {
1252
- const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default), {
1253
- globalRefetch: false
1254
- });
1255
+ const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default));
1255
1256
  comp = s;
1256
1257
  } else {
1257
1258
  const c = comp();
@@ -1505,6 +1506,7 @@ let DEV;
1505
1506
 
1506
1507
  exports.$DEVCOMP = $DEVCOMP;
1507
1508
  exports.$PROXY = $PROXY;
1509
+ exports.$TRACK = $TRACK;
1508
1510
  exports.DEV = DEV;
1509
1511
  exports.ErrorBoundary = ErrorBoundary;
1510
1512
  exports.For = For;
@@ -1546,7 +1548,6 @@ exports.on = on;
1546
1548
  exports.onCleanup = onCleanup;
1547
1549
  exports.onError = onError;
1548
1550
  exports.onMount = onMount;
1549
- exports.refetchResources = refetchResources;
1550
1551
  exports.requestCallback = requestCallback;
1551
1552
  exports.resetErrorBoundaries = resetErrorBoundaries;
1552
1553
  exports.runWithOwner = runWithOwner;
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) : queueMicrotask(() => updateComputation(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
- [s, set] = createSignal(options.initialValue),
247
+ [value, setValue] = createSignal(options.initialValue),
252
248
  [track, trigger] = createSignal(undefined, {
253
249
  equals: false
254
250
  }),
@@ -260,7 +256,7 @@ function createResource(source, fetcher, options) {
260
256
  id = null,
261
257
  loadedUnderTransition = false,
262
258
  scheduled = false,
263
- dynamic = typeof source === "function";
259
+ dynamic = typeof source === "function" && createMemo(source);
264
260
  if (sharedConfig.context) {
265
261
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
266
262
  if (sharedConfig.load) initP = sharedConfig.load(id);
@@ -290,7 +286,7 @@ function createResource(source, fetcher, options) {
290
286
  }
291
287
  function completeLoad(v) {
292
288
  batch(() => {
293
- set(() => v);
289
+ setValue(() => v);
294
290
  setLoading(false);
295
291
  for (const c of contexts.keys()) c.decrement();
296
292
  contexts.clear();
@@ -298,7 +294,7 @@ function createResource(source, fetcher, options) {
298
294
  }
299
295
  function read() {
300
296
  const c = SuspenseContext && lookup(Owner, SuspenseContext.id),
301
- v = s();
297
+ v = value();
302
298
  if (err) throw err;
303
299
  if (Listener && !Listener.user && c) {
304
300
  createComputed(() => {
@@ -317,15 +313,15 @@ function createResource(source, fetcher, options) {
317
313
  if (refetching && scheduled) return;
318
314
  scheduled = false;
319
315
  setError(err = undefined);
320
- const lookup = dynamic ? source() : source;
316
+ const lookup = dynamic ? dynamic() : source;
321
317
  loadedUnderTransition = Transition && Transition.running;
322
318
  if (lookup == null || lookup === false) {
323
- loadEnd(pr, untrack(s));
319
+ loadEnd(pr, untrack(value));
324
320
  return;
325
321
  }
326
322
  if (Transition && pr) Transition.promises.delete(pr);
327
323
  const p = initP || untrack(() => fetcher(lookup, {
328
- value: s(),
324
+ value: value(),
329
325
  refetching
330
326
  }));
331
327
  if (typeof p !== "object" || !("then" in p)) {
@@ -351,18 +347,20 @@ function createResource(source, fetcher, options) {
351
347
  get() {
352
348
  return error();
353
349
  }
350
+ },
351
+ latest: {
352
+ get() {
353
+ if (err) throw err;
354
+ return value();
355
+ }
354
356
  }
355
357
  });
356
358
  if (dynamic) createComputed(() => load(false));else load(false);
357
359
  return [read, {
358
360
  refetch: load,
359
- mutate: set
361
+ mutate: setValue
360
362
  }];
361
363
  }
362
- let Resources;
363
- function refetchResources(info) {
364
- return Resources && Promise.all([...Resources].map(fn => fn(info)));
365
- }
366
364
  function createDeferred(source, options) {
367
365
  let t,
368
366
  timeout = options ? options.timeoutMs : undefined;
@@ -736,11 +734,14 @@ function runUpdates(fn, init) {
736
734
  if (Effects) wait = true;else Effects = [];
737
735
  ExecCount++;
738
736
  try {
739
- return fn();
737
+ const res = fn();
738
+ completeUpdates(wait);
739
+ return res;
740
740
  } catch (err) {
741
741
  handleError(err);
742
742
  } finally {
743
- completeUpdates(wait);
743
+ Updates = null;
744
+ if (!wait) Effects = null;
744
745
  }
745
746
  }
746
747
  function completeUpdates(wait) {
@@ -981,6 +982,7 @@ function mapArray(list, mapFn, options = {}) {
981
982
  let newItems = list() || [],
982
983
  i,
983
984
  j;
985
+ newItems[$TRACK];
984
986
  return untrack(() => {
985
987
  let newLen = newItems.length,
986
988
  newIndices,
@@ -1082,6 +1084,7 @@ function indexArray(list, mapFn, options = {}) {
1082
1084
  onCleanup(() => dispose(disposers));
1083
1085
  return () => {
1084
1086
  const newItems = list() || [];
1087
+ newItems[$TRACK];
1085
1088
  return untrack(() => {
1086
1089
  if (newItems.length === 0) {
1087
1090
  if (len !== 0) {
@@ -1245,9 +1248,7 @@ function lazy(fn) {
1245
1248
  });
1246
1249
  comp = s;
1247
1250
  } else if (!comp) {
1248
- const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default), {
1249
- globalRefetch: false
1250
- });
1251
+ const [s] = createResource(() => (p || (p = fn())).then(mod => mod.default));
1251
1252
  comp = s;
1252
1253
  } else {
1253
1254
  const c = comp();
@@ -1499,4 +1500,4 @@ function Suspense(props) {
1499
1500
 
1500
1501
  let DEV;
1501
1502
 
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, refetchResources, requestCallback, resetErrorBoundaries, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
1503
+ 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.3.17",
4
+ "version": "1.4.0-beta.0",
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": "88ce357264a4966d38d143143a3efe8a394e57c0"
147
+ "gitHead": "c47bee46d775574c4eebd94ea207f4e679f08d60"
148
148
  }