@manyducks.co/dolla 2.0.0-alpha.5 → 2.0.0-alpha.6

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/signals.d.ts DELETED
@@ -1,101 +0,0 @@
1
- /**
2
- * Stops the observer that created it when called.
3
- */
4
- export type StopFunction = () => void;
5
- type Unwrapped<T> = T extends Signal<infer V> ? V : T;
6
- /**
7
- * Extracts value types from an array of signals.
8
- */
9
- export type SignalValues<T extends MaybeSignal<any>[]> = {
10
- [K in keyof T]: Unwrapped<T[K]>;
11
- };
12
- export interface CreateSignalOptions<T> {
13
- /**
14
- * Determines if the `next` value is equal to the `current` value.
15
- * If this function returns true, watchers will be notified of changes. If it returns false, watchers will not be notified.
16
- * By default equality is defined as deep equality.
17
- *
18
- * @param next - The new value being set.
19
- * @param current - The current value being replaced.
20
- */
21
- equality?: (next: T, current: T) => boolean;
22
- }
23
- export interface SignalWatchOptions<T> {
24
- /**
25
- * If true the watch callback will be called for the first time on the next change.
26
- * By default the callback is called immediately with the signal's current value.
27
- */
28
- lazy?: boolean;
29
- }
30
- export interface Signal<T> {
31
- /**
32
- * Returns the current value.
33
- */
34
- get(): T;
35
- /**
36
- * Watch this signal's value with a `callback` function.
37
- * The `callback` is only called if the value is not equal to the current value.
38
- *
39
- * > NOTE: If watching a signal inside a view, use the `.watch` method on the `ViewContext`. That method will automatically
40
- * clean up all watchers when the view is disconnected. Watchers created here must be cleaned up manually.
41
- */
42
- watch(callback: (value: T) => void, options?: SignalWatchOptions<T>): StopFunction;
43
- }
44
- /** A new value for a signal, or a callback that receives the current value and returns a new one. */
45
- export type SignalSetAction<I, O = I> = O | ((current: I) => O);
46
- /** Callback that updates the value of a signal. */
47
- export type SignalSetter<I, O = I> = (value: SignalSetAction<I, O>) => void;
48
- export type MaybeSignal<T> = Signal<T> | T;
49
- /**
50
- * A signal and setter in one. Useful for passing signals that are intended to be updated by subviews.
51
- */
52
- export interface SettableSignal<I, O = I> extends Signal<I> {
53
- /**
54
- * Updates the signal's value.
55
- */
56
- set(next: O): void;
57
- /**
58
- * Takes a callback that recieves the signal's current value and returns a new one.
59
- */
60
- set(callback: (current: I) => O): void;
61
- }
62
- export declare function isSignal<T>(value: any): value is Signal<T>;
63
- export declare function isSettableSignal<T>(value: any): value is Signal<T>;
64
- /**
65
- * Retrieves a plain value from a variable that may be a signal.
66
- */
67
- export declare function designalify<T>(value: MaybeSignal<T>): T;
68
- /**
69
- * Ensures a variable that may be a signal or plain value is a signal.
70
- */
71
- export declare function signalify<T>(value: MaybeSignal<T>): Signal<T>;
72
- /**
73
- * Creates a SettableSignal.
74
- */
75
- export declare function createSettableSignal<T>(initialValue: T, options?: CreateSignalOptions<T>): SettableSignal<T>;
76
- /**
77
- * Creates a SettableSignal.
78
- */
79
- export declare function createSettableSignal<T>(initialValue?: T, options?: CreateSignalOptions<T | undefined>): SettableSignal<T | undefined>;
80
- /**
81
- * Join a signal and its setter into a single SettableSignal object.
82
- */
83
- export declare function toSettableSignal<I, O = I>(signal: Signal<I>, setter: SignalSetter<I, O>): SettableSignal<I, O>;
84
- /**
85
- * Creates a SignalSetter with custom logic provided by `callback`.
86
- */
87
- export declare function createSignalSetter<I, O = I>(signal: Signal<I>, callback: (next: O, current: I) => void): SignalSetter<I, O>;
88
- /**
89
- * Creates a signal and setter.
90
- */
91
- export declare function createSignal<T>(initialValue: T, options?: CreateSignalOptions<T>): [Signal<T>, SignalSetter<T>];
92
- /**
93
- * Creates a signal and setter.
94
- */
95
- export declare function createSignal<T>(initialValue?: T, options?: CreateSignalOptions<T | undefined>): [Signal<T | undefined>, SignalSetter<T | undefined>];
96
- export interface DeriveOptions {
97
- equality?: (next: unknown, current: unknown) => boolean;
98
- }
99
- export declare function derive<Inputs extends MaybeSignal<any>[], T>(signals: [...Inputs], fn: (...currentValues: SignalValues<Inputs>) => T | Signal<T>, options?: DeriveOptions): Signal<T>;
100
- export declare function watch<I extends MaybeSignal<any>[]>(signals: [...I], fn: (...currentValues: SignalValues<I>) => void): StopFunction;
101
- export {};