ccstate 2.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.
@@ -0,0 +1,52 @@
1
+ type Updater<T> = (current: T) => T;
2
+ interface Setter {
3
+ <T>(state: State<T>, val: T | Updater<T>): void;
4
+ <T, Args extends unknown[]>(command: Command<T, Args>, ...args: Args): T;
5
+ }
6
+ type Getter = <T>(readable: ReadableAtom<T>) => T;
7
+ interface GetterOptions {
8
+ signal: AbortSignal;
9
+ }
10
+ type Read<T> = (get: Getter, options: GetterOptions) => T;
11
+ type Write<T, Args extends unknown[]> = (visitor: {
12
+ get: Getter;
13
+ set: Setter;
14
+ }, ...args: Args) => T;
15
+ interface State<T> {
16
+ init: T;
17
+ debugLabel?: string;
18
+ toString: () => string;
19
+ }
20
+ interface Computed<T> {
21
+ read: Read<T>;
22
+ debugLabel?: string;
23
+ toString: () => string;
24
+ }
25
+ interface Command<T, Args extends unknown[]> {
26
+ write: Write<T, Args>;
27
+ debugLabel?: string;
28
+ toString: () => string;
29
+ }
30
+ type ReadableAtom<T> = State<T> | Computed<T>;
31
+
32
+ interface Options {
33
+ debugLabel?: string;
34
+ }
35
+ declare function state<T>(init: T, options?: Options): State<T>;
36
+ declare function computed<T>(read: Read<T>, options?: Options): Computed<T>;
37
+ declare function command<T, Args extends unknown[]>(write: Write<T, Args>, options?: Options): Command<T, Args>;
38
+
39
+ interface Store {
40
+ get: Getter;
41
+ set: Setter;
42
+ sub: Subscribe;
43
+ }
44
+ interface SubscribeOptions {
45
+ signal?: AbortSignal;
46
+ }
47
+ type CallbackFunc<T> = Command<T, []>;
48
+ type Subscribe = (atoms$: ReadableAtom<unknown>[] | ReadableAtom<unknown>, callback: CallbackFunc<unknown>, options?: SubscribeOptions) => () => void;
49
+
50
+ declare function createStore(): Store;
51
+
52
+ export { type Command, type Computed, type Getter, type Read, type Setter, type State, type Store, type Subscribe, type Updater, type Write, command, computed, createStore, state };
@@ -0,0 +1,52 @@
1
+ type Updater<T> = (current: T) => T;
2
+ interface Setter {
3
+ <T>(state: State<T>, val: T | Updater<T>): void;
4
+ <T, Args extends unknown[]>(command: Command<T, Args>, ...args: Args): T;
5
+ }
6
+ type Getter = <T>(readable: ReadableAtom<T>) => T;
7
+ interface GetterOptions {
8
+ signal: AbortSignal;
9
+ }
10
+ type Read<T> = (get: Getter, options: GetterOptions) => T;
11
+ type Write<T, Args extends unknown[]> = (visitor: {
12
+ get: Getter;
13
+ set: Setter;
14
+ }, ...args: Args) => T;
15
+ interface State<T> {
16
+ init: T;
17
+ debugLabel?: string;
18
+ toString: () => string;
19
+ }
20
+ interface Computed<T> {
21
+ read: Read<T>;
22
+ debugLabel?: string;
23
+ toString: () => string;
24
+ }
25
+ interface Command<T, Args extends unknown[]> {
26
+ write: Write<T, Args>;
27
+ debugLabel?: string;
28
+ toString: () => string;
29
+ }
30
+ type ReadableAtom<T> = State<T> | Computed<T>;
31
+
32
+ interface Options {
33
+ debugLabel?: string;
34
+ }
35
+ declare function state<T>(init: T, options?: Options): State<T>;
36
+ declare function computed<T>(read: Read<T>, options?: Options): Computed<T>;
37
+ declare function command<T, Args extends unknown[]>(write: Write<T, Args>, options?: Options): Command<T, Args>;
38
+
39
+ interface Store {
40
+ get: Getter;
41
+ set: Setter;
42
+ sub: Subscribe;
43
+ }
44
+ interface SubscribeOptions {
45
+ signal?: AbortSignal;
46
+ }
47
+ type CallbackFunc<T> = Command<T, []>;
48
+ type Subscribe = (atoms$: ReadableAtom<unknown>[] | ReadableAtom<unknown>, callback: CallbackFunc<unknown>, options?: SubscribeOptions) => () => void;
49
+
50
+ declare function createStore(): Store;
51
+
52
+ export { type Command, type Computed, type Getter, type Read, type Setter, type State, type Store, type Subscribe, type Updater, type Write, command, computed, createStore, state };