solid-js 1.2.5 → 1.3.0-beta.0

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/solid.cjs CHANGED
@@ -184,12 +184,13 @@ function createSignal(value, options) {
184
184
  pending: NOTPENDING,
185
185
  comparator: options.equals || undefined
186
186
  };
187
- return [readSignal.bind(s), value => {
187
+ const setter = value => {
188
188
  if (typeof value === "function") {
189
189
  if (Transition && Transition.running && Transition.sources.has(s)) value = value(s.pending !== NOTPENDING ? s.pending : s.tValue);else value = value(s.pending !== NOTPENDING ? s.pending : s.value);
190
190
  }
191
191
  return writeSignal(s, value);
192
- }];
192
+ };
193
+ return [readSignal.bind(s), setter];
193
194
  }
194
195
  function createComputed(fn, value, options) {
195
196
  const c = createComputation(fn, value, true, STALE);
@@ -246,12 +247,7 @@ function createResource(source, fetcher, options) {
246
247
  dynamic = typeof source === "function";
247
248
  if (sharedConfig.context) {
248
249
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
249
- if (sharedConfig.context.loadResource) {
250
- initP = sharedConfig.context.loadResource(id);
251
- } else if (sharedConfig.resources && id && id in sharedConfig.resources) {
252
- initP = sharedConfig.resources[id];
253
- delete sharedConfig.resources[id];
254
- }
250
+ if (sharedConfig.load) initP = sharedConfig.load(id);
255
251
  }
256
252
  function loadEnd(p, v, e) {
257
253
  if (pr === p) {
@@ -406,7 +402,8 @@ function untrack(fn) {
406
402
  Listener = listener;
407
403
  return result;
408
404
  }
409
- function on(deps, fn, options) {
405
+ function on(deps, fn,
406
+ options) {
410
407
  const isArray = Array.isArray(deps);
411
408
  let prevInput;
412
409
  let defer = options && options.defer;
@@ -1161,7 +1158,7 @@ function lazy(fn) {
1161
1158
  let comp;
1162
1159
  const wrap = props => {
1163
1160
  const ctx = sharedConfig.context;
1164
- if (ctx && sharedConfig.resources) {
1161
+ if (ctx) {
1165
1162
  ctx.count++;
1166
1163
  const [s, set] = createSignal();
1167
1164
  fn().then(mod => {
@@ -1234,7 +1231,7 @@ function Switch(props) {
1234
1231
  }
1235
1232
  return [-1];
1236
1233
  }, undefined, {
1237
- equals: (a, b) => a && a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
1234
+ equals: (a, b) => a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
1238
1235
  });
1239
1236
  return createMemo(() => {
1240
1237
  const [index, when, cond] = evalConditions();
@@ -1328,7 +1325,10 @@ function SuspenseList(props) {
1328
1325
  function Suspense(props) {
1329
1326
  let counter = 0,
1330
1327
  showContent,
1331
- showFallback;
1328
+ showFallback,
1329
+ ctx,
1330
+ waitingHydration,
1331
+ flicker;
1332
1332
  const [inFallback, setFallback] = createSignal(false),
1333
1333
  SuspenseContext = getSuspenseContext(),
1334
1334
  store = {
@@ -1343,6 +1343,24 @@ function Suspense(props) {
1343
1343
  resolved: false
1344
1344
  },
1345
1345
  owner = getOwner();
1346
+ if (sharedConfig.context && sharedConfig.load) {
1347
+ const key = sharedConfig.context.id + sharedConfig.context.count;
1348
+ const p = sharedConfig.load(key);
1349
+ if (p) {
1350
+ const [s, set] = createSignal(undefined, {
1351
+ equals: false
1352
+ });
1353
+ flicker = s;
1354
+ p.then(() => {
1355
+ sharedConfig.gather(key);
1356
+ waitingHydration = true;
1357
+ setHydrateContext(ctx);
1358
+ set();
1359
+ setHydrateContext(undefined);
1360
+ waitingHydration = false;
1361
+ });
1362
+ }
1363
+ }
1346
1364
  const listContext = useContext(SuspenseListContext);
1347
1365
  if (listContext) [showContent, showFallback] = listContext.register(store.inFallback);
1348
1366
  let dispose;
@@ -1350,28 +1368,35 @@ function Suspense(props) {
1350
1368
  return createComponent(SuspenseContext.Provider, {
1351
1369
  value: store,
1352
1370
  get children() {
1353
- const rendered = untrack(() => props.children);
1354
1371
  return createMemo(() => {
1355
- const inFallback = store.inFallback(),
1356
- visibleContent = showContent ? showContent() : true,
1357
- visibleFallback = showFallback ? showFallback() : true;
1358
- dispose && dispose();
1359
- if (!inFallback && visibleContent) {
1360
- store.resolved = true;
1361
- resumeEffects(store.effects);
1362
- return rendered;
1372
+ if (flicker) {
1373
+ ctx = sharedConfig.context;
1374
+ flicker();
1375
+ return flicker = undefined;
1363
1376
  }
1364
- if (!visibleFallback) return;
1365
- return createRoot(disposer => {
1366
- dispose = disposer;
1367
- return props.fallback;
1368
- }, owner);
1377
+ const rendered = untrack(() => props.children);
1378
+ return createMemo(() => {
1379
+ const inFallback = store.inFallback(),
1380
+ visibleContent = showContent ? showContent() : true,
1381
+ visibleFallback = showFallback ? showFallback() : true;
1382
+ dispose && dispose();
1383
+ if ((!inFallback || waitingHydration) && visibleContent) {
1384
+ store.resolved = true;
1385
+ resumeEffects(store.effects);
1386
+ return rendered;
1387
+ }
1388
+ if (!visibleFallback) return;
1389
+ return createRoot(disposer => {
1390
+ dispose = disposer;
1391
+ if (sharedConfig.context) sharedConfig.context.count = 0;
1392
+ return props.fallback;
1393
+ }, owner);
1394
+ });
1369
1395
  });
1370
1396
  }
1371
1397
  });
1372
1398
  }
1373
1399
 
1374
- function awaitSuspense() {}
1375
1400
  let DEV;
1376
1401
 
1377
1402
  exports.$PROXY = $PROXY;
@@ -1384,7 +1409,6 @@ exports.Show = Show;
1384
1409
  exports.Suspense = Suspense;
1385
1410
  exports.SuspenseList = SuspenseList;
1386
1411
  exports.Switch = Switch;
1387
- exports.awaitSuspense = awaitSuspense;
1388
1412
  exports.batch = batch;
1389
1413
  exports.cancelCallback = cancelCallback;
1390
1414
  exports.children = children;
package/dist/solid.js CHANGED
@@ -180,12 +180,13 @@ function createSignal(value, options) {
180
180
  pending: NOTPENDING,
181
181
  comparator: options.equals || undefined
182
182
  };
183
- return [readSignal.bind(s), value => {
183
+ const setter = value => {
184
184
  if (typeof value === "function") {
185
185
  if (Transition && Transition.running && Transition.sources.has(s)) value = value(s.pending !== NOTPENDING ? s.pending : s.tValue);else value = value(s.pending !== NOTPENDING ? s.pending : s.value);
186
186
  }
187
187
  return writeSignal(s, value);
188
- }];
188
+ };
189
+ return [readSignal.bind(s), setter];
189
190
  }
190
191
  function createComputed(fn, value, options) {
191
192
  const c = createComputation(fn, value, true, STALE);
@@ -242,12 +243,7 @@ function createResource(source, fetcher, options) {
242
243
  dynamic = typeof source === "function";
243
244
  if (sharedConfig.context) {
244
245
  id = `${sharedConfig.context.id}${sharedConfig.context.count++}`;
245
- if (sharedConfig.context.loadResource) {
246
- initP = sharedConfig.context.loadResource(id);
247
- } else if (sharedConfig.resources && id && id in sharedConfig.resources) {
248
- initP = sharedConfig.resources[id];
249
- delete sharedConfig.resources[id];
250
- }
246
+ if (sharedConfig.load) initP = sharedConfig.load(id);
251
247
  }
252
248
  function loadEnd(p, v, e) {
253
249
  if (pr === p) {
@@ -402,7 +398,8 @@ function untrack(fn) {
402
398
  Listener = listener;
403
399
  return result;
404
400
  }
405
- function on(deps, fn, options) {
401
+ function on(deps, fn,
402
+ options) {
406
403
  const isArray = Array.isArray(deps);
407
404
  let prevInput;
408
405
  let defer = options && options.defer;
@@ -1157,7 +1154,7 @@ function lazy(fn) {
1157
1154
  let comp;
1158
1155
  const wrap = props => {
1159
1156
  const ctx = sharedConfig.context;
1160
- if (ctx && sharedConfig.resources) {
1157
+ if (ctx) {
1161
1158
  ctx.count++;
1162
1159
  const [s, set] = createSignal();
1163
1160
  fn().then(mod => {
@@ -1230,7 +1227,7 @@ function Switch(props) {
1230
1227
  }
1231
1228
  return [-1];
1232
1229
  }, undefined, {
1233
- equals: (a, b) => a && a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
1230
+ equals: (a, b) => a[0] === b[0] && (strictEqual ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2]
1234
1231
  });
1235
1232
  return createMemo(() => {
1236
1233
  const [index, when, cond] = evalConditions();
@@ -1324,7 +1321,10 @@ function SuspenseList(props) {
1324
1321
  function Suspense(props) {
1325
1322
  let counter = 0,
1326
1323
  showContent,
1327
- showFallback;
1324
+ showFallback,
1325
+ ctx,
1326
+ waitingHydration,
1327
+ flicker;
1328
1328
  const [inFallback, setFallback] = createSignal(false),
1329
1329
  SuspenseContext = getSuspenseContext(),
1330
1330
  store = {
@@ -1339,6 +1339,24 @@ function Suspense(props) {
1339
1339
  resolved: false
1340
1340
  },
1341
1341
  owner = getOwner();
1342
+ if (sharedConfig.context && sharedConfig.load) {
1343
+ const key = sharedConfig.context.id + sharedConfig.context.count;
1344
+ const p = sharedConfig.load(key);
1345
+ if (p) {
1346
+ const [s, set] = createSignal(undefined, {
1347
+ equals: false
1348
+ });
1349
+ flicker = s;
1350
+ p.then(() => {
1351
+ sharedConfig.gather(key);
1352
+ waitingHydration = true;
1353
+ setHydrateContext(ctx);
1354
+ set();
1355
+ setHydrateContext(undefined);
1356
+ waitingHydration = false;
1357
+ });
1358
+ }
1359
+ }
1342
1360
  const listContext = useContext(SuspenseListContext);
1343
1361
  if (listContext) [showContent, showFallback] = listContext.register(store.inFallback);
1344
1362
  let dispose;
@@ -1346,28 +1364,35 @@ function Suspense(props) {
1346
1364
  return createComponent(SuspenseContext.Provider, {
1347
1365
  value: store,
1348
1366
  get children() {
1349
- const rendered = untrack(() => props.children);
1350
1367
  return createMemo(() => {
1351
- const inFallback = store.inFallback(),
1352
- visibleContent = showContent ? showContent() : true,
1353
- visibleFallback = showFallback ? showFallback() : true;
1354
- dispose && dispose();
1355
- if (!inFallback && visibleContent) {
1356
- store.resolved = true;
1357
- resumeEffects(store.effects);
1358
- return rendered;
1368
+ if (flicker) {
1369
+ ctx = sharedConfig.context;
1370
+ flicker();
1371
+ return flicker = undefined;
1359
1372
  }
1360
- if (!visibleFallback) return;
1361
- return createRoot(disposer => {
1362
- dispose = disposer;
1363
- return props.fallback;
1364
- }, owner);
1373
+ const rendered = untrack(() => props.children);
1374
+ return createMemo(() => {
1375
+ const inFallback = store.inFallback(),
1376
+ visibleContent = showContent ? showContent() : true,
1377
+ visibleFallback = showFallback ? showFallback() : true;
1378
+ dispose && dispose();
1379
+ if ((!inFallback || waitingHydration) && visibleContent) {
1380
+ store.resolved = true;
1381
+ resumeEffects(store.effects);
1382
+ return rendered;
1383
+ }
1384
+ if (!visibleFallback) return;
1385
+ return createRoot(disposer => {
1386
+ dispose = disposer;
1387
+ if (sharedConfig.context) sharedConfig.context.count = 0;
1388
+ return props.fallback;
1389
+ }, owner);
1390
+ });
1365
1391
  });
1366
1392
  }
1367
1393
  });
1368
1394
  }
1369
1395
 
1370
- function awaitSuspense() {}
1371
1396
  let DEV;
1372
1397
 
1373
- export { $PROXY, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, awaitSuspense, batch, cancelCallback, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
1398
+ export { $PROXY, DEV, ErrorBoundary, For, Index, Match, Show, Suspense, SuspenseList, Switch, batch, cancelCallback, children, createComponent, createComputed, createContext, createDeferred, createEffect, createMemo, createRenderEffect, createResource, createRoot, createSelector, createSignal, createUniqueId, enableScheduling, equalFn, from, getListener, getOwner, indexArray, lazy, mapArray, mergeProps, observable, on, onCleanup, onError, onMount, requestCallback, runWithOwner, sharedConfig, splitProps, startTransition, untrack, useContext, useTransition };
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": "1.2.5",
4
+ "version": "1.3.0-beta.0",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",
7
7
  "homepage": "https://github.com/solidjs/solid#readme",
@@ -132,5 +132,5 @@
132
132
  "compiler",
133
133
  "performance"
134
134
  ],
135
- "gitHead": "faf884b19acc078f1e202030bbd6b22c49a5ae6b"
135
+ "gitHead": "4efd2be2d5180db0a4875c7c05d8fb4cd9bf44f3"
136
136
  }
package/types/index.d.ts CHANGED
@@ -7,7 +7,6 @@ export * from "./render";
7
7
  import type { JSX } from "./jsx";
8
8
  declare type JSXElement = JSX.Element;
9
9
  export type { JSXElement, JSX };
10
- export declare function awaitSuspense(): void;
11
10
  import { writeSignal, serializeGraph, registerGraph, hashValue } from "./reactive/signal";
12
11
  declare let DEV: {
13
12
  writeSignal: typeof writeSignal;
@@ -1,16 +1,14 @@
1
1
  import { requestCallback } from "./scheduler";
2
2
  import type { JSX } from "../jsx";
3
- export declare type Accessor<T> = () => T;
4
- export declare type Setter<T> = undefined extends T ? <U extends T>(v?: (U extends Function ? never : U) | ((prev?: T) => U)) => U : <U extends T>(v: (U extends Function ? never : U) | ((prev: T) => U)) => U;
5
3
  export declare const equalFn: <T>(a: T, b: T) => boolean;
6
4
  export declare const $PROXY: unique symbol;
7
5
  export declare const NOTPENDING: {};
8
6
  export declare var Owner: Owner | null;
9
- export declare let Transition: Transition | null;
7
+ export declare let Transition: TransitionState | null;
10
8
  declare global {
11
9
  var _$afterUpdate: () => void;
12
10
  }
13
- interface Signal<T> {
11
+ export interface SignalState<T> {
14
12
  value?: T;
15
13
  observers: Computation<any>[] | null;
16
14
  observerSlots: number[] | null;
@@ -19,7 +17,7 @@ interface Signal<T> {
19
17
  comparator?: (prev: T, next: T) => boolean;
20
18
  name?: string;
21
19
  }
22
- interface Owner {
20
+ export interface Owner {
23
21
  owned: Computation<any>[] | null;
24
22
  cleanups: (() => void)[] | null;
25
23
  owner: Owner | null;
@@ -30,23 +28,20 @@ interface Owner {
30
28
  name?: string;
31
29
  componentName?: string;
32
30
  }
33
- interface Computation<T> extends Owner {
34
- fn: (v?: T) => T;
31
+ export interface Computation<Init, Next extends Init = Init> extends Owner {
32
+ fn: EffectFunction<Init, Next>;
35
33
  state: number;
36
34
  tState?: number;
37
- sources: Signal<T>[] | null;
35
+ sources: SignalState<Next>[] | null;
38
36
  sourceSlots: number[] | null;
39
- value?: T;
37
+ value?: Init;
40
38
  updatedAt: number | null;
41
39
  pure: boolean;
42
40
  user?: boolean;
43
41
  suspense?: SuspenseContextType;
44
42
  }
45
- interface Memo<T> extends Signal<T>, Computation<T> {
46
- tOwned?: Computation<any>[];
47
- }
48
- interface Transition {
49
- sources: Set<Signal<any>>;
43
+ export interface TransitionState {
44
+ sources: Set<SignalState<any>>;
50
45
  effects: Computation<any>[];
51
46
  promises: Set<Promise<any>>;
52
47
  disposed: Set<Computation<any>>;
@@ -55,6 +50,7 @@ interface Transition {
55
50
  running: boolean;
56
51
  cb: (() => void)[];
57
52
  }
53
+ export declare type RootFunction<T> = (dispose: () => void) => T;
58
54
  /**
59
55
  * Creates a new non-tracked reactive context that doesn't auto-dispose
60
56
  *
@@ -64,11 +60,13 @@ interface Transition {
64
60
  *
65
61
  * @description https://www.solidjs.com/docs/latest/api#createroot
66
62
  */
67
- export declare function createRoot<T>(fn: (dispose: () => void) => T, detachedOwner?: Owner): T;
68
- export declare type SignalOptions<T> = {
69
- name?: string;
70
- equals?: false | ((prev: T, next: T) => boolean);
71
- };
63
+ export declare function createRoot<T>(fn: RootFunction<T>, detachedOwner?: Owner): T;
64
+ export declare type Accessor<T> = () => T;
65
+ export declare type Setter<T> = undefined extends T ? <U extends T>(value?: (U extends Function ? never : U) | ((prev?: T) => U)) => U : <U extends T>(value: (U extends Function ? never : U) | ((prev: T) => U)) => U;
66
+ export declare type Signal<T> = [get: Accessor<T>, set: Setter<T>];
67
+ export interface SignalOptions<T> extends MemoOptions<T> {
68
+ internal?: boolean;
69
+ }
72
70
  /**
73
71
  * Creates a simple reactive state with a getter and setter
74
72
  * ```typescript
@@ -92,18 +90,21 @@ export declare type SignalOptions<T> = {
92
90
  *
93
91
  * @description https://www.solidjs.com/docs/latest/api#createsignal
94
92
  */
95
- export declare function createSignal<T>(): [get: Accessor<T | undefined>, set: Setter<T | undefined>];
96
- export declare function createSignal<T>(value: T, options?: {
97
- equals?: false | ((prev: T, next: T) => boolean);
93
+ export declare function createSignal<T>(): Signal<T | undefined>;
94
+ export declare function createSignal<T>(value: T, options?: SignalOptions<T>): Signal<T>;
95
+ export interface BaseOptions {
98
96
  name?: string;
99
- internal?: boolean;
100
- }): [get: Accessor<T>, set: Setter<T>];
97
+ }
98
+ export declare type NoInfer<T extends any> = [T][T extends any ? 0 : never];
99
+ export interface EffectOptions extends BaseOptions {
100
+ }
101
+ export declare type EffectFunction<Prev, Next extends Prev = Prev> = (v: Prev) => Next;
101
102
  /**
102
103
  * Creates a reactive computation that runs immediately before render, mainly used to write to other reactive primitives
103
104
  * ```typescript
104
- * export function createComputed<T>(
105
- * fn: (v: T) => T,
106
- * value?: T,
105
+ * export function createComputed<Next, Init = Next>(
106
+ * fn: (v: Init | Next) => Next,
107
+ * value?: Init,
107
108
  * options?: { name?: string }
108
109
  * ): void;
109
110
  * ```
@@ -113,10 +114,8 @@ export declare function createSignal<T>(value: T, options?: {
113
114
  *
114
115
  * @description https://www.solidjs.com/docs/latest/api#createcomputed
115
116
  */
116
- export declare function createComputed<T>(fn: (v?: T) => T | undefined): void;
117
- export declare function createComputed<T>(fn: (v: T) => T, value: T, options?: {
118
- name?: string;
119
- }): void;
117
+ export declare function createComputed<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void;
118
+ export declare function createComputed<Next, Init = undefined>(..._: undefined extends Init ? [fn: EffectFunction<Init | Next, Next>, value?: Init, options?: EffectOptions] : [fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions]): void;
120
119
  /**
121
120
  * Creates a reactive computation that runs during the render phase as DOM elements are created and updated but not necessarily connected
122
121
  * ```typescript
@@ -132,10 +131,8 @@ export declare function createComputed<T>(fn: (v: T) => T, value: T, options?: {
132
131
  *
133
132
  * @description https://www.solidjs.com/docs/latest/api#createrendereffect
134
133
  */
135
- export declare function createRenderEffect<T>(fn: (v?: T) => T | undefined): void;
136
- export declare function createRenderEffect<T>(fn: (v: T) => T, value: T, options?: {
137
- name?: string;
138
- }): void;
134
+ export declare function createRenderEffect<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void;
135
+ export declare function createRenderEffect<Next, Init = undefined>(..._: undefined extends Init ? [fn: EffectFunction<Init | Next, Next>, value?: Init, options?: EffectOptions] : [fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions]): void;
139
136
  /**
140
137
  * Creates a reactive computation that runs after the render phase
141
138
  * ```typescript
@@ -151,10 +148,14 @@ export declare function createRenderEffect<T>(fn: (v: T) => T, value: T, options
151
148
  *
152
149
  * @description https://www.solidjs.com/docs/latest/api#createeffect
153
150
  */
154
- export declare function createEffect<T>(fn: (v?: T) => T | undefined): void;
155
- export declare function createEffect<T>(fn: (v: T) => T, value: T, options?: {
156
- name?: string;
157
- }): void;
151
+ export declare function createEffect<Next, Init = Next>(fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions): void;
152
+ export declare function createEffect<Next, Init = undefined>(..._: undefined extends Init ? [fn: EffectFunction<Init | Next, Next>, value?: Init, options?: EffectOptions] : [fn: EffectFunction<Init | Next, Next>, value: Init, options?: EffectOptions]): void;
153
+ interface Memo<Prev, Next = Prev> extends SignalState<Next>, Computation<Next> {
154
+ tOwned?: Computation<Prev | Next, Next>[];
155
+ }
156
+ export interface MemoOptions<T> extends EffectOptions {
157
+ equals?: false | ((prev: T, next: T) => boolean);
158
+ }
158
159
  /**
159
160
  * Creates a readonly derived reactive memoized signal
160
161
  * ```typescript
@@ -170,14 +171,8 @@ export declare function createEffect<T>(fn: (v: T) => T, value: T, options?: {
170
171
  *
171
172
  * @description https://www.solidjs.com/docs/latest/api#creatememo
172
173
  */
173
- export declare function createMemo<T>(fn: (v?: T) => T, value?: undefined, options?: {
174
- equals?: false | ((prev: T, next: T) => boolean);
175
- name?: string;
176
- }): Accessor<T>;
177
- export declare function createMemo<T>(fn: (v: T) => T, value: T, options?: {
178
- equals?: false | ((prev: T, next: T) => boolean);
179
- name?: string;
180
- }): Accessor<T>;
174
+ export declare function createMemo<Next extends _Next, Init = Next, _Next = Next>(fn: EffectFunction<Init | _Next, Next>, value: Init, options?: MemoOptions<Next>): Accessor<Next>;
175
+ export declare function createMemo<Next extends _Next, Init = undefined, _Next = Next>(..._: undefined extends Init ? [fn: EffectFunction<Init | _Next, Next>, value?: Init, options?: MemoOptions<Next>] : [fn: EffectFunction<Init | _Next, Next>, value: Init, options?: MemoOptions<Next>]): Accessor<Next>;
181
176
  export interface Resource<T> extends Accessor<T> {
182
177
  loading: boolean;
183
178
  error: any;
@@ -221,30 +216,30 @@ export declare type ResourceOptions<T> = T extends undefined ? {
221
216
  *
222
217
  * @description https://www.solidjs.com/docs/latest/api#createresource
223
218
  */
224
- export declare function createResource<T extends any, S = true>(fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): [Resource<T | undefined>, ResourceActions<T | undefined>];
225
- export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): [Resource<T>, ResourceActions<T>];
226
- export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): [Resource<T | undefined>, ResourceActions<T | undefined>];
227
- export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): [Resource<T>, ResourceActions<T>];
219
+ export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>;
220
+ export declare function createResource<T, S = true>(fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>;
221
+ export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options?: ResourceOptions<undefined>): ResourceReturn<T | undefined>;
222
+ export declare function createResource<T, S>(source: ResourceSource<S>, fetcher: ResourceFetcher<S, T>, options: ResourceOptions<T>): ResourceReturn<T>;
223
+ export interface DeferredOptions<T> {
224
+ equals?: false | ((prev: T, next: T) => boolean);
225
+ name?: string;
226
+ timeoutMs?: number;
227
+ }
228
228
  /**
229
229
  * Creates a reactive computation that only runs and notifies the reactive context when the browser is idle
230
230
  * ```typescript
231
231
  * export function createDeferred<T>(
232
232
  * fn: (v: T) => T,
233
- * value?: T,
234
233
  * options?: { timeoutMs?: number, name?: string, equals?: false | ((prev: T, next: T) => boolean) }
235
234
  * ): () => T);
236
235
  * ```
237
236
  * @param fn a function that receives its previous or the initial value, if set, and returns a new value used to react on a computation
238
- * @param value an optional initial value for the computation; if set, fn will never receive undefined as first argument
239
237
  * @param options allows to set the timeout in milliseconds, use a custom comparison function and set a name in dev mode for debugging purposes
240
238
  *
241
239
  * @description https://www.solidjs.com/docs/latest/api#createdeferred
242
240
  */
243
- export declare function createDeferred<T>(source: Accessor<T>, options?: {
244
- equals?: false | ((prev: T, next: T) => boolean);
245
- name?: string;
246
- timeoutMs?: number;
247
- }): Accessor<T>;
241
+ export declare function createDeferred<T>(source: Accessor<T>, options?: DeferredOptions<T>): Accessor<T>;
242
+ export declare type EqualityCheckerFunction<T, U> = (a: U, b: T) => boolean;
248
243
  /**
249
244
  * Creates a conditional signal that only notifies subscribers when entering or exiting their key matching the value
250
245
  * ```typescript
@@ -269,9 +264,7 @@ export declare function createDeferred<T>(source: Accessor<T>, options?: {
269
264
  *
270
265
  * @description https://www.solidjs.com/docs/latest/api#createselector
271
266
  */
272
- export declare function createSelector<T, U>(source: Accessor<T>, fn?: (a: U, b: T) => boolean, options?: {
273
- name?: string;
274
- }): (key: U) => boolean;
267
+ export declare function createSelector<T, U>(source: Accessor<T>, fn?: EqualityCheckerFunction<T, U>, options?: BaseOptions): (key: U) => boolean;
275
268
  /**
276
269
  * Holds changes inside the block before the reactive context is updated
277
270
  * @param fn wraps the reactive updates that should be batched
@@ -279,7 +272,7 @@ export declare function createSelector<T, U>(source: Accessor<T>, fn?: (a: U, b:
279
272
  *
280
273
  * @description https://www.solidjs.com/docs/latest/api#batch
281
274
  */
282
- export declare function batch<T>(fn: () => T): T;
275
+ export declare function batch<T>(fn: Accessor<T>): T;
283
276
  /**
284
277
  * Ignores tracking context inside its scope
285
278
  * @param fn the scope that is out of the tracking context
@@ -291,6 +284,10 @@ export declare function untrack<T>(fn: Accessor<T>): T;
291
284
  export declare type ReturnTypes<T> = T extends (() => any)[] ? {
292
285
  [I in keyof T]: ReturnTypes<T[I]>;
293
286
  } : T extends () => any ? ReturnType<T> : never;
287
+ export declare type OnEffectFunction<S, Prev, Next extends Prev = Prev> = (input: ReturnTypes<S>, prevInput: ReturnTypes<S>, v: Prev) => Next;
288
+ export interface OnOptions {
289
+ defer?: boolean;
290
+ }
294
291
  /**
295
292
  * on - make dependencies of a computation explicit
296
293
  * ```typescript
@@ -303,6 +300,8 @@ export declare type ReturnTypes<T> = T extends (() => any)[] ? {
303
300
  * @param deps list of reactive dependencies or a single reactive dependency
304
301
  * @param fn computation on input; the current previous content(s) of input and the previous value are given as arguments and it returns a new value
305
302
  * @param options optional, allows deferred computation until at the end of the next change
303
+ * @returns an effect function that is passed into createEffect. For example:
304
+ *
306
305
  * ```typescript
307
306
  * createEffect(on(a, (v) => console.log(v, b())));
308
307
  *
@@ -315,12 +314,7 @@ export declare type ReturnTypes<T> = T extends (() => any)[] ? {
315
314
  *
316
315
  * @description https://www.solidjs.com/docs/latest/api#on
317
316
  */
318
- export declare function on<T extends (() => any)[], U>(deps: [...T], fn: (input: ReturnTypes<T>, prevInput: ReturnTypes<T>, prevValue?: U) => U, options?: {
319
- defer?: boolean;
320
- }): (prevValue?: U) => U;
321
- export declare function on<T extends () => any, U>(deps: T, fn: (input: ReturnType<T>, prevInput: ReturnType<T>, prevValue?: U) => U, options?: {
322
- defer?: boolean;
323
- }): (prevValue?: U) => U;
317
+ export declare function on<S extends Accessor<unknown> | Accessor<unknown>[] | [], Next, Init = unknown>(deps: S, fn: OnEffectFunction<S, Init | Next, Next>, options?: OnOptions): EffectFunction<NoInfer<Init> | NoInfer<Next>, NoInfer<Next>>;
324
318
  /**
325
319
  * onMount - run an effect only after initial render on mount
326
320
  * @param fn an effect that should run only once on mount
@@ -344,11 +338,12 @@ export declare function onCleanup(fn: () => void): () => void;
344
338
  * @description https://www.solidjs.com/docs/latest/api#onerror
345
339
  */
346
340
  export declare function onError(fn: (err: any) => void): void;
347
- export declare function getListener(): Computation<any> | null;
341
+ export declare function getListener(): Computation<any, any> | null;
348
342
  export declare function getOwner(): Owner | null;
349
343
  export declare function runWithOwner(o: Owner, fn: () => any): any;
350
344
  export declare function enableScheduling(scheduler?: typeof requestCallback): void;
351
345
  export declare function startTransition(fn: () => void, cb?: () => void): void;
346
+ export declare type Transition = [Accessor<boolean>, (fn: () => void, cb?: () => void) => void];
352
347
  /**
353
348
  * ```typescript
354
349
  * export function useTransition(): [
@@ -359,7 +354,7 @@ export declare function startTransition(fn: () => void, cb?: () => void): void;
359
354
  *
360
355
  * @description https://www.solidjs.com/docs/latest/api#usetransition
361
356
  */
362
- export declare function useTransition(): [Accessor<boolean>, (fn: () => void, cb?: () => void) => void];
357
+ export declare function useTransition(): Transition;
363
358
  export declare function resumeEffects(e: Computation<any>[]): void;
364
359
  export declare function devComponent<T>(Comp: (props: T) => JSX.Element, props: T): JSX.Element;
365
360
  export declare function hashValue(v: any): string;
@@ -370,12 +365,13 @@ interface GraphRecord {
370
365
  [k: string]: GraphRecord | unknown;
371
366
  }
372
367
  export declare function serializeGraph(owner?: Owner | null): GraphRecord;
368
+ export declare type ContextProviderComponent<T> = (props: {
369
+ value: T;
370
+ children: any;
371
+ }) => any;
373
372
  export interface Context<T> {
374
373
  id: symbol;
375
- Provider: (props: {
376
- value: T;
377
- children: any;
378
- }) => any;
374
+ Provider: ContextProviderComponent<T>;
379
375
  defaultValue: T;
380
376
  }
381
377
  /**
@@ -413,18 +409,20 @@ export declare function useContext<T>(context: Context<T>): T;
413
409
  * @description https://www.solidjs.com/docs/latest/api#children
414
410
  */
415
411
  export declare function children(fn: Accessor<JSX.Element>): Accessor<JSX.Element>;
416
- declare type SuspenseContextType = {
412
+ export declare type SuspenseContextType = {
417
413
  increment?: () => void;
418
414
  decrement?: () => void;
419
415
  inFallback?: () => boolean;
420
416
  effects?: Computation<any>[];
421
417
  resolved?: boolean;
422
418
  };
423
- export declare function getSuspenseContext(): Context<SuspenseContextType> & {
419
+ declare type SuspenseContext = Context<SuspenseContextType> & {
424
420
  active?(): boolean;
425
421
  increment?(): void;
426
422
  decrement?(): void;
427
423
  };
428
- export declare function readSignal(this: Signal<any> | Memo<any>): any;
429
- export declare function writeSignal(node: Signal<any> | Memo<any>, value: any, isComp?: boolean): any;
424
+ declare let SuspenseContext: SuspenseContext;
425
+ export declare function getSuspenseContext(): SuspenseContext;
426
+ export declare function readSignal(this: SignalState<any> | Memo<any>): any;
427
+ export declare function writeSignal(node: SignalState<any> | Memo<any>, value: any, isComp?: boolean): any;
430
428
  export {};