-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.d.ts
48 lines (43 loc) · 1.84 KB
/
index.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
declare module 'immuter' {
type Path = string | string[]
type GetPath = Path | { [key: string]: Path }
type SetPath = Path | { [key: string]: any }
type Updater = (val: any) => any
type UpdatePath = Path | { [key: string]: Updater }
type DelPath = Path | { [key: string]: boolean }
export type ImmuterGet = (path: GetPath, defaults?: any) => any
export type ImmuterSet<State> = (path: SetPath, value?: any) => State
export type ImmuterUpdate<State> = (path: UpdatePath, fn?: Updater) => State
export type ImmuterDel<State> = (path: DelPath) => State
export class ImmuterWrapper<T> {
constructor(obj: T, chain: boolean);
bindObj(wrap: boolean): ImmuterWrapper<T>;
getObj(): T;
get(path: GetPath, defaults?: any): any;
set(path: SetPath, value?: any): T;
update(path: SetPath, fn?: Updater): T;
del(path: DelPath): T;
}
export interface ImmuterInterface {
bindObj<T>(obj: T, wrap?: boolean): ImmuterWrapper<T>;
bindComp(ns?: boolean | string, includes?: Array<string>, excludes?: Array<string>): Function;
get<T>(obj: T, path: GetPath, defaults?: any): any;
set<T>(obj: T, path: SetPath, value?: any): T;
update<T>(obj: T, path: SetPath, fn?: Updater): T;
del<T>(obj: T, path: DelPath): T;
Struct: StructConstructor;
}
type StructT<T> = T & {
clone(fn: (struct: StructT<T>) => (StructT<T> | void)): StructT<T>;
}
export function setIn<T extends Object, F>(data: T, keyPath: Array<string | number> | ((key: T) => F)): (val: F) => T;
export interface StructConstructor {
<T>(obj: T): StructT<T>;
isStruct<T>(obj: T): boolean;
clone<T>(obj: T, fn?: (struct: StructT<T>) => (StructT<T> | void)): StructT<T>;
debug(obj: any, json?: boolean, out?: boolean);
}
export const Struct: StructConstructor
export const Immuter: ImmuterInterface
export default Immuter
}