solid-js 2.0.0-experimental.3 → 2.0.0-experimental.5

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
@@ -9,8 +9,8 @@ function onMount(fn) {
9
9
  function createContext(defaultValue, options) {
10
10
  const id = Symbol(options && options.name || "");
11
11
  function provider(props) {
12
- return signals.createMemo(() => {
13
- signals.setContext(provider, signals.untrack(() => props.value));
12
+ return signals.createRoot(() => {
13
+ signals.setContext(provider, props.value);
14
14
  return children(() => props.children);
15
15
  });
16
16
  }
@@ -101,43 +101,19 @@ const sharedConfig = {
101
101
  context: undefined,
102
102
  registry: undefined,
103
103
  done: false,
104
- getContextId() {
105
- return getContextId(this.context.count);
106
- },
107
104
  getNextContextId() {
108
- return getContextId(this.context.count++);
105
+ const o = signals.getOwner();
106
+ if (!o) throw new Error(`getNextContextId cannot be used under non-hydrating context`);
107
+ return o.getNextChildId();
109
108
  }
110
109
  };
111
- function getContextId(count) {
112
- const num = String(count),
113
- len = num.length - 1;
114
- return sharedConfig.context.id + (len ? String.fromCharCode(96 + len) : "") + num;
115
- }
116
110
  function setHydrateContext(context) {
117
111
  sharedConfig.context = context;
118
112
  }
119
- function nextHydrateContext() {
120
- return {
121
- ...sharedConfig.context,
122
- id: sharedConfig.getNextContextId(),
123
- count: 0
124
- };
125
- }
126
113
 
127
- let hydrationEnabled = false;
128
114
  function enableHydration() {
129
- hydrationEnabled = true;
130
115
  }
131
116
  function createComponent(Comp, props) {
132
- if (hydrationEnabled) {
133
- if (sharedConfig.context) {
134
- const c = sharedConfig.context;
135
- setHydrateContext(nextHydrateContext());
136
- const r = devComponent(Comp, props || {}) ;
137
- setHydrateContext(c);
138
- return r;
139
- }
140
- }
141
117
  return devComponent(Comp, props || {});
142
118
  }
143
119
  function lazy(fn) {
@@ -198,6 +174,7 @@ function Repeat(props) {
198
174
  const options = "fallback" in props ? {
199
175
  fallback: () => props.fallback
200
176
  } : {};
177
+ options.from = () => props.from;
201
178
  return signals.createMemo(signals.repeat(() => props.count, index => typeof props.children === "function" ? props.children(index) : props.children, options), undefined, {
202
179
  name: "value"
203
180
  }) ;
@@ -274,7 +251,12 @@ function ErrorBoundary(props) {
274
251
  function Suspense(props) {
275
252
  return signals.createSuspense(() => props.children, () => props.fallback);
276
253
  }
254
+ function Boundary(props) {
255
+ return signals.createBoundary(() => props.children, () => props.mode);
256
+ }
277
257
 
258
+ function ssrHandleError() {}
259
+ function ssrRunInScope() {}
278
260
  const DevHooks = {};
279
261
  const DEV = {
280
262
  hooks: DevHooks,
@@ -296,10 +278,6 @@ Object.defineProperty(exports, "$TRACK", {
296
278
  enumerable: true,
297
279
  get: function () { return signals.$TRACK; }
298
280
  });
299
- Object.defineProperty(exports, "catchError", {
300
- enumerable: true,
301
- get: function () { return signals.catchError; }
302
- });
303
281
  Object.defineProperty(exports, "createAsync", {
304
282
  enumerable: true,
305
283
  get: function () { return signals.createAsync; }
@@ -400,6 +378,10 @@ Object.defineProperty(exports, "runWithOwner", {
400
378
  enumerable: true,
401
379
  get: function () { return signals.runWithOwner; }
402
380
  });
381
+ Object.defineProperty(exports, "tryCatch", {
382
+ enumerable: true,
383
+ get: function () { return signals.tryCatch; }
384
+ });
403
385
  Object.defineProperty(exports, "untrack", {
404
386
  enumerable: true,
405
387
  get: function () { return signals.untrack; }
@@ -409,6 +391,7 @@ Object.defineProperty(exports, "unwrap", {
409
391
  get: function () { return signals.unwrap; }
410
392
  });
411
393
  exports.$DEVCOMP = $DEVCOMP;
394
+ exports.Boundary = Boundary;
412
395
  exports.DEV = DEV;
413
396
  exports.ErrorBoundary = ErrorBoundary;
414
397
  exports.For = For;
@@ -427,4 +410,6 @@ exports.lazy = lazy;
427
410
  exports.observable = observable;
428
411
  exports.onMount = onMount;
429
412
  exports.sharedConfig = sharedConfig;
413
+ exports.ssrHandleError = ssrHandleError;
414
+ exports.ssrRunInScope = ssrRunInScope;
430
415
  exports.useContext = useContext;
package/dist/dev.js CHANGED
@@ -1,66 +1,15 @@
1
- import {
2
- createEffect,
3
- getContext,
4
- createMemo,
5
- flatten,
6
- setContext,
7
- untrack,
8
- createRoot,
9
- getOwner,
10
- onCleanup,
11
- createSignal,
12
- createAsync,
13
- mapArray,
14
- repeat,
15
- createErrorBoundary,
16
- createSuspense
17
- } from "@solidjs/signals";
18
- export {
19
- $PROXY,
20
- $RAW,
21
- $TRACK,
22
- catchError,
23
- createAsync,
24
- createEffect,
25
- createMemo,
26
- createProjection,
27
- createRenderEffect,
28
- createRoot,
29
- createSignal,
30
- createStore,
31
- flatten,
32
- flushSync,
33
- getObserver,
34
- getOwner,
35
- isEqual,
36
- isPending,
37
- isWrappable,
38
- latest,
39
- mapArray,
40
- merge,
41
- omit,
42
- onCleanup,
43
- reconcile,
44
- repeat,
45
- resolve,
46
- runWithObserver,
47
- runWithOwner,
48
- untrack,
49
- unwrap
50
- } from "@solidjs/signals";
1
+ import { createEffect, getContext, createMemo, flatten, createRoot, setContext, getOwner, untrack, onCleanup, createSignal, createAsync, mapArray, repeat, createErrorBoundary, createSuspense, createBoundary } from '@solidjs/signals';
2
+ export { $PROXY, $RAW, $TRACK, createAsync, createEffect, createMemo, createProjection, createRenderEffect, createRoot, createSignal, createStore, flatten, flushSync, getObserver, getOwner, isEqual, isPending, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithObserver, runWithOwner, tryCatch, untrack, unwrap } from '@solidjs/signals';
51
3
 
52
- const $DEVCOMP = Symbol("COMPONENT_DEV");
4
+ const $DEVCOMP = Symbol("COMPONENT_DEV" );
53
5
  function onMount(fn) {
54
6
  createEffect(() => null, fn);
55
7
  }
56
8
  function createContext(defaultValue, options) {
57
- const id = Symbol((options && options.name) || "");
9
+ const id = Symbol(options && options.name || "");
58
10
  function provider(props) {
59
- return createMemo(() => {
60
- setContext(
61
- provider,
62
- untrack(() => props.value)
63
- );
11
+ return createRoot(() => {
12
+ setContext(provider, props.value);
64
13
  return children(() => props.children);
65
14
  });
66
15
  }
@@ -75,7 +24,7 @@ function children(fn) {
75
24
  const children = createMemo(fn);
76
25
  const memo = createMemo(() => flatten(children()), undefined, {
77
26
  name: "children"
78
- });
27
+ }) ;
79
28
  memo.toArray = () => {
80
29
  const c = memo();
81
30
  return Array.isArray(c) ? c : c != null ? [c] : [];
@@ -99,8 +48,7 @@ function devComponent(Comp, props) {
99
48
  function registerGraph(value) {
100
49
  const owner = getOwner();
101
50
  if (!owner) return;
102
- if (owner.sourceMap) owner.sourceMap.push(value);
103
- else owner.sourceMap = [value];
51
+ if (owner.sourceMap) owner.sourceMap.push(value);else owner.sourceMap = [value];
104
52
  value.graph = owner;
105
53
  }
106
54
 
@@ -110,20 +58,16 @@ function observable(input) {
110
58
  if (!(observer instanceof Object) || observer == null) {
111
59
  throw new TypeError("Expected the observer to be an object.");
112
60
  }
113
- const handler =
114
- typeof observer === "function" ? observer : observer.next && observer.next.bind(observer);
61
+ const handler = typeof observer === "function" ? observer : observer.next && observer.next.bind(observer);
115
62
  if (!handler) {
116
63
  return {
117
64
  unsubscribe() {}
118
65
  };
119
66
  }
120
67
  const dispose = createRoot(disposer => {
121
- createEffect(
122
- () => input(),
123
- v => {
124
- handler(v);
125
- }
126
- );
68
+ createEffect(() => input(), v => {
69
+ handler(v);
70
+ });
127
71
  return disposer;
128
72
  });
129
73
  if (getOwner()) onCleanup(dispose);
@@ -144,7 +88,7 @@ function from(producer, initialValue = undefined) {
144
88
  });
145
89
  if ("subscribe" in producer) {
146
90
  const unsub = producer.subscribe(v => set(() => v));
147
- onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub()));
91
+ onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub());
148
92
  } else {
149
93
  const clean = producer(set);
150
94
  onCleanup(clean);
@@ -156,43 +100,19 @@ const sharedConfig = {
156
100
  context: undefined,
157
101
  registry: undefined,
158
102
  done: false,
159
- getContextId() {
160
- return getContextId(this.context.count);
161
- },
162
103
  getNextContextId() {
163
- return getContextId(this.context.count++);
104
+ const o = getOwner();
105
+ if (!o) throw new Error(`getNextContextId cannot be used under non-hydrating context`);
106
+ return o.getNextChildId();
164
107
  }
165
108
  };
166
- function getContextId(count) {
167
- const num = String(count),
168
- len = num.length - 1;
169
- return sharedConfig.context.id + (len ? String.fromCharCode(96 + len) : "") + num;
170
- }
171
109
  function setHydrateContext(context) {
172
110
  sharedConfig.context = context;
173
111
  }
174
- function nextHydrateContext() {
175
- return {
176
- ...sharedConfig.context,
177
- id: sharedConfig.getNextContextId(),
178
- count: 0
179
- };
180
- }
181
112
 
182
- let hydrationEnabled = false;
183
113
  function enableHydration() {
184
- hydrationEnabled = true;
185
114
  }
186
115
  function createComponent(Comp, props) {
187
- if (hydrationEnabled) {
188
- if (sharedConfig.context) {
189
- const c = sharedConfig.context;
190
- setHydrateContext(nextHydrateContext());
191
- const r = devComponent(Comp, props || {});
192
- setHydrateContext(c);
193
- return r;
194
- }
195
- }
196
116
  return devComponent(Comp, props || {});
197
117
  }
198
118
  function lazy(fn) {
@@ -216,23 +136,19 @@ function lazy(fn) {
216
136
  comp = s;
217
137
  }
218
138
  let Comp;
219
- return createMemo(() =>
220
- (Comp = comp())
221
- ? untrack(() => {
222
- Object.assign(Comp, {
223
- [$DEVCOMP]: true
224
- });
225
- if (!ctx || sharedConfig.done) return Comp(props);
226
- const c = sharedConfig.context;
227
- setHydrateContext(ctx);
228
- const r = Comp(props);
229
- setHydrateContext(c);
230
- return r;
231
- })
232
- : ""
233
- );
139
+ return createMemo(() => (Comp = comp()) ? untrack(() => {
140
+ Object.assign(Comp, {
141
+ [$DEVCOMP]: true
142
+ });
143
+ if (!ctx || sharedConfig.done) return Comp(props);
144
+ const c = sharedConfig.context;
145
+ setHydrateContext(ctx);
146
+ const r = Comp(props);
147
+ setHydrateContext(c);
148
+ return r;
149
+ }) : "");
234
150
  };
235
- wrap.preload = () => p || ((p = fn()).then(mod => (comp = () => mod.default)), p);
151
+ wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
236
152
  return wrap;
237
153
  }
238
154
  let counter = 0;
@@ -241,78 +157,50 @@ function createUniqueId() {
241
157
  return ctx ? sharedConfig.getNextContextId() : `cl-${counter++}`;
242
158
  }
243
159
 
244
- const narrowedError = name =>
245
- `Attempting to access a stale value from <${name}> that could possibly be undefined. This may occur because you are reading the accessor returned from the component at a time where it has already been unmounted. We recommend cleaning up any stale timers or async, or reading from the initial condition.`;
160
+ const narrowedError = name => `Attempting to access a stale value from <${name}> that could possibly be undefined. This may occur because you are reading the accessor returned from the component at a time where it has already been unmounted. We recommend cleaning up any stale timers or async, or reading from the initial condition.` ;
246
161
  function For(props) {
247
- const options =
248
- "fallback" in props
249
- ? {
250
- keyed: props.keyed,
251
- fallback: () => props.fallback
252
- }
253
- : {
254
- keyed: props.keyed
255
- };
256
- return createMemo(
257
- mapArray(() => props.each, props.children, options),
258
- undefined,
259
- {
260
- name: "value"
261
- }
262
- );
162
+ const options = "fallback" in props ? {
163
+ keyed: props.keyed,
164
+ fallback: () => props.fallback
165
+ } : {
166
+ keyed: props.keyed
167
+ };
168
+ return createMemo(mapArray(() => props.each, props.children, options), undefined, {
169
+ name: "value"
170
+ }) ;
263
171
  }
264
172
  function Repeat(props) {
265
- const options =
266
- "fallback" in props
267
- ? {
268
- fallback: () => props.fallback
269
- }
270
- : {};
271
- return createMemo(
272
- repeat(
273
- () => props.count,
274
- index => (typeof props.children === "function" ? props.children(index) : props.children),
275
- options
276
- ),
277
- undefined,
278
- {
279
- name: "value"
280
- }
281
- );
173
+ const options = "fallback" in props ? {
174
+ fallback: () => props.fallback
175
+ } : {};
176
+ options.from = () => props.from;
177
+ return createMemo(repeat(() => props.count, index => typeof props.children === "function" ? props.children(index) : props.children, options), undefined, {
178
+ name: "value"
179
+ }) ;
282
180
  }
283
181
  function Show(props) {
284
182
  const keyed = props.keyed;
285
183
  const conditionValue = createMemo(() => props.when, undefined, {
286
184
  name: "condition value"
287
- });
288
- const condition = keyed
289
- ? conditionValue
290
- : createMemo(conditionValue, undefined, {
291
- equals: (a, b) => !a === !b,
292
- name: "condition"
293
- });
294
- return createMemo(
295
- () => {
296
- const c = condition();
297
- if (c) {
298
- const child = props.children;
299
- const fn = typeof child === "function" && child.length > 0;
300
- return fn
301
- ? untrack(() =>
302
- child(() => {
303
- if (!untrack(condition)) throw narrowedError("Show");
304
- return conditionValue();
305
- })
306
- )
307
- : child;
308
- }
309
- return props.fallback;
310
- },
311
- undefined,
312
- {
313
- name: "value"
185
+ } );
186
+ const condition = keyed ? conditionValue : createMemo(conditionValue, undefined, {
187
+ equals: (a, b) => !a === !b,
188
+ name: "condition"
189
+ } );
190
+ return createMemo(() => {
191
+ const c = condition();
192
+ if (c) {
193
+ const child = props.children;
194
+ const fn = typeof child === "function" && child.length > 0;
195
+ return fn ? untrack(() => child(() => {
196
+ if (!untrack(condition)) throw narrowedError("Show");
197
+ return conditionValue();
198
+ })) : child;
314
199
  }
315
- );
200
+ return props.fallback;
201
+ }, undefined, {
202
+ name: "value"
203
+ } );
316
204
  }
317
205
  function Switch(props) {
318
206
  const chs = children(() => props.children);
@@ -324,93 +212,57 @@ function Switch(props) {
324
212
  const index = i;
325
213
  const mp = mps[i];
326
214
  const prevFunc = func;
327
- const conditionValue = createMemo(() => (prevFunc() ? undefined : mp.when), undefined, {
215
+ const conditionValue = createMemo(() => prevFunc() ? undefined : mp.when, undefined, {
328
216
  name: "condition value"
329
- });
330
- const condition = mp.keyed
331
- ? conditionValue
332
- : createMemo(conditionValue, undefined, {
333
- equals: (a, b) => !a === !b,
334
- name: "condition"
335
- });
217
+ } );
218
+ const condition = mp.keyed ? conditionValue : createMemo(conditionValue, undefined, {
219
+ equals: (a, b) => !a === !b,
220
+ name: "condition"
221
+ } );
336
222
  func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
337
223
  }
338
224
  return func;
339
225
  });
340
- return createMemo(
341
- () => {
342
- const sel = switchFunc()();
343
- if (!sel) return props.fallback;
344
- const [index, conditionValue, mp] = sel;
345
- const child = mp.children;
346
- const fn = typeof child === "function" && child.length > 0;
347
- return fn
348
- ? untrack(() =>
349
- child(() => {
350
- if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
351
- return conditionValue();
352
- })
353
- )
354
- : child;
355
- },
356
- undefined,
357
- {
358
- name: "eval conditions"
359
- }
360
- );
226
+ return createMemo(() => {
227
+ const sel = switchFunc()();
228
+ if (!sel) return props.fallback;
229
+ const [index, conditionValue, mp] = sel;
230
+ const child = mp.children;
231
+ const fn = typeof child === "function" && child.length > 0;
232
+ return fn ? untrack(() => child(() => {
233
+ if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
234
+ return conditionValue();
235
+ })) : child;
236
+ }, undefined, {
237
+ name: "eval conditions"
238
+ } );
361
239
  }
362
240
  function Match(props) {
363
241
  return props;
364
242
  }
365
243
  function ErrorBoundary(props) {
366
- return createErrorBoundary(
367
- () => props.children,
368
- (err, reset) => {
369
- const f = props.fallback;
370
- if (typeof f !== "function" || f.length == 0) console.error(err);
371
- return typeof f === "function" && f.length ? f(err, reset) : f;
372
- }
373
- );
244
+ return createErrorBoundary(() => props.children, (err, reset) => {
245
+ const f = props.fallback;
246
+ if ((typeof f !== "function" || f.length == 0)) console.error(err);
247
+ return typeof f === "function" && f.length ? f(err, reset) : f;
248
+ });
374
249
  }
375
250
  function Suspense(props) {
376
- return createSuspense(
377
- () => props.children,
378
- () => props.fallback
379
- );
251
+ return createSuspense(() => props.children, () => props.fallback);
252
+ }
253
+ function Boundary(props) {
254
+ return createBoundary(() => props.children, () => props.mode);
380
255
  }
381
256
 
257
+ function ssrHandleError() {}
258
+ function ssrRunInScope() {}
382
259
  const DevHooks = {};
383
260
  const DEV = {
384
261
  hooks: DevHooks,
385
262
  registerGraph
386
- };
263
+ } ;
387
264
  if (globalThis) {
388
- if (!globalThis.Solid$$) globalThis.Solid$$ = true;
389
- else
390
- console.warn(
391
- "You appear to have multiple instances of Solid. This can lead to unexpected behavior."
392
- );
265
+ if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
393
266
  }
394
267
 
395
- export {
396
- $DEVCOMP,
397
- DEV,
398
- ErrorBoundary,
399
- For,
400
- Match,
401
- Repeat,
402
- Show,
403
- Suspense,
404
- Switch,
405
- children,
406
- createComponent,
407
- createContext,
408
- createUniqueId,
409
- enableHydration,
410
- from,
411
- lazy,
412
- observable,
413
- onMount,
414
- sharedConfig,
415
- useContext
416
- };
268
+ export { $DEVCOMP, Boundary, DEV, ErrorBoundary, For, Match, Repeat, Show, Suspense, Switch, children, createComponent, createContext, createUniqueId, enableHydration, from, lazy, observable, onMount, sharedConfig, ssrHandleError, ssrRunInScope, useContext };