@solidjs/signals 0.1.0 → 0.2.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.
@@ -51,7 +51,7 @@ interface ObserverType {
51
51
  /**
52
52
  * Returns the current observer.
53
53
  */
54
- export declare function getObserver(): ObserverType | null;
54
+ export declare function getObserver(): Computation | null;
55
55
  export declare const UNCHANGED: unique symbol;
56
56
  export type UNCHANGED = typeof UNCHANGED;
57
57
  export declare class Computation<T = any> extends Owner implements SourceType, ObserverType {
@@ -148,6 +148,12 @@ export declare function isStale(fn: () => any): boolean;
148
148
  */
149
149
  export declare function latest<T>(fn: () => T): T;
150
150
  export declare function catchError(fn: () => void): unknown | undefined;
151
+ /**
152
+ * Runs the given function in the given observer so that tracking, error handling and cleanups continue to work.
153
+ *
154
+ * Warning: Usually there are simpler ways of modeling a problem that avoid using this function
155
+ */
156
+ export declare function runWithObserver<T>(observer: Computation, run: () => T): T | undefined;
151
157
  /**
152
158
  * A convenient wrapper that calls `compute` with the `owner` and `observer` and is guaranteed
153
159
  * to reset the global context after the computation is finished even if an error is thrown.
@@ -1,6 +1,6 @@
1
1
  export { ContextNotFoundError, NoOwnerError, NotReadyError, type ErrorHandler } from "./error.js";
2
2
  export { Owner, createContext, getContext, setContext, hasContext, getOwner, onCleanup, type Context, type ContextRecord, type Disposable } from "./owner.js";
3
- export { Computation, createBoundary, getObserver, isEqual, untrack, hasUpdated, isStale, latest, catchError, UNCHANGED, compute, type SignalOptions } from "./core.js";
3
+ export { Computation, createBoundary, getObserver, isEqual, untrack, hasUpdated, isStale, latest, catchError, UNCHANGED, compute, runWithObserver, type SignalOptions } from "./core.js";
4
4
  export { Effect, EagerComputation } from "./effect.js";
5
5
  export { flushSync, getClock, incrementClock, type IQueue, Queue } from "./scheduler.js";
6
6
  export { createSuspense } from "./suspense.js";
@@ -1,4 +1,4 @@
1
- export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flatten, flushSync, createBoundary, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isStale, latest, catchError, createSuspense, SUPPORTS_PROXY } from "./core/index.js";
1
+ export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flatten, flushSync, createBoundary, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isStale, latest, catchError, runWithObserver, createSuspense, SUPPORTS_PROXY } from "./core/index.js";
2
2
  export type { ErrorHandler, SignalOptions, Context, ContextRecord, Disposable, IQueue } from "./core/index.js";
3
3
  export { mapArray, repeat, type Maybe } from "./map.js";
4
4
  export * from "./signals.js";
@@ -12,8 +12,10 @@ export type ComputeFunction<Prev, Next extends Prev = Prev> = (v: Prev) => Next;
12
12
  export type EffectFunction<Prev, Next extends Prev = Prev> = (v: Next, p?: Prev) => (() => void) | void;
13
13
  export interface EffectOptions {
14
14
  name?: string;
15
+ defer?: boolean;
15
16
  }
16
- export interface MemoOptions<T> extends EffectOptions {
17
+ export interface MemoOptions<T> {
18
+ name?: string;
17
19
  equals?: false | ((prev: T, next: T) => boolean);
18
20
  }
19
21
  export type NoInfer<T extends any> = [T][T extends any ? 0 : never];
@@ -95,7 +97,7 @@ export declare function createAsync<T>(compute: (prev?: T) => Promise<T> | Async
95
97
  * @description https://docs.solidjs.com/reference/basic-reactivity/create-effect
96
98
  */
97
99
  export declare function createEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effect: EffectFunction<NoInfer<Next>, Next>, error?: (err: unknown) => void): void;
98
- export declare function createEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next>, error: (err: unknown) => void | undefined, value: Init, options?: EffectOptions): void;
100
+ export declare function createEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next>, error: ((err: unknown) => void) | undefined, value: Init, options?: EffectOptions): void;
99
101
  /**
100
102
  * Creates a reactive computation that runs during the render phase as DOM elements are created and updated but not necessarily connected
101
103
  * ```typescript
@@ -129,7 +131,7 @@ export declare function createRoot<T>(init: ((dispose: () => void) => T) | (() =
129
131
  *
130
132
  * Warning: Usually there are simpler ways of modeling a problem that avoid using this function
131
133
  */
132
- export declare function runWithOwner<T>(owner: Owner | null, run: () => T): T | undefined;
134
+ export declare function runWithOwner<T>(owner: Owner | null, run: () => T): T;
133
135
  /**
134
136
  * Switches to fallback whenever an error is thrown within the context of the child scopes
135
137
  * @param fn boundary for the error
@@ -145,18 +147,3 @@ export declare function createErrorBoundary<T, U>(fn: () => T, fallback: (error:
145
147
  * @param fn a reactive expression to resolve
146
148
  */
147
149
  export declare function resolve<T>(fn: () => T): Promise<T>;
148
- /**
149
- * Creates a reactive computation that runs after the render phase with flexible tracking
150
- * ```typescript
151
- * export function createReaction(
152
- * effect: () => void,
153
- * options?: { name?: string }
154
- * ): (fn: () => void) => void;
155
- * ```
156
- * @param effect a function that is called when tracked function is invalidated.
157
- * @param error an optional function that receives an error if thrown during tracking
158
- * @param options allows to set a name in dev mode for debugging purposes
159
- *
160
- * @description https://docs.solidjs.com/reference/secondary-primitives/create-reaction
161
- */
162
- export declare function createReaction(effect: () => (() => void) | void, error?: (err: unknown) => (() => void) | void, options?: EffectOptions): (tracking: () => void) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/signals",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",