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/dist/solid.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
52
  const $DEVCOMP = Symbol(0);
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
  }
@@ -36,16 +87,20 @@ function observable(input) {
36
87
  if (!(observer instanceof Object) || observer == null) {
37
88
  throw new TypeError("Expected the observer to be an object.");
38
89
  }
39
- const handler = typeof observer === "function" ? observer : observer.next && observer.next.bind(observer);
90
+ const handler =
91
+ typeof observer === "function" ? observer : observer.next && observer.next.bind(observer);
40
92
  if (!handler) {
41
93
  return {
42
94
  unsubscribe() {}
43
95
  };
44
96
  }
45
97
  const dispose = createRoot(disposer => {
46
- createEffect(() => input(), v => {
47
- handler(v);
48
- });
98
+ createEffect(
99
+ () => input(),
100
+ v => {
101
+ handler(v);
102
+ }
103
+ );
49
104
  return disposer;
50
105
  });
51
106
  if (getOwner()) onCleanup(dispose);
@@ -60,13 +115,13 @@ function observable(input) {
60
115
  }
61
116
  };
62
117
  }
63
- function from(producer) {
64
- const [s, set] = createSignal(undefined, {
118
+ function from(producer, initialValue = undefined) {
119
+ const [s, set] = createSignal(() => initialValue, initialValue, {
65
120
  equals: false
66
121
  });
67
122
  if ("subscribe" in producer) {
68
123
  const unsub = producer.subscribe(v => set(() => v));
69
- onCleanup(() => "unsubscribe" in unsub ? unsub.unsubscribe() : unsub());
124
+ onCleanup(() => ("unsubscribe" in unsub ? unsub.unsubscribe() : unsub()));
70
125
  } else {
71
126
  const clean = producer(set);
72
127
  onCleanup(clean);
@@ -138,16 +193,20 @@ function lazy(fn) {
138
193
  comp = s;
139
194
  }
140
195
  let Comp;
141
- return createMemo(() => (Comp = comp()) ? untrack(() => {
142
- if (!ctx || sharedConfig.done) return Comp(props);
143
- const c = sharedConfig.context;
144
- setHydrateContext(ctx);
145
- const r = Comp(props);
146
- setHydrateContext(c);
147
- return r;
148
- }) : "");
196
+ return createMemo(() =>
197
+ (Comp = comp())
198
+ ? untrack(() => {
199
+ if (!ctx || sharedConfig.done) return Comp(props);
200
+ const c = sharedConfig.context;
201
+ setHydrateContext(ctx);
202
+ const r = Comp(props);
203
+ setHydrateContext(c);
204
+ return r;
205
+ })
206
+ : ""
207
+ );
149
208
  };
150
- wrap.preload = () => p || ((p = fn()).then(mod => comp = () => mod.default), p);
209
+ wrap.preload = () => p || ((p = fn()).then(mod => (comp = () => mod.default)), p);
151
210
  return wrap;
152
211
  }
153
212
  let counter = 0;
@@ -158,80 +217,145 @@ function createUniqueId() {
158
217
 
159
218
  const narrowedError = name => `Stale read from <${name}>.`;
160
219
  function For(props) {
161
- const options = "fallback" in props ? {
162
- keyed: props.keyed,
163
- fallback: () => props.fallback
164
- } : {
165
- keyed: props.keyed
166
- };
220
+ const options =
221
+ "fallback" in props
222
+ ? {
223
+ keyed: props.keyed,
224
+ fallback: () => props.fallback
225
+ }
226
+ : {
227
+ keyed: props.keyed
228
+ };
167
229
  return createMemo(mapArray(() => props.each, props.children, options));
168
230
  }
169
231
  function Repeat(props) {
170
- const options = "fallback" in props ? {
171
- fallback: () => props.fallback
172
- } : {};
173
- return createMemo(repeat(() => props.count, index => typeof props.children === "function" ? props.children(index) : props.children, options));
232
+ const options =
233
+ "fallback" in props
234
+ ? {
235
+ fallback: () => props.fallback
236
+ }
237
+ : {};
238
+ return createMemo(
239
+ repeat(
240
+ () => props.count,
241
+ index => (typeof props.children === "function" ? props.children(index) : props.children),
242
+ options
243
+ )
244
+ );
174
245
  }
175
246
  function Show(props) {
176
247
  const keyed = props.keyed;
177
- const condition = createMemo(() => props.when, undefined, {
178
- equals: (a, b) => keyed ? a === b : !a === !b
179
- });
180
- return createMemo(() => {
181
- const c = condition();
182
- if (c) {
183
- const child = props.children;
184
- const fn = typeof child === "function" && child.length > 0;
185
- return fn ? untrack(() => child(() => {
186
- if (!untrack(condition)) throw narrowedError("Show");
187
- return props.when;
188
- })) : child;
189
- }
190
- return props.fallback;
191
- }, undefined, undefined);
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
+ });
254
+ return createMemo(
255
+ () => {
256
+ const c = condition();
257
+ if (c) {
258
+ const child = props.children;
259
+ const fn = typeof child === "function" && child.length > 0;
260
+ return fn
261
+ ? untrack(() =>
262
+ child(() => {
263
+ if (!untrack(condition)) throw narrowedError("Show");
264
+ return conditionValue();
265
+ })
266
+ )
267
+ : child;
268
+ }
269
+ return props.fallback;
270
+ },
271
+ undefined,
272
+ undefined
273
+ );
192
274
  }
193
275
  function Switch(props) {
194
- let keyed = false;
195
- const equals = (a, b) => (keyed ? a[1] === b[1] : !a[1] === !b[1]) && a[2] === b[2];
196
- const conditions = children(() => props.children),
197
- evalConditions = createMemo(() => {
198
- let conds = conditions();
199
- if (!Array.isArray(conds)) conds = [conds];
200
- for (let i = 0; i < conds.length; i++) {
201
- const c = conds[i].when;
202
- if (c) {
203
- keyed = !!conds[i].keyed;
204
- return [i, c, conds[i]];
205
- }
206
- }
207
- return [-1];
208
- }, undefined, {
209
- equals
210
- });
211
- return createMemo(() => {
212
- const [index, when, cond] = evalConditions();
213
- if (index < 0) return props.fallback;
214
- const c = cond.children;
215
- const fn = typeof c === "function" && c.length > 0;
216
- return fn ? untrack(() => c(() => {
217
- if (untrack(evalConditions)[0] !== index) throw narrowedError("Match");
218
- return cond.when;
219
- })) : c;
220
- }, undefined, undefined);
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
+ });
299
+ return createMemo(
300
+ () => {
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;
306
+ return fn
307
+ ? untrack(() =>
308
+ child(() => {
309
+ if (untrack(switchFunc)()?.[0] !== index) throw narrowedError("Match");
310
+ return conditionValue();
311
+ })
312
+ )
313
+ : child;
314
+ },
315
+ undefined,
316
+ undefined
317
+ );
221
318
  }
