solid-js 2.0.0-experimental.4 → 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) {
@@ -275,7 +251,12 @@ function ErrorBoundary(props) {
275
251
  function Suspense(props) {
276
252
  return signals.createSuspense(() => props.children, () => props.fallback);
277
253
  }
254
+ function Boundary(props) {
255
+ return signals.createBoundary(() => props.children, () => props.mode);
256
+ }
278
257
 
258
+ function ssrHandleError() {}
259
+ function ssrRunInScope() {}
279
260
  const DevHooks = {};
280
261
  const DEV = {
281
262
  hooks: DevHooks,
@@ -297,10 +278,6 @@ Object.defineProperty(exports, "$TRACK", {
297
278
  enumerable: true,
298
279
  get: function () { return signals.$TRACK; }
299
280
  });
300
- Object.defineProperty(exports, "catchError", {
301
- enumerable: true,
302
- get: function () { return signals.catchError; }
303
- });
304
281
  Object.defineProperty(exports, "createAsync", {
305
282
  enumerable: true,
306
283
  get: function () { return signals.createAsync; }
@@ -401,6 +378,10 @@ Object.defineProperty(exports, "runWithOwner", {
401
378
  enumerable: true,
402
379
  get: function () { return signals.runWithOwner; }
403
380
  });
381
+ Object.defineProperty(exports, "tryCatch", {
382
+ enumerable: true,
383
+ get: function () { return signals.tryCatch; }
384
+ });
404
385
  Object.defineProperty(exports, "untrack", {
405
386
  enumerable: true,
406
387
  get: function () { return signals.untrack; }
@@ -410,6 +391,7 @@ Object.defineProperty(exports, "unwrap", {
410
391
  get: function () { return signals.unwrap; }
411
392
  });
412
393
  exports.$DEVCOMP = $DEVCOMP;
394
+ exports.Boundary = Boundary;
413
395
  exports.DEV = DEV;
414
396
  exports.ErrorBoundary = ErrorBoundary;
415
397
  exports.For = For;
@@ -428,4 +410,6 @@ exports.lazy = lazy;
428
410
  exports.observable = observable;
429
411
  exports.onMount = onMount;
430
412
  exports.sharedConfig = sharedConfig;
413
+ exports.ssrHandleError = ssrHandleError;
414
+ exports.ssrRunInScope = ssrRunInScope;
431
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,79 +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
- : {};
173
+ const options = "fallback" in props ? {
174
+ fallback: () => props.fallback
175
+ } : {};
271
176
  options.from = () => props.from;
272
- return createMemo(
273
- repeat(
274
- () => props.count,
275
- index => (typeof props.children === "function" ? props.children(index) : props.children),
276
- options
277
- ),
278
- undefined,
279
- {
280
- name: "value"
281
- }
282
- );
177
+ return createMemo(repeat(() => props.count, index => typeof props.children === "function" ? props.children(index) : props.children, options), undefined, {
178
+ name: "value"
179
+ }) ;
283
180
  }
284
181
  function Show(props) {
285
182
  const keyed = props.keyed;
286
183
  const conditionValue = createMemo(() => props.when, undefined, {
287
184
  name: "condition value"
288
- });
289
- const condition = keyed
290
- ? conditionValue
291
- : createMemo(conditionValue, undefined, {
292
- equals: (a, b) => !a === !b,
293
- name: "condition"
294
- });
295
- return createMemo(
296
- () => {
297
- const c = condition();
298
- if (c) {
299
- const child = props.children;
300
- const fn = typeof child === "function" && child.length > 0;
301
- return fn
302
- ? untrack(() =>
303
- child(() => {
304
- if (!untrack(condition)) throw narrowedError("Show");
305
- return conditionValue();
306
- })
307
- )
308
- : child;
309
- }
310
- return props.fallback;
311
- },
312
- undefined,
313
- {
314
- 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;
315
199
  }
316
- );
200
+ return props.fallback;
201
+ }, undefined, {
202
+ name: "value"
203
+ } );
317
204
  }
318
205
  function Switch(props) {
319
206
  const chs = children(() => props.children);
@@ -325,93 +212,57 @@ function Switch(props) {
325
212
  const index = i;
326
213
  const mp = mps[i];
327
214
  const prevFunc = func;
328
- const conditionValue = createMemo(() => (prevFunc() ? undefined : mp.when), undefined, {
215
+ const conditionValue = createMemo(() => prevFunc() ? undefined : mp.when, undefined, {
329
216
  name: "condition value"
330
- });
331
- const condition = mp.keyed
332
- ? conditionValue
333
- : createMemo(conditionValue, undefined, {
334
- equals: (a, b) => !a === !b,
335
- name: "condition"
336
- });
217
+ } );
218
+ const condition = mp.keyed ? conditionValue : createMemo(conditionValue, undefined, {
219
+ equals: (a, b) => !a === !b,
220
+ name: "condition"
221
+ } );
337
222
  func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
338
223
  }
339
224
  return func;
340
225
  });
341
- return createMemo(
342
- () => {
343
- const sel = switchFunc()();
344
- if (!sel) return props.fallback;
345
- const [index, conditionValue, mp] = sel;
346
- const child = mp.children;
347
- const fn = typeof child === "function" && child.length > 0;
348
- return fn
349
- ? untrack(() =>
350
- child(() => {
351
- if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
352
- return conditionValue();
353
- })
354
- )
355
- : child;
356
- },
357
- undefined,
358
- {
359
- name: "eval conditions"
360
- }
361
- );
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
+ } );
362
239
  }
363
240
  function Match(props) {
364
241
  return props;
365
242
  }
366
243
  function ErrorBoundary(props) {
367
- return createErrorBoundary(
368
- () => props.children,
369
- (err, reset) => {
370
- const f = props.fallback;
371
- if (typeof f !== "function" || f.length == 0) console.error(err);
372
- return typeof f === "function" && f.length ? f(err, reset) : f;
373
- }
374
- );
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
+ });
375
249
  }
376
250
  function Suspense(props) {
377
- return createSuspense(
378
- () => props.children,
379
- () => props.fallback
380
- );
251
+ return createSuspense(() => props.children, () => props.fallback);
252
+ }
253
+ function Boundary(props) {
254
+ return createBoundary(() => props.children, () => props.mode);
381
255
  }
382
256
 
257
+ function ssrHandleError() {}
258
+ function ssrRunInScope() {}
383
259
  const DevHooks = {};
384
260
  const DEV = {
385
261
  hooks: DevHooks,
386
262
  registerGraph
387
- };
263
+ } ;
388
264
  if (globalThis) {
389
- if (!globalThis.Solid$$) globalThis.Solid$$ = true;
390
- else
391
- console.warn(
392
- "You appear to have multiple instances of Solid. This can lead to unexpected behavior."
393
- );
265
+ if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
394
266
  }
395
267
 
396
- export {
397
- $DEVCOMP,
398
- DEV,
399
- ErrorBoundary,
400
- For,
401
- Match,
402
- Repeat,
403
- Show,
404
- Suspense,
405
- Switch,
406
- children,
407
- createComponent,
408
- createContext,
409
- createUniqueId,
410
- enableHydration,
411
- from,
412
- lazy,
413
- observable,
414
- onMount,
415
- sharedConfig,
416
- useContext
417
- };
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 };