-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathderivable.d.ts
93 lines (52 loc) · 2.03 KB
/
derivable.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
declare module derivable {
export interface Derivable<T> {
derive<E>(f: (value: T) => E): Derivable<E>;
maybeDerive<E>(f: (value: T) => E): Derivable<E>;
orDefault<E>(value: E): Derivable<T | E>
react(f: (value: T) => void, options?: Lifecycle<T>): void;
maybeReact(f: (value: T) => void, options?: Lifecycle<T>): void;
get(): T;
is(other: any): Derivable<boolean>;
withEquality(equals: (a: T, b: T) => boolean): this;
}
export interface Atom<T> extends Derivable<T> {
set(value: T): void;
update(f: (value: T) => T): void;
update<A>(f: (value: T, a: A) => T, a: A): void;
update<A, B>(f: (value: T, a: A, b: B) => T, a: A, b: B): void;
update<A, B, C>(f: (value: T, a: A, b: B, c: C) => T, a: A, b: B, c: C): void;
update<A, B, C, D>(f: (value: T, a: A, b: B, c: C, d: D) => T, a: A, b: B, c: C, d: D): void;
}
export interface Lens<T> extends Atom<T> {}
export interface LensDescriptor<T> {
get(): T;
set(value: T): void;
}
export interface Lifecycle<T> {
from?: (((d: Derivable<T>) => boolean) | Derivable<boolean>);
when?: (((d: Derivable<T>) => boolean) | Derivable<boolean>);
until?: (((d: Derivable<T>) => boolean) | Derivable<boolean>);
skipFirst?: boolean;
once?: boolean;
}
function atom<T>(value: T): Atom<T>;
function derive<T>(f: () => T): Derivable<T>;
function lens<T>(descriptor: LensDescriptor<T>): Lens<T>;
function transact(f: () => void): void;
function transaction<F extends Function>(f: F): F;
function atomically(f: () => void): void;
function atomic<F extends Function>(f: F): F;
function struct(obj: any): Derivable<any>;
function unpack(obj: any): any;
function isAtom(obj: any): boolean;
function isDerivable(obj: any): boolean;
function isDerivation(obj: any): boolean;
function isLens(obj: any): boolean;
function setDebugMode(debugMode: boolean): void;
export interface Ticker {
tick(): void;
release(): void;
}
function ticker(): Ticker;
}
export = derivable