222
319
  function Match(props) {
223
320
  return props;
224
321
  }
225
322
  function ErrorBoundary(props) {
226
- return createErrorBoundary(() => props.children, (err, reset) => {
227
- const f = props.fallback;
228
- return typeof f === "function" && f.length ? f(err, reset) : f;
229
- });
323
+ return createErrorBoundary(
324
+ () => props.children,
325
+ (err, reset) => {
326
+ const f = props.fallback;
327
+ return typeof f === "function" && f.length ? f(err, reset) : f;
328
+ }
329
+ );
230
330
  }
231
331
  function Suspense(props) {
232
- return createSuspense(() => props.children, () => props.fallback);
332
+ return createSuspense(
333
+ () => props.children,
334
+ () => props.fallback
335
+ );
233
336
  }
234
337
 
235
338
  const DEV = undefined;
236
339
 
237
- export { $DEVCOMP, DEV, ErrorBoundary, For, Match, Repeat, Show, Suspense, Switch, children, createComponent, createContext, createUniqueId, enableHydration, from, lazy, observable, onMount, sharedConfig, useContext };
340
+ export {
341
+ $DEVCOMP,
342
+ DEV,
343
+ ErrorBoundary,
344
+ For,
345
+ Match,
346
+ Repeat,
347
+ Show,
348
+ Suspense,
349
+ Switch,
350
+ children,
351
+ createComponent,
352
+ createContext,
353
+ createUniqueId,
354
+ enableHydration,
355
+ from,
356
+ lazy,
357
+ observable,
358
+ onMount,
359
+ sharedConfig,
360
+ useContext
361
+ };
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.1",
4
+ "version": "2.0.0-experimental.3",
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.1.0",
82
+ "@solidjs/signals": "^0.2.3",
83
83
  "csstype": "^3.1.0"
84
84
  },
