@solidjs/signals 0.6.4 → 0.7.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.
@@ -149,12 +149,6 @@ export declare function isPending(fn: () => any, loadingValue: boolean): boolean
149
149
  */
150
150
  export declare function latest<T>(fn: () => T): T;
151
151
  export declare function latest<T, U>(fn: () => T, fallback: U): T | U;
152
- /**
153
- * Runs the given function in the given observer.
154
- *
155
- * Warning: Usually there are simpler ways of modeling a problem that avoid using this function
156
- */
157
- export declare function runWithObserver<T>(observer: Computation, run: () => T): T | undefined;
158
152
  /**
159
153
  * A convenient wrapper that calls `compute` with the `owner` and `observer` and is guaranteed
160
154
  * to reset the global context after the computation is finished even if an error is thrown.
@@ -24,6 +24,14 @@ export declare class Effect<T = any> extends Computation<T> {
24
24
  _disposeNode(): void;
25
25
  _run(type: number): void;
26
26
  }
27
+ export declare class TrackedEffect extends Computation {
28
+ _type: number;
29
+ _cleanup: (() => void) | undefined;
30
+ constructor(compute: () => void | (() => void), options?: SignalOptions<undefined>);
31
+ _notify(state: number, skipQueue?: boolean): void;
32
+ _disposeNode(): void;
33
+ _run(type: number): void;
34
+ }
27
35
  export declare class EagerComputation<T = any> extends Computation<T> {
28
36
  constructor(initialValue: T, compute: () => T, options?: SignalOptions<T> & {
29
37
  defer?: boolean;
@@ -1,6 +1,6 @@
1
1
  export { ContextNotFoundError, NoOwnerError, NotReadyError } 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, getObserver, isEqual, untrack, hasUpdated, isPending, latest, UNCHANGED, compute, runWithObserver, type SignalOptions } from "./core.js";
3
+ export { Computation, getObserver, isEqual, untrack, hasUpdated, isPending, latest, UNCHANGED, compute, type SignalOptions } from "./core.js";
4
4
  export { Effect, EagerComputation } from "./effect.js";
5
5
  export { flush, Queue, incrementClock, transition, ActiveTransition, type IQueue } from "./scheduler.js";
6
6
  export * from "./constants.js";
@@ -1,4 +1,4 @@
1
- export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flush, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isPending, latest, runWithObserver, transition, SUPPORTS_PROXY } from "./core/index.js";
1
+ export { Computation, ContextNotFoundError, NoOwnerError, NotReadyError, Owner, Queue, createContext, flush, getContext, setContext, hasContext, getOwner, onCleanup, getObserver, isEqual, untrack, hasUpdated, isPending, latest, transition, SUPPORTS_PROXY } from "./core/index.js";
2
2
  export type { 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";
@@ -123,6 +123,34 @@ export declare function createEffect<Next, Init = Next>(compute: ComputeFunction
123
123
  */
124
124
  export declare function createRenderEffect<Next>(compute: ComputeFunction<undefined | NoInfer<Next>, Next>, effect: EffectFunction<NoInfer<Next>, Next>): void;
125
125
  export declare function createRenderEffect<Next, Init = Next>(compute: ComputeFunction<Init | Next, Next>, effect: EffectFunction<Next, Next>, value: Init, options?: EffectOptions): void;
126
+ /**
127
+ * Creates a tracked reactive effect that only tracks dependencies inside the effect itself
128
+ * ```typescript
129
+ * export function createTrackedEffect(
130
+ * compute: () => (() => void) | void,
131
+ * options?: { name?: string, defer?: boolean }
132
+ * ): void;
133
+ * ```
134
+ * @param compute a function that contains reactive reads to track and returns an optional cleanup function to run on disposal or before next execution
135
+ * @param options allows to set a name in dev mode for debugging purposes
136
+ *
137
+ * @description https://docs.solidjs.com/reference/secondary-primitives/create-tracked-effect
138
+ */
139
+ export declare function createTrackedEffect(compute: () => void | (() => void), options?: EffectOptions): void;
140
+ /**
141
+ * Creates a reactive computation that runs after the render phase with flexible tracking
142
+ * ```typescript
143
+ * export function createReaction(
144
+ * onInvalidate: () => void,
145
+ * options?: { name?: string }
146
+ * ): (fn: () => void) => void;
147
+ * ```
148
+ * @param invalidated a function that is called when tracked function is invalidated.
149
+ * @param options allows to set a name in dev mode for debugging purposes
150
+ *
151
+ * @description https://docs.solidjs.com/reference/secondary-primitives/create-reaction
152
+ */
153
+ export declare function createReaction(effect: EffectFunction<undefined> | EffectBundle<undefined>, options?: EffectOptions): (tracking: () => void) => void;
126
154
  /**
127
155
  * Creates a new non-tracked reactive context with manual disposal
128
156
  *
@@ -146,6 +174,9 @@ export declare function runWithOwner<T>(owner: Owner | null, run: () => T): T;
146
174
  * @param fn a reactive expression to resolve
147
175
  */
148
176
  export declare function resolve<T>(fn: () => T): Promise<T>;
177
+ export declare function createOptimistic<T>(): Signal<T | undefined>;
178
+ export declare function createOptimistic<T>(value: Exclude<T, Function>, options?: SignalOptions<T>): Signal<T>;
179
+ export declare function createOptimistic<T>(fn: ComputeFunction<T>, initialValue?: T, options?: SignalOptions<T>): Signal<T>;
149
180
  /** Allows the user to mark a state change as non-urgent.
150
181
  *
151
182
  * @see {@link https://docs.solidjs.com/reference/advanced-reactivity/transition}
@@ -2,6 +2,6 @@ export type { Store, StoreSetter, StoreNode, NotWrappable, SolidStore } from "./
2
2
  export type { Merge, Omit } from "./utils.js";
3
3
  export { isWrappable, createStore, deep, $TRACK, $PROXY, $TARGET } from "./store.js";
4
4
  export { createProjection } from "./projection.js";
5
- export { createOptimistic } from "./optimistic.js";
5
+ export { createOptimisticStore } from "./optimistic.js";
6
6
  export { reconcile } from "./reconcile.js";
7
7
  export { snapshot, merge, omit } from "./utils.js";
@@ -15,8 +15,8 @@ import { type Store, type StoreSetter } from "./store.js";
15
15
  *
16
16
  * @returns A tuple containing an accessor for the current value and a setter function to apply changes.
17
17
  */
18
- export declare function createOptimistic<T extends object = {}>(initial: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
19
- export declare function createOptimistic<T extends object = {}>(fn: (store: T) => T | void, initial: T | Store<T>, options?: {
18
+ export declare function createOptimisticStore<T extends object = {}>(initial: T | Store<T>): [get: Store<T>, set: StoreSetter<T>];
19
+ export declare function createOptimisticStore<T extends object = {}>(fn: (store: T) => T | void, initial: T | Store<T>, options?: {
20
20
  key?: string | ((item: NonNullable<any>) => any);
21
21
  all?: boolean;
22
22
  }): [get: Store<T>, set: StoreSetter<T>];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solidjs/signals",
3
- "version": "0.6.4",
3
+ "version": "0.7.0",
4
4
  "description": "",
5
5
  "author": "Ryan Carniato",
6
6
  "license": "MIT",