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

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2016-2023 Ryan Carniato
3
+ Copyright (c) 2016-2025 Ryan Carniato
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/dev.cjs CHANGED
@@ -83,8 +83,8 @@ function observable(input) {
83
83
  }
84
84
  };
85
85
  }
86
- function from(producer) {
87
- const [s, set] = signals.createSignal(undefined, {
86
+ function from(producer, initialValue = undefined) {
87
+ const [s, set] = signals.createSignal(() => initialValue, initialValue, {
88
88
  equals: false
89
89
  });
90
90
  if ("subscribe" in producer) {
@@ -204,8 +204,11 @@ function Repeat(props) {
204
204
  }
205
205
  function Show(props) {
206
206
  const keyed = props.keyed;
207
- const condition = signals.createMemo(() => props.when, undefined, {
208
- equals: (a, b) => keyed ? a === b : !a === !b,
207
+ const conditionValue = signals.createMemo(() => props.when, undefined, {
208
+ name: "condition value"
209
+ } );
210
+ const condition = keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
211
+ equals: (a, b) => !a === !b,
209
212
  name: "condition"
210
213
  } );
211
214
  return signals.createMemo(() => {
@@ -215,7 +218,7 @@ function Show(props) {
215
218
  const fn = typeof child === "function" && child.length > 0;
216
219
  return fn ? signals.untrack(() => child(() => {
217
220
  if (!signals.untrack(condition)) throw narrowedError("Show");
218
- return props.when;
221
+ return conditionValue();
219
222
  })) : child;
220
223
  }
221
224
  return props.fallback;
@@ -224,35 +227,38 @@ function Show(props) {
224
227
  } );
225
228
  }
226
229
  function Switch(props) {
227
- let keyed = false;
228
- const equals = (a, b) => (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2];
229
- const conditions = children(() => props.children),
230
- evalConditions = signals.createMemo(() => {
231
- let conds = conditions();
232
- if (!Array.isArray(conds)) conds = [conds];
233
- for (let i = 0; i < conds.length; i++) {
234
- const c = conds[i].when;
235
- if (c) {
236
- keyed = !!conds[i].keyed;
237
- return [i, c, conds[i]];
238
- }
239
- }
240
- return [-1];
241
- }, undefined, {
242
- equals,
243
- name: "eval conditions"
244
- } );
230
+ const chs = children(() => props.children);
231
+ const switchFunc = signals.createMemo(() => {
232
+ const ch = chs();
233
+ const mps = Array.isArray(ch) ? ch : [ch];
234
+ let func = () => undefined;
235
+ for (let i = 0; i < mps.length; i++) {
236
+ const index = i;
237
+ const mp = mps[i];
238
+ const prevFunc = func;
239
+ const conditionValue = signals.createMemo(() => prevFunc() ? undefined : mp.when, undefined, {
240
+ name: "condition value"
241
+ } );
242
+ const condition = mp.keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
243
+ equals: (a, b) => !a === !b,
244
+ name: "condition"
245
+ } );
246
+ func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
247
+ }
248
+ return func;
249
+ });
245
250
  return signals.createMemo(() => {
246
- const [index, when, cond] = evalConditions();
247
- if (index < 0) return props.fallback;
248
- const c = cond.children;
249
- const fn = typeof c === "function" && c.length > 0;
250
- return fn ? signals.untrack(() => c(() => {
251
- if (signals.untrack(evalConditions)[0] !== index) throw narrowedError("Match");
252
- return cond.when;
253
- })) : c;
251
+ const sel = switchFunc()();
252
+ if (!sel) return props.fallback;
253
+ const [index, conditionValue, mp] = sel;
254
+ const child = mp.children;
255
+ const fn = typeof child === "function" && child.length > 0;
256
+ return fn ? signals.untrack(() => child(() => {
257
+ if (signals.untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
258
+ return conditionValue();
259
+ })) : child;
254
260
  }, undefined, {
255
- name: "value"
261
+ name: "eval conditions"
256
262
  } );
257
263
  }
258
264
  function Match(props) {
@@ -310,10 +316,6 @@ Object.defineProperty(exports, "createProjection", {
310
316
  enumerable: true,
311
317
  get: function () { return signals.createProjection; }
312
318
  });
313
- Object.defineProperty(exports, "createReaction", {
314
- enumerable: true,
315
- get: function () { return signals.createReaction; }
316
- });
317
319
  Object.defineProperty(exports, "createRenderEffect", {
318
320
  enumerable: true,
319
321
  get: function () { return signals.createRenderEffect; }
@@ -350,9 +352,9 @@ Object.defineProperty(exports, "isEqual", {
350
352
  enumerable: true,
351
353
  get: function () { return signals.isEqual; }
352
354
  });
353
- Object.defineProperty(exports, "isStale", {
355
+ Object.defineProperty(exports, "isPending", {
354
356
  enumerable: true,
355
- get: function () { return signals.isStale; }
357
+ get: function () { return signals.isPending; }
356
358
  });
357
359
  Object.defineProperty(exports, "isWrappable", {
358
360
  enumerable: true,
@@ -390,6 +392,10 @@ Object.defineProperty(exports, "resolve", {
390
392
  enumerable: true,
391
393
  get: function () { return signals.resolve; }
392
394
  });
395
+ Object.defineProperty(exports, "runWithObserver", {
396
+ enumerable: true,
397
+ get: function () { return signals.runWithObserver; }
398
+ });
393
399
  Object.defineProperty(exports, "runWithOwner", {
394
400
  enumerable: true,
395
401
  get: function () { return signals.runWithOwner; }
package/dist/dev.js CHANGED
@@ -1,15 +1,66 @@
1
- import { createEffect, getContext, createMemo, flatten, setContext, untrack, createRoot, getOwner, onCleanup, createSignal, createAsync, mapArray, repeat, createErrorBoundary, createSuspense } from '@solidjs/signals';
2
- export { $PROXY, $RAW, $TRACK, catchError, createAsync, createEffect, createMemo, createProjection, createReaction, createRenderEffect, createRoot, createSignal, createStore, flatten, flushSync, getObserver, getOwner, isEqual, isStale, isWrappable, latest, mapArray, merge, omit, onCleanup, reconcile, repeat, resolve, runWithOwner, untrack, unwrap } from '@solidjs/signals';
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";
3
51
 
4
- const $DEVCOMP = Symbol("COMPONENT_DEV" );
52
+ const $DEVCOMP = Symbol("COMPONENT_DEV");
5
53
  function onMount(fn) {
6
54
  createEffect(() => null, fn);
7
55
  }
8
56
  function createContext(defaultValue, options) {
9
- const id = Symbol(options && options.name || "");
57
+ const id = Symbol((options && options.name) || "");
10
58
  function provider(props) {
11
59
  return createMemo(() => {
12
- setContext(provider, untrack(() => props.value));
60
+ setContext(
61
+ provider,
62
+ untrack(() => props.value)
63
+ );
13
64
  return children(() => props.children);
14
65
  });
15
66
  }
@@ -24,7 +75,7 @@ function children(fn) {
24
75
  const children = createMemo(fn);
25
76
  const memo = createMemo(() => flatten(children()), undefined, {
26
77
  name: "children"
27
- }) ;
78
+ });
28
79
  memo.toArray = () => {
29
80
  const c = memo();
30
81
  return Array.isArray(c) ? c : c != null ? [c] : [];
@@ -48,7 +99,8 @@ function devComponent(Comp, props) {
48
99
  function registerGraph(value) {
49
100
  const owner = getOwner();
50
101
  if (!owner) return;
51
- if (owner.sourceMap) owner.sourceMap.push(value);else owner.sourceMap = [value];
102
+ if (owner.sourceMap) owner.sourceMap.push(value);
103
+ else owner.sourceMap = [value];
52
104
  value.graph = owner;
53
105
  }
54
106
 
@@ -58,16 +110,20 @@ function observable(input) {
58
110
  if (!(observer instanceof Object) || observer == null) {
59
111
  throw new TypeError("Expected the observer to be an object.");
60
112
  }
61
- const handler = typeof observer === "function" ? observer : observer.next && observer.next.bind(observer);
113
+ const handler =
114
+ typeof observer === "function" ? observer : observer.next && observer.next.bind(observer);
62
115
  if (!handler) {
63
116
  return {
64
117
  unsubscribe() {}
65
118
  };
66
119
  }
67
120
  const dispose = createRoot(disposer => {
68
- createEffect(() => input(), v => {
69
- handler(v);
70
- });
121
+ createEffect(
122
+ () => input(),
123
+ v => {
124
+ handler(v);
125
+ }
126
+ );
71
127
  return disposer;
72
128
  });
73
129
  if (getOwner()) onCleanup(dispose);
@@ -82,13 +138,13 @@ function observable(input) {
82
138
  }
83
139
  };
84
140
  }
85
- function from(producer) {
86
- const [s, set] = createSignal(undefined, {
141
+ function from(producer, initialValue = undefined) {
142
+ const [s, set] = createSignal(() => initialValue, initialValue, {
87
143
  equals: false
88
144
  });
89
145
  if ("subscribe" in producer) {
90
146
  const unsub = producer.subscribe(v => set(() => v));
91
- onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub());
147
+ onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub()));
92
148
  } else {
93
149
  const clean = producer(set);
94
150
  onCleanup(clean);
@@ -132,7 +188,7 @@ function createComponent(Comp, props) {
132
188
  if (sharedConfig.context) {
133
189
  const c = sharedConfig.context;
134
190
  setHydrateContext(nextHydrateContext());
135
- const r = devComponent(Comp, props || {}) ;
191
+ const r = devComponent(Comp, props || {});
136
192
  setHydrateContext(c);
137
193
  return r;
138
194
  }
@@ -160,19 +216,23 @@ function lazy(fn) {
160
216
  comp = s;
161
217
  }
162
218
  let Comp;
163
- return createMemo(() => (Comp = comp()) ? untrack(() => {
164
- Object.assign(Comp, {
165
- [$DEVCOMP]: true
166
- });
167
- if (!ctx || sharedConfig.done) return Comp(props);
168
- const c = sharedConfig.context;
169
- setHydrateContext(ctx);
170
- const r = Comp(props);
171
- setHydrateContext(c);
172
- return r;
173
- }) : "");
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
+ );
174
234
  };
175
- wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
235
+ wrap.preload = () => p || ((p = fn()).then(mod => (comp = () => mod.default)), p);
176
236
  return wrap;
177
237
  }
178
238
  let counter = 0;
@@ -181,100 +241,176 @@ function createUniqueId() {
181
241
  return ctx ? sharedConfig.getNextContextId() : `cl-${counter++}`;
182
242
  }
183
243
 
184
- 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.` ;
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.`;
185
246
  function For(props) {
186
- const options = "fallback" in props ? {
187
- keyed: props.keyed,
188
- fallback: () => props.fallback
189
- } : {
190
- keyed: props.keyed
191
- };
192
- return createMemo(mapArray(() => props.each, props.children, options), undefined, {
193
- name: "value"
194
- }) ;
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
+ );
195
263
  }
196
264
  function Repeat(props) {
197
- const options = "fallback" in props ? {
198
- fallback: () => props.fallback
199
- } : {};
200
- return createMemo(repeat(() => props.count, index => typeof props.children === "function" ? props.children(index) : props.children, options), undefined, {
201
- name: "value"
202
- }) ;
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
+ );
203
282
  }
204
283
  function Show(props) {
205
284
  const keyed = props.keyed;
206
- const condition = createMemo(() => props.when, undefined, {
207
- equals: (a, b) => keyed ? a === b : !a === !b,
208
- name: "condition"
209
- } );
210
- return createMemo(() => {
211
- const c = condition();
212
- if (c) {
213
- const child = props.children;
214
- const fn = typeof child === "function" && child.length > 0;
215
- return fn ? untrack(() => child(() => {
216
- if (!untrack(condition)) throw narrowedError("Show");
217
- return props.when;
218
- })) : child;
285
+ const conditionValue = createMemo(() => props.when, undefined, {
286
+ 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"
219
314
  }
220
- return props.fallback;
221
- }, undefined, {
222
- name: "value"
223
- } );
315
+ );
224
316
  }
225
317
  function Switch(props) {
226
- let keyed = false;
227
- const equals = (a, b) => (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2];
228
- const conditions = children(() => props.children),
229
- evalConditions = createMemo(() => {
230
- let conds = conditions();
231
- if (!Array.isArray(conds)) conds = [conds];
232
- for (let i = 0; i < conds.length; i++) {
233
- const c = conds[i].when;
234
- if (c) {
235
- keyed = !!conds[i].keyed;
236
- return [i, c, conds[i]];
237
- }
238
- }
239
- return [-1];
240
- }, undefined, {
241
- equals,
318
+ const chs = children(() => props.children);
319
+ const switchFunc = createMemo(() => {
320
+ const ch = chs();
321
+ const mps = Array.isArray(ch) ? ch : [ch];
322
+ let func = () => undefined;
323
+ for (let i = 0; i < mps.length; i++) {
324
+ const index = i;
325
+ const mp = mps[i];
326
+ const prevFunc = func;
327
+ const conditionValue = createMemo(() => (prevFunc() ? undefined : mp.when), undefined, {
328
+ 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
+ });
336
+ func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
337
+ }
338
+ return func;
339
+ });
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
+ {
242
358
  name: "eval conditions"
243
- } );
244
- return createMemo(() => {
245
- const [index, when, cond] = evalConditions();
246
- if (index < 0) return props.fallback;
247
- const c = cond.children;
248
- const fn = typeof c === "function" && c.length > 0;
249
- return fn ? untrack(() => c(() => {
250
- if (untrack(evalConditions)[0] !== index) throw narrowedError("Match");
251
- return cond.when;
252
- })) : c;
253
- }, undefined, {
254
- name: "value"
255
- } );
359
+ }
360
+ );
256
361
  }
257
362
  function Match(props) {
258
363
  return props;
259
364
  }
260
365
  function ErrorBoundary(props) {
261
- return createErrorBoundary(() => props.children, (err, reset) => {
262
- const f = props.fallback;
263
- if ((typeof f !== "function" || f.length == 0)) console.error(err);
264
- return typeof f === "function" && f.length ? f(err, reset) : f;
265
- });
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
+ );
266
374
  }
267
375
  function Suspense(props) {
268
- return createSuspense(() => props.children, () => props.fallback);
376
+ return createSuspense(
377
+ () => props.children,
378
+ () => props.fallback
379
+ );
269
380
  }
270
381
 
271
382
  const DevHooks = {};
272
383
  const DEV = {
273
384
  hooks: DevHooks,
274
385
  registerGraph
275
- } ;
386
+ };
276
387
  if (globalThis) {
277
- if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
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
+ );
278
393
  }
279
394
 
280
- export { $DEVCOMP, DEV, ErrorBoundary, For, Match, Repeat, Show, Suspense, Switch, children, createComponent, createContext, createUniqueId, enableHydration, from, lazy, observable, onMount, sharedConfig, useContext };
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
+ };