@tempots/dom 33.1.1 → 34.0.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/std/value.d.ts DELETED
@@ -1,131 +0,0 @@
1
- import { ValueTypes } from '../types/domain';
2
- import { ListenerOptions, Prop, Signal } from './signal';
3
- /**
4
- * Represents a value that can either be a `Signal<T>` or a generic type `T`.
5
- *
6
- * @public
7
- */
8
- export type Value<T> = Signal<T> | T;
9
- export declare const Value: {
10
- /**
11
- * Maps a value or a Signal to a new value.
12
- * If the value is a Signal, it returns a new Signal with the mapped value.
13
- * If the value is not a Signal, it returns the mapped value.
14
- *
15
- * @typeParam T - The type of the value.
16
- * @typeParam U - The type of the new value.
17
- * @param value - The value or Signal to map.
18
- * @param fn - The function to map the value.
19
- * @returns The mapped value.
20
- */
21
- map: <T, U>(value: Value<T>, fn: (value: T) => U) => Value<U>;
22
- /**
23
- * Wraps a value or a Signal instance into a Signal.
24
- * If the value is already a Signal, it returns the value itself.
25
- * If the value is not a Signal, it creates a new Signal instance with the given value.
26
- *
27
- * @typeParam O - The type of the value.
28
- * @param value - The value or Signal instance to wrap.
29
- * @param equals - A function that determines if two values are equal. Defaults to strict equality (===).
30
- * @returns A Signal instance.
31
- */
32
- toSignal: <T>(value: Value<T>, equals?: (a: T, b: T) => boolean) => Signal<T>;
33
- /**
34
- * Wraps a value in a `Signal` if it is not already a `Signal`.
35
- * If the value is `null` or `undefined`, it returns `null` or `undefined` respectively.
36
- * @param value - The value to wrap or check.
37
- * @returns The wrapped value if it is not `null` or `undefined`, otherwise `null` or `undefined`.
38
- */
39
- maybeToSignal: <T>(value: Value<T> | undefined | null, equals?: (a: T, b: T) => boolean) => Signal<T> | undefined;
40
- /**
41
- * Gets the value from a `Signal` or the value itself if it is not a `Signal`.
42
- * @param value - The value or Signal instance to get the value from.
43
- * @returns The value.
44
- */
45
- get: <T>(value: Value<T>) => T;
46
- /**
47
- * Adds a listener to a `Signal` or calls the listener immediately if it is not a `Signal`.
48
- * @param value - The value or Signal instance to add the listener to.
49
- * @param listener - The listener to call when the value changes.
50
- * @returns A function to remove the listener.
51
- */
52
- on: <T>(value: Value<T>, listener: (value: T) => void) => (() => void);
53
- /**
54
- * Disposes of a value or a Signal.
55
- * If the value is a Signal, it disposes of the Signal.
56
- * If the value is not a Signal, it does nothing.
57
- * @param value - The value or Signal instance to dispose of.
58
- */
59
- dispose: <T>(value: Value<T>) => void;
60
- /**
61
- * Returns a function that disposes of a value or a Signal.
62
- * If the value is a Signal, it returns a function that disposes of the Signal.
63
- * If the value is not a Signal, it returns a function that does nothing.
64
- * @param value - The value or Signal instance to dispose of.
65
- * @returns A function to dispose of the value or Signal.
66
- */
67
- disposeFn: <T>(value: Value<T>) => () => void;
68
- /**
69
- * Derives a Prop from a Signal.
70
- * If the value is a Signal, it returns a new Prop with the derived value.
71
- * If the value is not a Signal, it returns a new Prop with the value.
72
- * @param value - The value or Signal instance to derive the Prop from.
73
- * @param options - The options for the derived Prop.
74
- * @param options.autoDisposeProp - Determines whether the derived Prop should be automatically disposed.
75
- * @param options.equals - A function that determines if two values are equal.
76
- * @returns A Prop instance.
77
- */
78
- deriveProp: <T>(value: Value<T>, { autoDisposeProp, equals, }?: {
79
- autoDisposeProp?: boolean;
80
- equals?: (a: T, b: T) => boolean;
81
- }) => Prop<T>;
82
- /**
83
- * Creates a new signal that emits `true` if the value is truthy, `false` otherwise.
84
- * @param value - The value or signal to check.
85
- * @returns A signal that emits `true` if the value is truthy, `false` otherwise.
86
- */
87
- truthy: <T>(value: Value<T>) => Value<boolean>;
88
- /**
89
- * Creates a new signal that emits `true` if the value is falsy, `false` otherwise.
90
- * @param value - The value or signal to check.
91
- * @returns A signal that emits `true` if the value is falsy, `false` otherwise.
92
- */
93
- falsy: <T>(value: Value<T>) => Value<boolean>;
94
- /**
95
- * Creates a new signal that emits `true` if the value is null or undefined, `false` otherwise.
96
- * @param value - The value or signal to check.
97
- * @returns A signal that emits `true` if the value is null or undefined, `false` otherwise.
98
- */
99
- nil: <T>(value: Value<T>) => Value<boolean>;
100
- /**
101
- * Creates a new signal that emits `true` if the value is not null or undefined, `false` otherwise.
102
- * @param value - The value or signal to check.
103
- * @returns A signal that emits `true` if the value is not null or undefined, `false` otherwise.
104
- */
105
- defined: <T>(value: Value<T>) => Value<boolean>;
106
- };
107
- /**
108
- * Creates a computed signal that depends on other signals or literal values and updates when any of the dependencies change.
109
- *
110
- * @typeParam T - The type of the argument values.
111
- * @param fn - The function that computes the value.
112
- * @param equals - The equality function used to compare the previous and current computed values.
113
- * @returns - The computed signal.
114
- * @public
115
- */
116
- export declare const computedOf: <T extends Value<unknown>[]>(...args: T) => <O>(fn: (...args: ValueTypes<T>) => O, equals?: (a: O, b: O) => boolean) => import('./signal').Computed<O>;
117
- /**
118
- * Joins a set of signals into a single signal that emits a record of the values.
119
- * @param values - The set of signals to join as a record of `Value`s.
120
- * @returns A signal that emits a record of the values.
121
- * @public
122
- */
123
- export declare const joinSignals: <T extends Record<string, Value<unknown>>>(values: T) => Signal<{ [K in keyof T]: T[K]; }>;
124
- /**
125
- * Creates an effect that depends on other signals or literal values and updates when any of the dependencies change.
126
- *
127
- * @param args - The array of signals or literal values that the effect depends on.
128
- * @returns A disposable object that can be used to stop the effect.
129
- * @public
130
- */
131
- export declare const effectOf: <T extends Value<unknown>[]>(...args: T) => (fn: (...args: ValueTypes<T>) => void, options?: ListenerOptions) => () => void;