85
85
  "scripts": {
@@ -11,7 +11,7 @@ export type Component<P extends Record<string, any> = {}> = (props: P) => JSX.El
11
11
  * would silently throw them away.
12
12
  */
13
13
  export type VoidProps<P extends Record<string, any> = {}> = P & {
14
- children?: never;
14
+ children?: never;
15
15
  };
16
16
  /**
17
17
  * `VoidComponent` forbids the `children` prop.
@@ -25,7 +25,7 @@ export type VoidComponent<P extends Record<string, any> = {}> = Component<VoidPr
25
25
  * Use this for components that you want to accept children.
26
26
  */
27
27
  export type ParentProps<P extends Record<string, any> = {}> = P & {
28
- children?: JSX.Element;
28
+ children?: JSX.Element;
29
29
  };
30
30
  /**
31
31
  * `ParentComponent` allows an optional `children` prop with the usual
@@ -40,7 +40,7 @@ export type ParentComponent<P extends Record<string, any> = {}> = Component<Pare
40
40
  * Note that all JSX <Elements> are of the type `JSX.Element`.
41
41
  */
42
42
  export type FlowProps<P extends Record<string, any> = {}, C = JSX.Element> = P & {
43
- children: C;
43
+ children: C;
44
44
  };
45
45
  /**
46
46
  * `FlowComponent` requires a `children` prop with the specified type.
@@ -48,7 +48,9 @@ export type FlowProps<P extends Record<string, any> = {}, C = JSX.Element> = P &
48
48
  * typically a function that receives specific argument types.
49
49
  * Note that all JSX <Elements> are of the type `JSX.Element`.
50
50
  */
51
- export type FlowComponent<P extends Record<string, any> = {}, C = JSX.Element> = Component<FlowProps<P, C>>;
51
+ export type FlowComponent<P extends Record<string, any> = {}, C = JSX.Element> = Component<
52
+ FlowProps<P, C>
53
+ >;
52
54
  export type ValidComponent = keyof JSX.IntrinsicElements | Component<any> | (string & {});
53
55
  /**
54
56
  * Takes the props of the passed component and returns its type
@@ -57,19 +59,28 @@ export type ValidComponent = keyof JSX.IntrinsicElements | Component<any> | (str
57
59
  * ComponentProps<typeof Portal> // { mount?: Node; useShadow?: boolean; children: JSX.Element }
58
60
  * ComponentProps<'div'> // JSX.HTMLAttributes<HTMLDivElement>
59
61
  */
60
- export type ComponentProps<T extends ValidComponent> = T extends Component<infer P> ? P : T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] : Record<string, unknown>;
62
+ export type ComponentProps<T extends ValidComponent> = T extends Component<infer P>
63
+ ? P
64
+ : T extends keyof JSX.IntrinsicElements
65
+ ? JSX.IntrinsicElements[T]
66
+ : Record<string, unknown>;
61
67
  /**
62
68
  * Type of `props.ref`, for use in `Component` or `props` typing.
63
69
  *
64
70
  * @example Component<{ref: Ref<Element>}>
65
71
  */
66
72
  export type Ref<T> = T | ((val: T) => void);
