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

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.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
- createReaction,
28
- createRenderEffect,
29
- createRoot,
30
- createSignal,
31
- createStore,
32
- flatten,
33
- flushSync,
34
- getObserver,
35
- getOwner,
36
- isEqual,
37
- isStale,
38
- isWrappable,
39
- latest,
40
- mapArray,
41
- merge,
42
- omit,
43
- onCleanup,
44
- reconcile,
45
- repeat,
46
- resolve,
47
- runWithOwner,
48
- untrack,
49
- unwrap
50
- } from "@solidjs/signals";
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';
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
11
  return createMemo(() => {
60
- setContext(
61
- provider,
62
- untrack(() => props.value)
63
- );
12
+ setContext(provider, untrack(() => 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) {
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);
@@ -188,7 +132,7 @@ function createComponent(Comp, props) {
188
132
  if (sharedConfig.context) {
189
133
  const c = sharedConfig.context;
190
134
  setHydrateContext(nextHydrateContext());
191
- const r = devComponent(Comp, props || {});
135
+ const r = devComponent(Comp, props || {}) ;
192
136
  setHydrateContext(c);
193
137
  return r;
194
138
  }
@@ -216,23 +160,19 @@ function lazy(fn) {
216
160
  comp = s;
217
161
  }
218
162
  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
- );
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
+ }) : "");
234
174
  };
235
- wrap.preload = () => p || ((p = fn()).then(mod => (comp = () => mod.default)), p);
175
+ wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
236
176
  return wrap;
237
177
  }
238
178
  let counter = 0;
@@ -241,170 +181,100 @@ function createUniqueId() {
241
181
  return ctx ? sharedConfig.getNextContextId() : `cl-${counter++}`;
242
182
  }
243
183
 
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.`;
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.` ;
246
185
  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
- );
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
+ }) ;
263
195
  }
264
196
  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
- );
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
+ }) ;
282
203
  }
283
204
  function Show(props) {
284
205
  const keyed = props.keyed;
285
206
  const condition = createMemo(() => props.when, undefined, {
286
- equals: (a, b) => (keyed ? a === b : !a === !b),
207
+ equals: (a, b) => keyed ? a === b : !a === !b,
287
208
  name: "condition"
288
- });
289
- return createMemo(
290
- () => {
291
- const c = condition();
292
- if (c) {
293
- const child = props.children;
294
- const fn = typeof child === "function" && child.length > 0;
295
- return fn
296
- ? untrack(() =>
297
- child(() => {
298
- if (!untrack(condition)) throw narrowedError("Show");
299
- return props.when;
300
- })
301
- )
302
- : child;
303
- }
304
- return props.fallback;
305
- },
306
- undefined,
307
- {
308
- name: "value"
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;
309
219
  }
310
- );
220
+ return props.fallback;
221
+ }, undefined, {
222
+ name: "value"
223
+ } );
311
224
  }
312
225
  function Switch(props) {
313
226
  let keyed = false;
314
227
  const equals = (a, b) => (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2];
315
228
  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
- }
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]];
326
237
  }
327
- return [-1];
328
- },
329
- undefined,
330
- {
331
- equals,
332
- name: "eval conditions"
333
238
  }
334
- );
335
- return createMemo(
336
- () => {
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;
341
- return fn
342
- ? untrack(() =>
343
- c(() => {
344
- if (untrack(evalConditions)[0] !== index) throw narrowedError("Match");
345
- return cond.when;
346
- })
347
- )
348
- : c;
349
- },
350
- undefined,
351
- {
352
- name: "value"
353
- }
354
- );
239
+ return [-1];
240
+ }, undefined, {
241
+ equals,
242
+ 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
+ } );
355
256
  }
356
257
  function Match(props) {
357
258
  return props;
358
259
  }
359
260
  function ErrorBoundary(props) {
360
- return createErrorBoundary(
361
- () => props.children,
362
- (err, reset) => {
363
- const f = props.fallback;
364
- if (typeof f !== "function" || f.length == 0) console.error(err);
365
- return typeof f === "function" && f.length ? f(err, reset) : f;
366
- }
367
- );
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
+ });
368
266
  }
369
267
  function Suspense(props) {
370
- return createSuspense(
371
- () => props.children,
372
- () => props.fallback
373
- );
268
+ return createSuspense(() => props.children, () => props.fallback);
374
269
  }
375
270
 
376
271
  const DevHooks = {};
377
272
  const DEV = {
378
273
  hooks: DevHooks,
379
274
  registerGraph
380
- };
275
+ } ;
381
276
  if (globalThis) {
382
- if (!globalThis.Solid$$) globalThis.Solid$$ = true;
383
- else
384
- console.warn(
385
- "You appear to have multiple instances of Solid. This can lead to unexpected behavior."
386
- );
277
+ if (!globalThis.Solid$$) globalThis.Solid$$ = true;else console.warn("You appear to have multiple instances of Solid. This can lead to unexpected behavior.");
387
278
  }
388
279
 
389
- export {
390
- $DEVCOMP,
391
- DEV,
392
- ErrorBoundary,
393
- For,
394
- Match,
395
- Repeat,
396
- Show,
397
- Suspense,
398
- Switch,
399
- children,
400
- createComponent,
401
- createContext,
402
- createUniqueId,
403
- enableHydration,
404
- from,
405
- lazy,
406
- observable,
407
- onMount,
408
- sharedConfig,
409
- useContext
410
- };
280
+ export { $DEVCOMP, DEV, ErrorBoundary, For, Match, Repeat, Show, Suspense, Switch, children, createComponent, createContext, createUniqueId, enableHydration, from, lazy, observable, onMount, sharedConfig, useContext };