Skip to content

Commit

Permalink
new types
Browse files Browse the repository at this point in the history
  • Loading branch information
A-gambit committed Dec 27, 2016
1 parent 9ebeea5 commit 91f773c
Showing 1 changed file with 153 additions and 100 deletions.
253 changes: 153 additions & 100 deletions flow-typed/mobx.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,26 @@ declare module 'mobx' {
spyReportEnd: (change?: any) => void,
spyReportStart: (event: any) => void,
setReactionScheduler: (fn: (f: () => void) => void) => void
};
}

declare type IObservableMapInitialValues<V> = IMapEntries<V> | IKeyValueMap<V> | IMap<string, V>;

declare interface IReactionOptions {
context?: any;
fireImmediately?: boolean;
delay?: number;
compareStructural?: boolean;
name?: string;
}

declare interface IInterceptable<T> {
interceptors: IInterceptor<T>[] | any,
intercept(handler: IInterceptor<T>): Lambda
interceptors: IInterceptor<T>[] | any;
intercept(handler: IInterceptor<T>): Lambda;
}

declare type _ = {
getAdministration: (thing: any, property?: string) => any,
resetGlobalState: () => void
getAdministration: (thing: any, property?: string) => any;
resetGlobalState: () => void;
};

declare type ITransformer<A, B> = (object: A) => B;
Expand All @@ -34,190 +44,231 @@ declare module 'mobx' {

declare type IMapEntries<V> = IMapEntry<V>[];

declare interface IMap<K, V> {
clear(): void;
delete(key: K): boolean;
forEach(callbackfn: (value: V, index: K, map: IMap<K, V>) => void, thisArg?: any): void;
get(key: K): V | any;
has(key: K): boolean;
set(key: K, value?: V): this;
size: number;
}

declare type isObservableMap = (x: any) => boolean;

declare type ISimpleEventListener = {
(): void
(): void;
};

declare interface IComputedValueOptions {
asStructure: boolean
declare interface IComputedValueOptions<T> {
compareStructural?: boolean;
name?: string;
setter?: (value: T) => void;
context?: any;
}

declare type IDerivationState = 'NOT_TRACKING' | 'UP_TO_DATE' | 'POSSIBLY_STALE' | 'STALE'
declare type PropertyDescriptor = any

declare interface IComputed {
<T>(func: () => T, setter?: (value: T) => void): IComputedValue<T>;
<T>(func: () => T, options: IComputedValueOptions<T>): IComputedValue<T>;
(target: Object, key: string, baseDescriptor?: PropertyDescriptor): void;
struct(target: Object, key: string, baseDescriptor?: PropertyDescriptor): void;
}

declare interface IDependencyTree {
name: string,
dependencies?: IDependencyTree[]
name: string;
dependencies?: IDependencyTree[];
}

declare interface IObserverTree {
name: string,
observers?: IObserverTree[]
name: string;
observers?: IObserverTree[];
}

declare interface IAtom {

}

declare type IDerivationState = 'NOT_TRACKING' | 'UP_TO_DATE' | 'POSSIBLY_STALE' | 'STALE'
declare type PropertyDescriptor = any

declare interface IComputedValue<T> {
get(): T,
set(value: T): void,
get(): T;
set(value: T): void;
observe(
listener: (newValue: T, oldValue: T) => void, fireImmediately?: boolean
): Lambda
): Lambda;
}

declare interface IObservable {
diffValue: number,
lastAccessedBy: number,
lowestObserverState: IDerivationState,
isPendingUnobservation: boolean,
observers: IDerivation[],
observersIndexes: {

},
onBecomeUnobserved(): any
diffValue: number;
lastAccessedBy: number;
lowestObserverState: IDerivationState;
isPendingUnobservation: boolean;
observers: IDerivation[];
observersIndexes: {};
onBecomeUnobserved(): any;
}

declare interface IDepTreeNode {
name: string,
observing?: IObservable[]
name: string;
observing?: IObservable[];
}

declare interface IDerivation {
name: string,
observing: IObservable[],
newObserving: ?IObservable[],
dependenciesState: IDerivationState,
runId: number,
unboundDepsCount: number,
___mapid: string,
onBecomeStale(): any,
recoverFromError(): any
name: string;
observing: IObservable[];
newObserving: ?IObservable[];
dependenciesState: IDerivationState;
runId: number;
unboundDepsCount: number;
___mapid: string;
onBecomeStale(): any;
recoverFromError(): any;
}

declare interface IReactionPublic {
dispose: () => void
dispose: () => void;
}

declare interface IListenable {
changeListeners: any,
changeListeners: any;
observe(
handler: (change: any, oldValue?: any) => void, fireImmediately?: boolean
): Lambda
): Lambda;
}

declare interface IObservableArray<T> extends Array<T> {
spliceWithArray(index: number, deleteCount?: number, newItems?: T[]): T[],
spliceWithArray(index: number, deleteCount?: number, newItems?: T[]): T[];
observe(
listener: (changeData: IArrayChange<T> | IArraySplice<T>) => void, fireImmediately?: boolean
): Lambda,
intercept<T>(handler: IInterceptor<IArrayChange<T> | IArraySplice<T>>): Lambda,
clear(): T[],
peek(): T[],
replace(newItems: T[]): T[],
): Lambda;
intercept<T>(handler: IInterceptor<IArrayChange<T> | IArraySplice<T>>): Lambda;
clear(): T[];
peek(): T[];
replace(newItems: T[]): T[];
find(
predicate: (item: T, index: number, array: Array<T>) => boolean, thisArg?: any, fromIndex?: number
): T | any,
remove(value: T): boolean
): T | any;
remove(value: T): boolean;
}

