solid-js 2.0.0-experimental.0 → 2.0.0-experimental.2

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
@@ -24,7 +24,6 @@ export {
24
24
  createEffect,
25
25
  createMemo,
26
26
  createProjection,
27
- createReaction,
28
27
  createRenderEffect,
29
28
  createRoot,
30
29
  createSignal,
@@ -34,7 +33,7 @@ export {
34
33
  getObserver,
35
34
  getOwner,
36
35
  isEqual,
37
- isStale,
36
+ isPending,
38
37
  isWrappable,
39
38
  latest,
40
39
  mapArray,
@@ -44,6 +43,7 @@ export {
44
43
  reconcile,
45
44
  repeat,
46
45
  resolve,
46
+ runWithObserver,
47
47
  runWithOwner,
48
48
  untrack,
49
49
  unwrap
@@ -138,8 +138,8 @@ function observable(input) {
138
138
  }
139
139
  };
140
140
  }
141
- function from(producer) {
142
- const [s, set] = createSignal(undefined, {
141
+ function from(producer, initialValue = undefined) {
142
+ const [s, set] = createSignal(() => initialValue, initialValue, {
143
143
  equals: false
144
144
  });
145
145
  if ("subscribe" in producer) {
@@ -282,10 +282,15 @@ function Repeat(props) {
282
282
  }
283
283
  function Show(props) {
284
284
  const keyed = props.keyed;
285
- const condition = createMemo(() => props.when, undefined, {
286
- equals: (a, b) => (keyed ? a === b : !a === !b),
287
- name: "condition"
285
+ const conditionValue = createMemo(() => props.when, undefined, {
286
+ name: "condition value"
288
287
  });
288
+ const condition = keyed
289
+ ? conditionValue
290
+ : createMemo(conditionValue, undefined, {
291
+ equals: (a, b) => !a === !b,
292
+ name: "condition"
293
+ });
289
294
  return createMemo(
290
295
  () => {
291
296
  const c = condition();
@@ -296,7 +301,7 @@ function Show(props) {
296
301
  ? untrack(() =>
297
302
  child(() => {
298
303
  if (!untrack(condition)) throw narrowedError("Show");
299
- return props.when;
304
+ return conditionValue();
300
305
  })
301
306
  )
302
307
  : child;
@@ -310,46 +315,47 @@ function Show(props) {
310
315
  );
311
316
  }
312
317
  function Switch(props) {
313
- let keyed = false;
314
- const equals = (a, b) => (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2];
315
- const conditions = children(() => props.children),
316
- evalConditions = createMemo(
317
- () => {
318
- let conds = conditions();
319
- if (!Array.isArray(conds)) conds = [conds];
320
- for (let i = 0; i < conds.length; i++) {
321
- const c = conds[i].when;
322
- if (c) {
323
- keyed = !!conds[i].keyed;
324
- return [i, c, conds[i]];
325
- }
326
- }
327
- return [-1];
328
- },
329
- undefined,
330
- {
331
- equals,
332
- name: "eval conditions"
333
- }
334
- );
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
+ });
335
340
  return createMemo(
336
341
  () => {
337
- const [index, when, cond] = evalConditions();
338
- if (index < 0) return props.fallback;
339
- const c = cond.children;
340
- const fn = typeof c === "function" && c.length > 0;
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;
341
347
  return fn
342
348
  ? untrack(() =>
343
- c(() => {
344
- if (untrack(evalConditions)[0] !== index) throw narrowedError("Match");
345
- return cond.when;
349
+ child(() => {
350
+ if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
351
+ return conditionValue();
346
352
  })
347
353
  )
348
- : c;
354
+ : child;
349
355
  },
350
356
  undefined,
351
357
  {
352
- name: "value"
358
+ name: "eval conditions"
353
359
  }
354
360
  );
355
361
  }
package/dist/solid.cjs CHANGED
@@ -61,8 +61,8 @@ function observable(input) {
61
61
  }
62
62
  };
63
63
  }
64
- function from(producer) {
65
- const [s, set] = signals.createSignal(undefined, {
64
+ function from(producer, initialValue = undefined) {
65
+ const [s, set] = signals.createSignal(() => initialValue, initialValue, {
66
66
  equals: false
67
67
  });
68
68
  if ("subscribe" in producer) {
@@ -175,8 +175,9 @@ function Repeat(props) {
175
175
  }
176
176
  function Show(props) {
177
177
  const keyed = props.keyed;
178
- const condition = signals.createMemo(() => props.when, undefined, {
179
- equals: (a, b) => keyed ? a === b : !a === !b
178
+ const conditionValue = signals.createMemo(() => props.when, undefined, undefined);
179
+ const condition = keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
180
+ equals: (a, b) => !a === !b
180
181
  });
181
182
  return signals.createMemo(() => {
182
183
  const c = condition();
@@ -185,39 +186,40 @@ function Show(props) {
185
186
  const fn = typeof child === "function" && child.length > 0;
186
187
  return fn ? signals.untrack(() => child(() => {
187
188
  if (!signals.untrack(condition)) throw narrowedError("Show");
188
- return props.when;
189
+ return conditionValue();
189
190
  })) : child;
190
191
  }
191
192
  return props.fallback;
192
193
  }, undefined, undefined);
193
194
  }
194
195
  function Switch(props) {
195
- let keyed = false;
196
- const equals = (a, b) => (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2];
197
- const conditions = children(() => props.children),
198
- evalConditions = signals.createMemo(() => {
199
- let conds = conditions();
200
- if (!Array.isArray(conds)) conds = [conds];
201
- for (let i = 0; i < conds.length; i++) {
202
- const c = conds[i].when;
203
- if (c) {
204
- keyed = !!conds[i].keyed;
205
- return [i, c, conds[i]];
206
- }
207
- }
208
- return [-1];
209
- }, undefined, {
210
- equals
211
- });
196
+ const chs = children(() => props.children);
197
+ const switchFunc = signals.createMemo(() => {
198
+ const ch = chs();
199
+ const mps = Array.isArray(ch) ? ch : [ch];
200
+ let func = () => undefined;
201
+ for (let i = 0; i < mps.length; i++) {
202
+ const index = i;
203
+ const mp = mps[i];
204
+ const prevFunc = func;
205
+ const conditionValue = signals.createMemo(() => prevFunc() ? undefined : mp.when, undefined, undefined);
206
+ const condition = mp.keyed ? conditionValue : signals.createMemo(conditionValue, undefined, {
207
+ equals: (a, b) => !a === !b
208
+ });
209
+ func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
210
+ }
211
+ return func;
212
+ });
212
213
  return signals.createMemo(() => {
213
- const [index, when, cond] = evalConditions();
214
- if (index < 0) return props.fallback;
215
- const c = cond.children;
216
- const fn = typeof c === "function" && c.length > 0;
217
- return fn ? signals.untrack(() => c(() => {
218
- if (signals.untrack(evalConditions)[0] !== index) throw narrowedError("Match");
219
- return cond.when;
220
- })) : c;
214
+ const sel = switchFunc()();
215
+ if (!sel) return props.fallback;
216
+ const [index, conditionValue, mp] = sel;
217
+ const child = mp.children;
218
+ const fn = typeof child === "function" && child.length > 0;
219
+ return fn ? signals.untrack(() => child(() => {
220
+ if (signals.untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
221
+ return conditionValue();
222
+ })) : child;
221
223
  }, undefined, undefined);
222
224
  }
223
225
  function Match(props) {
@@ -267,10 +269,6 @@ Object.defineProperty(exports, "createProjection", {
267
269
  enumerable: true,
268
270
  get: function () { return signals.createProjection; }
269
271
  });
270
- Object.defineProperty(exports, "createReaction", {
271
- enumerable: true,
272
- get: function () { return signals.createReaction; }
273
- });
274
272
  Object.defineProperty(exports, "createRenderEffect", {
275
273
  enumerable: true,
276
274
  get: function () { return signals.createRenderEffect; }
@@ -307,9 +305,9 @@ Object.defineProperty(exports, "isEqual", {
307
305
  enumerable: true,
308
306
  get: function () { return signals.isEqual; }
309
307
  });
310
- Object.defineProperty(exports, "isStale", {
308
+ Object.defineProperty(exports, "isPending", {
311
309
  enumerable: true,
312
- get: function () { return signals.isStale; }
310
+ get: function () { return signals.isPending; }
313
311
  });
314
312
  Object.defineProperty(exports, "isWrappable", {
315
313
  enumerable: true,
@@ -347,6 +345,10 @@ Object.defineProperty(exports, "resolve", {
347
345
  enumerable: true,
348
346
  get: function () { return signals.resolve; }
349
347
  });
348
+ Object.defineProperty(exports, "runWithObserver", {
349
+ enumerable: true,
350
+ get: function () { return signals.runWithObserver; }
351
+ });
350
352
  Object.defineProperty(exports, "runWithOwner", {
351
353
  enumerable: true,
352
354
  get: function () { return signals.runWithOwner; }
package/dist/solid.js CHANGED
@@ -24,7 +24,6 @@ export {
24
24
  createEffect,
25
25
  createMemo,
26
26
  createProjection,
27
- createReaction,
28
27
  createRenderEffect,
29
28
  createRoot,
30
29
  createSignal,
@@ -34,7 +33,7 @@ export {
34
33
  getObserver,
35
34
  getOwner,
36
35
  isEqual,
37
- isStale,
36
+ isPending,
38
37
  isWrappable,
39
38
  latest,
40
39
  mapArray,
@@ -44,6 +43,7 @@ export {
44
43
  reconcile,
45
44
  repeat,
46
45
  resolve,
46
+ runWithObserver,
47
47
  runWithOwner,
48
48
  untrack,
49
49
  unwrap
@@ -115,8 +115,8 @@ function observable(input) {
115
115
  }
116
116
  };
117
117
  }
118
- function from(producer) {
119
- const [s, set] = createSignal(undefined, {
118
+ function from(producer, initialValue = undefined) {
119
+ const [s, set] = createSignal(() => initialValue, initialValue, {
120
120
  equals: false
121
121
  });
122
122
  if ("subscribe" in producer) {
@@ -245,9 +245,12 @@ function Repeat(props) {
245
245
  }
246
246
  function Show(props) {
247
247
  const keyed = props.keyed;
248
- const condition = createMemo(() => props.when, undefined, {
249
- equals: (a, b) => (keyed ? a === b : !a === !b)
250
- });
248
+ const conditionValue = createMemo(() => props.when, undefined, undefined);
249
+ const condition = keyed
250
+ ? conditionValue
251
+ : createMemo(conditionValue, undefined, {
252
+ equals: (a, b) => !a === !b
253
+ });
251
254
  return createMemo(
252
255
  () => {
253
256
  const c = condition();
@@ -258,7 +261,7 @@ function Show(props) {
258
261
  ? untrack(() =>
259
262
  child(() => {
260
263
  if (!untrack(condition)) throw narrowedError("Show");
261
- return props.when;
264
+ return conditionValue();
262
265
  })
263
266
  )
264
267
  : child;
@@ -270,41 +273,44 @@ function Show(props) {
270
273
  );
271
274
  }
272
275
  function Switch(props) {
273
- let keyed = false;
274
- const equals = (a, b) => (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2];
275
- const conditions = children(() => props.children),
276
- evalConditions = createMemo(
277
- () => {
278
- let conds = conditions();
279
- if (!Array.isArray(conds)) conds = [conds];
280
- for (let i = 0; i < conds.length; i++) {
281
- const c = conds[i].when;
282
- if (c) {
283
- keyed = !!conds[i].keyed;
284
- return [i, c, conds[i]];
285
- }
286
- }
287
- return [-1];
288
- },
289
- undefined,
290
- {
291
- equals
292
- }
293
- );
276
+ const chs = children(() => props.children);
277
+ const switchFunc = createMemo(() => {
278
+ const ch = chs();
279
+ const mps = Array.isArray(ch) ? ch : [ch];
280
+ let func = () => undefined;
281
+ for (let i = 0; i < mps.length; i++) {
282
+ const index = i;
283
+ const mp = mps[i];
284
+ const prevFunc = func;
285
+ const conditionValue = createMemo(
286
+ () => (prevFunc() ? undefined : mp.when),
287
+ undefined,
288
+ undefined
289
+ );
290
+ const condition = mp.keyed
291
+ ? conditionValue
292
+ : createMemo(conditionValue, undefined, {
293
+ equals: (a, b) => !a === !b
294
+ });
295
+ func = () => prevFunc() || (condition() ? [index, conditionValue, mp] : undefined);
296
+ }
297
+ return func;
298
+ });
294
299
  return createMemo(
295
300
  () => {
296
- const [index, when, cond] = evalConditions();
297
- if (index < 0) return props.fallback;
298
- const c = cond.children;
299
- const fn = typeof c === "function" && c.length > 0;
301
+ const sel = switchFunc()();
302
+ if (!sel) return props.fallback;
303
+ const [index, conditionValue, mp] = sel;
304
+ const child = mp.children;
305
+ const fn = typeof child === "function" && child.length > 0;
300
306
  return fn
301
307
  ? untrack(() =>
302
- c(() => {
303
- if (untrack(evalConditions)[0] !== index) throw narrowedError("Match");
304
- return cond.when;
308
+ child(() => {
309
+ if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
310
+ return conditionValue();
305
311
  })
306
312
  )
307
- : c;
313
+ : child;
308
314
  },
309
315
  undefined,
310
316
  undefined
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": "2.0.0-experimental.0",
4
+ "version": "2.0.0-experimental.2",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://solidjs.com",
@@ -79,7 +79,7 @@
79
79
  "performance"
80
80
  ],
81
81
  "dependencies": {
82
- "@solidjs/signals": "^0.0.10",
82
+ "@solidjs/signals": "^0.2.1",
83
83
  "csstype": "^3.1.0"
84
84
  },
85
85
  "scripts": {
@@ -28,15 +28,15 @@ export type ObservableObserver<T> =
28
28
  * description https://docs.solidjs.com/reference/reactive-utilities/observable
29
29
  */
30
30
  export declare function observable<T>(input: Accessor<T>): Observable<T>;
31
- export declare function from<T>(
32
- producer:
33
- | ((setter: Setter<T | undefined>) => () => void)
34
- | {
35
- subscribe: (fn: (v: T) => void) =>
36
- | (() => void)
37
- | {
38
- unsubscribe: () => void;
39
- };
40
- }
41
- ): Accessor<T | undefined>;
31
+ type Producer<T> =
32
+ | ((setter: Setter<T>) => () => void)
33
+ | {
34
+ subscribe: (fn: (v: T) => void) =>
35
+ | (() => void)
36
+ | {
37
+ unsubscribe: () => void;
38
+ };
39
+ };
40
+ export declare function from<T>(producer: Producer<T>, initalValue: T): Accessor<T>;
41
+ export declare function from<T>(producer: Producer<T | undefined>): Accessor<T | undefined>;
42
42
  export {};
package/types/index.d.ts CHANGED
@@ -7,7 +7,6 @@ export {
7
7
  createEffect,
8
8
  createMemo,
9
9
  createProjection,
10
- createReaction,
11
10
  createRenderEffect,
12
11
  createRoot,
13
12
  createSignal,
@@ -17,7 +16,7 @@ export {
17
16
  getObserver,
18
17
  getOwner,
19
18
  isEqual,
20
- isStale,
19
+ isPending,
21
20
  isWrappable,
22
21
  latest,
23
22
  mapArray,
@@ -27,6 +26,7 @@ export {
27
26
  reconcile,
28
27
  repeat,
29
28
  resolve,
29
+ runWithObserver,
30
30
  runWithOwner,
31
31
  untrack,
32
32
  unwrap