67
- export declare function createComponent<T extends Record<string, any>>(Comp: Component<T>, props: T): JSX.Element;
68
- export declare function lazy<T extends Component<any>>(fn: () => Promise<{
73
+ export declare function createComponent<T extends Record<string, any>>(
74
+ Comp: Component<T>,
75
+ props: T
76
+ ): JSX.Element;
77
+ export declare function lazy<T extends Component<any>>(
78
+ fn: () => Promise<{
69
79
  default: T;
70
- }>): T & {
71
- preload: () => Promise<{
72
- default: T;
73
- }>;
80
+ }>
81
+ ): T & {
82
+ preload: () => Promise<{
83
+ default: T;
84
+ }>;
74
85
  };
75
86
  export declare function createUniqueId(): string;
@@ -12,11 +12,11 @@ export declare const $DEVCOMP: unique symbol;
12
12
  export declare function onMount(fn: () => void): void;
13
13
  export type NoInfer<T extends any> = [T][T extends any ? 0 : never];
14
14
  export type ContextProviderComponent<T> = FlowComponent<{
15
- value: T;
15
+ value: T;
16
16
  }>;
17
17
  export interface Context<T> extends ContextProviderComponent<T> {
18
- id: symbol;
19
- defaultValue: T;
18
+ id: symbol;
19
+ defaultValue: T;
20
20
  }
21
21
  /**
22
22
  * Creates a Context to handle a state scoped for the children of a component
@@ -37,7 +37,10 @@ export interface Context<T> extends ContextProviderComponent<T> {
37
37
  *
38
38
  * @description https://docs.solidjs.com/reference/component-apis/create-context
39
39
  */
40
- export declare function createContext<T>(defaultValue?: undefined, options?: EffectOptions): Context<T | undefined>;
40
+ export declare function createContext<T>(
41
+ defaultValue?: undefined,
42
+ options?: EffectOptions
43
+ ): Context<T | undefined>;
41
44
  export declare function createContext<T>(defaultValue: T, options?: EffectOptions): Context<T>;
42
45
  /**
43
46
  * Uses a context to receive a scoped state from a parent's Context.Provider
@@ -51,7 +54,7 @@ export declare function useContext<T>(context: Context<T>): T;
51
54
  export type ResolvedJSXElement = Exclude<JSX.Element, JSX.ArrayElement>;
52
55
  export type ResolvedChildren = ResolvedJSXElement | ResolvedJSXElement[];
53
56
  export type ChildrenReturn = Accessor<ResolvedChildren> & {
54
- toArray: () => ResolvedJSXElement[];
57
+ toArray: () => ResolvedJSXElement[];
55
58
  };
56
59
  /**
57
60
  * Resolves child elements to help interact with children
@@ -64,9 +67,9 @@ export type ChildrenReturn = Accessor<ResolvedChildren> & {
64
67
  export declare function children(fn: Accessor<JSX.Element>): ChildrenReturn;
65
68
  export declare function devComponent<P, V>(Comp: (props: P) => V, props: P): V;
66
69
  interface SourceMapValue {
67
- value: unknown;
68
- name?: string;
69
- graph?: Owner;
70
+ value: unknown;
71
+ name?: string;
72
+ graph?: Owner;
70
73
  }
71
74
  export declare function registerGraph(value: SourceMapValue): void;
72
75
  export {};
@@ -13,10 +13,10 @@ import type { JSX } from "../jsx.js";
13
13
  * @description https://docs.solidjs.com/reference/components/for
14
14
  */
15
15
  export declare function For<T extends readonly any[], U extends JSX.Element>(props: {
16
- each: T | undefined | null | false;
17
- fallback?: JSX.Element;
18
- keyed?: boolean | ((item: T) => any);
19
- children: (item: Accessor<T[number]>, index: Accessor<number>) => U;
16
+ each: T | undefined | null | false;
17
+ fallback?: JSX.Element;
18
+ keyed?: boolean | ((item: T) => any);
19
+ children: (item: Accessor<T[number]>, index: Accessor<number>) => U;
20
20
  }): JSX.Element;
21
21
  /**
22
22
  * Creates a list elements from a count
@@ -31,19 +31,19 @@ export declare function For<T extends readonly any[], U extends JSX.Element>(pro
31
31
  * @description https://docs.solidjs.com/reference/components/repeat
32
32
  */
33
33
  export declare function Repeat<T extends JSX.Element>(props: {
34
- count: number;
35
- fallback?: JSX.Element;
36
- children: ((index: number) => T) | T;
34
+ count: number;
35
+ fallback?: JSX.Element;
36
+ children: ((index: number) => T) | T;
37
37
  }): JSX.Element;
38
38
  /**
39
39
  * Conditionally render its children or an optional fallback component
40
40
  * @description https://docs.solidjs.com/reference/components/show
41
41
  */
42
42
  export declare function Show<T>(props: {
43
- when: T | undefined | null | false;
44
- keyed?: boolean;
45
- fallback?: JSX.Element;
46
- children: JSX.Element | ((item: Accessor<NonNullable<T>>) => JSX.Element);
43
+ when: T | undefined | null | false;
44
+ keyed?: boolean;
45
+ fallback?: JSX.Element;
46
+ children: JSX.Element | ((item: Accessor<NonNullable<T>>) => JSX.Element);
47
47
  }): JSX.Element;
48
48
  /**
49
49
  * Switches between content based on mutually exclusive conditions
@@ -60,13 +60,13 @@ export declare function Show<T>(props: {
60
60
  * @description https://docs.solidjs.com/reference/components/switch-and-match
61
61
  */
62
62
  export declare function Switch(props: {
63
- fallback?: JSX.Element;
64
- children: JSX.Element;
63
+ fallback?: JSX.Element;
64
+ children: JSX.Element;
65
65
  }): JSX.Element;
66
66
  export type MatchProps<T> = {
67
- when: T | undefined | null | false;
68
- keyed?: boolean;
69
- children: JSX.Element | ((item: Accessor<NonNullable<T>>) => JSX.Element);
67
+ when: T | undefined | null | false;
68
+ keyed?: boolean;
69
+ children: JSX.Element | ((item: Accessor<NonNullable<T>>) => JSX.Element);
70
70
  };
71
71
  /**
72
72
  * Selects a content based on condition when inside a `<Switch>` control flow
@@ -94,8 +94,8 @@ export declare function Match<T>(props: MatchProps<T>): JSX.Element;
94
94
  * @description https://docs.solidjs.com/reference/components/error-boundary
95
95
  */
96
96
  export declare function ErrorBoundary(props: {
97
- fallback: JSX.Element | ((err: any, reset: () => void) => JSX.Element);
98
- children: JSX.Element;
97
+ fallback: JSX.Element | ((err: any, reset: () => void) => JSX.Element);
98
+ children: JSX.Element;
99
99
  }): JSX.Element;
100
100
  /**
101
101
  * Tracks all resources inside a component and renders a fallback until they are all resolved
@@ -109,6 +109,6 @@ export declare function ErrorBoundary(props: {
109
109
  * @description https://docs.solidjs.com/reference/components/suspense
110
110
  */
111
111
  export declare function Suspense(props: {
112
- fallback?: JSX.Element;
113
- children: JSX.Element;
112
+ fallback?: JSX.Element;
113
+ children: JSX.Element;
114
114
  }): JSX.Element;
@@ -1,20 +1,20 @@
1
1
  export type HydrationContext = {
2
- id: string;
3
- count: number;
2
+ id: string;
3
+ count: number;
4
4
  };
5
5
  type SharedConfig = {
6
- context?: HydrationContext;
7
- resources?: {
8
- [key: string]: any;
9
- };
10
- load?: (id: string) => Promise<any> | any;
11
- has?: (id: string) => boolean;
12
- gather?: (key: string) => void;
13
- registry?: Map<string, Element>;
14
- done?: boolean;
15
- count?: number;
16
- getContextId(): string;
17
- getNextContextId(): string;
6
+ context?: HydrationContext;
7
+ resources?: {
8
+ [key: string]: any;
9
+ };
10
+ load?: (id: string) => Promise<any> | any;
11
+ has?: (id: string) => boolean;
12
+ gather?: (key: string) => void;
13
+ registry?: Map<string, Element>;
14
+ done?: boolean;
15
+ count?: number;
16
+ getContextId(): string;
17
+ getNextContextId(): string;
18
18
  };
19
19
  export declare const sharedConfig: SharedConfig;
20
20
  export declare function setHydrateContext(context?: HydrationContext): void;
@@ -1,20 +1,22 @@
1
1
  import { Accessor, Setter } from "@solidjs/signals";
2
2
  declare global {
3
- interface SymbolConstructor {
4
- readonly observable: symbol;
5
- }
3
+ interface SymbolConstructor {
4
+ readonly observable: symbol;
5
+ }
6
6
  }
7
7
  interface Observable<T> {
8
- subscribe(observer: ObservableObserver<T>): {
9
- unsubscribe(): void;
10
- };
11
- [Symbol.observable](): Observable<T>;
8
+ subscribe(observer: ObservableObserver<T>): {
9
+ unsubscribe(): void;
10
+ };
11
+ [Symbol.observable](): Observable<T>;
12
12
  }
13
- export type ObservableObserver<T> = ((v: T) => void) | {
14
- next?: (v: T) => void;
15
- error?: (v: any) => void;
16
- complete?: (v: boolean) => void;
17
- };
13
+ export type ObservableObserver<T> =
14
+ | ((v: T) => void)
15
+ | {
16
+ next?: (v: T) => void;
17
+ error?: (v: any) => void;
18
+ complete?: (v: boolean) => void;
19
+ };
18
20
  /**
19
21
  * Creates a simple observable from a signal's accessor to be used with the `from` operator of observable libraries like e.g. rxjs
20
22
  * ```typescript
@@ -26,9 +28,15 @@ export type ObservableObserver<T> = ((v: T) => void) | {
26
28
  * description https://docs.solidjs.com/reference/reactive-utilities/observable
27
29
  */
28
30
  export declare function observable<T>(input: Accessor<T>): Observable<T>;
29
- export declare function from<T>(producer: ((setter: Setter<T | undefined>) => () => void) | {
30
- subscribe: (fn: (v: T) => void) => (() => void) | {
31
- unsubscribe: () => void;
31
+ type Producer<T> =
32
+ | ((setter: Setter<T>) => () => void)
33
+ | {
34
+ subscribe: (fn: (v: T) => void) =>
35
+ | (() => void)
36
+ | {
37
+ unsubscribe: () => void;
38
+ };
32
39
  };
33
- }): Accessor<T | undefined>;
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>;
34
42
  export {};