declare interface IArrayChange<T> {
type: 'update',
object: IObservableArray<T>,
index: number,
newValue: T,
oldValue: T
type: 'update';
object: IObservableArray<T>;
index: number;
newValue: T;
oldValue: T;
}

declare interface IArraySplice<T> {
type: 'splice',
object: IObservableArray<T>,
index: number,
added: T[],
addedCount: number,
removed: T[],
removedCount: number
type: 'splice';
object: IObservableArray<T>;
index: number;
added: T[];
addedCount: number;
removed: T[];
removedCount: number;
}

declare interface IArrayWillChange<T> {
type: 'update',
object: IObservableArray<T>,
index: number,
newValue: T
type: 'update';
object: IObservableArray<T>;
index: number;
newValue: T;
}

declare interface IArrayWillSplice<T> {
type: 'splice',
object: IObservableArray<T>,
index: number,
added: T[],
removedCount: number
type: 'splice';
object: IObservableArray<T>;
index: number;
added: T[];
removedCount: number;
}

declare interface IKeyValueMap<V> {
[key: string]: V
[key: string]: V;
}

declare interface IMapChange<T> {
object: ObservableMap<T>,
type: 'update' | 'add' | 'delete',
name: string,
newValue?: any,
oldValue?: any
object: ObservableMap<T>;
type: 'update' | 'add' | 'delete';
name: string;
newValue?: any;
oldValue?: any;
}

declare interface IMapWillChange<T> {
object: ObservableMap<T>,
type: 'update' | 'add' | 'delete',
name: string,
newValue?: any
object: ObservableMap<T>;
type: 'update' | 'add' | 'delete';
name: string;
newValue?: any;
}

declare interface IObservableObject {}

declare interface IObjectChange {
name: string,
object: any,
type: 'update' | 'add',
oldValue?: any,
newValue: any
name: string;
object: any;
type: 'update' | 'add';
oldValue?: any;
newValue: any;
}

declare interface IObjectWillChange {
object: any,
type: 'update' | 'add',
name: string,
newValue: any
object: any;
type: 'update' | 'add';
name: string;
newValue: any;
}

declare interface IValueWillChange<T> {
object: any,
type: 'update',
newValue: T
object: any;
type: 'update';
newValue: T;
}

declare interface IObservableValue<T> {
get(): T,
set(value: T): void,
intercept(handler: IInterceptor<IValueWillChange<T>>): Lambda,
get(): T;
set(value: T): void;
intercept(handler: IInterceptor<IValueWillChange<T>>): Lambda;
observe(
listener: (newValue: T, oldValue: T) => void, fireImmediately?: boolean
): Lambda
): Lambda;
}

declare interface IObservableFactory {
(value: any, key?: string, baseDescriptor?: PropertyDescriptor): any;
}

declare class IObservableFactories {
box<T>(value?: T, name?: string): IObservableValue<T>;
shallowBox<T>(value?: T, name?: string): IObservableValue<T>;
array<T>(initialValues?: T[], name?: string): IObservableArray<T>;
shallowArray<T>(initialValues?: T[], name?: string): IObservableArray<T>;
map<T>(initialValues?: IObservableMapInitialValues<T>, name?: string): ObservableMap<T>;
shallowMap<T>(initialValues?: IObservableMapInitialValues<T>, name?: string): ObservableMap<T>;
object<T>(props: T, name?: string): T & IObservableObject;
shallowObject<T>(props: T, name?: string): T & IObservableObject;
ref(target: Object, property?: string, descriptor?: PropertyDescriptor): any;
shallow(target: Object, property?: string, descriptor?: PropertyDescriptor): any;
deep(target: Object, property?: string, descriptor?: PropertyDescriptor): any;
}

declare interface Iterator<T> {
next(): {
done: boolean,
value?: T
}
};
}

declare interface Lambda {
(): void,
name?: string
(): void;
name?: string;
}

declare interface IActionFactory {
(a1: any, a2?: any, a3?: any, a4?: any, a6?: any): any;
bound(target: Object, propertyKey: string, descriptor?: PropertyDescriptor): void;
}

declare class ObservableMap<V> {
Expand Down Expand Up @@ -247,14 +298,16 @@ declare module 'mobx' {
intercept(handler: IInterceptor<IMapWillChange<V>>): Lambda
}

declare function extendShallowObservable(target: any): any;

declare function action(targetOrName: any, propertyKeyOrFuc?: any, descriptor?: PropertyDescriptor): any;
declare function runInAction<T>(name: string, block: () => T, scope?: any): T;
declare function isAction(thing: any): boolean;
declare function autorun(nameOrFunction: string | (r: IReactionPublic) => void, viewOrScope?: any, scope?: any): any;
declare function when(predicate: () => boolean, effect: Lambda, scope?: any): any
declare function autorunAsync(func: (r: IReactionPublic) => void, delay?: number, scope?: any): any
declare function reaction<T>(
expression: () => T, effect: (arg: T, r: IReactionPublic) => void, fireImmediately?: boolean, delay?: number, scope?: any
expression: (r: IReactionPublic) => T, effect: (arg: T, r: IReactionPublic) => void, fireImmediately?: boolean, delay?: number, scope?: any
): any

declare function computed<T>(target: any, key?: string, baseDescriptor?: PropertyDescriptor): any
Expand Down

0 comments on commit 91f773c

Please sign in to comment.