From 600016786ee0ec508dbec2990043ef37299181bd Mon Sep 17 00:00:00 2001 From: A-gambit Date: Mon, 21 Nov 2016 17:36:14 +0200 Subject: [PATCH] generate flow types --- .gitignore | 1 + flow-typed/mobx.js | 356 +++++++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 358 insertions(+), 1 deletion(-) create mode 100644 flow-typed/mobx.js diff --git a/.gitignore b/.gitignore index cc49bd097..1586009cb 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ test/typescript-tests.js* dist/ .build/ yarn.lock +.idea diff --git a/flow-typed/mobx.js b/flow-typed/mobx.js new file mode 100644 index 000000000..630e3a0da --- /dev/null +++ b/flow-typed/mobx.js @@ -0,0 +1,356 @@ +declare module 'mobx' { + declare type extras = { + allowStateChanges: (allowStateChanges: boolean, func: () => T) => T, + getAtom: (thing: any, property?: string) => IDepTreeNode, + getDebugName: (thing: any, property?: string) => string, + getDependencyTree: (thing: any, property?: string) => IDependencyTree, + getObserverTree: (thing: any, property?: string) => IObserverTree, + isComputingDerivation: () => boolean, + isSpyEnabled: () => boolean, + resetGlobalState: () => void, + spyReport: (event: any) => boolean, + spyReportEnd: (change?: any) => void, + spyReportStart: (event: any) => void, + trackTransitions: (onReport?: (c: any) => void) => Lambda, + setReactionScheduler: (fn: (f: () => void) => void) => void + }; + + declare type _ = { + getAdministration: (thing: any, property?: string) => any, + resetGlobalState: () => void + }; + + declare type ITransformer = (object: A) => B; + + declare type IInterceptor = (change: T) => T; + + declare type IMapEntry = [string, V]; + + declare type IMapEntries = IMapEntry[]; + + declare type isObservableMap = (x: any) => boolean; + + declare type ISimpleEventListener = { + (): void + }; + + declare interface IComputedValueOptions { + asStructure: boolean + } + + declare interface IDependencyTree { + name: string, + dependencies?: IDependencyTree[] + } + + declare interface IObserverTree { + name: string, + observers?: IObserverTree[] + } + + declare interface IAtom { + + } + + declare interface IComputedValue { + get(): T, + set(value: T): void, + observe( + listener: (newValue: T, oldValue: T) => void, fireImmediately?: boolean + ): Lambda + } + + declare interface IDerivation { + observing: IObservable[], + newObserving: IObservable[], + dependenciesState: IDerivationState, + runId: number, + unboundDepsCount: number, + ___mapid: string, + onBecomeStale(): any, + recoverFromError(): any + } + + declare interface IDepTreeNode { + name: string, + observing?: IObservable[] + } + + declare interface IObservable { + diffValue: number, + lastAccessedBy: number, + lowestObserverState: IDerivationState, + isPendingUnobservation: boolean, + observers: IDerivation[], + observersIndexes: { + + }, + onBecomeUnobserved(): any + } + + declare interface IReactionPublic { + dispose: () => void + } + + declare interface IInterceptable { + interceptors: IInterceptor[], + intercept(handler: IInterceptor): Lambda + } + + declare interface IListenable { + changeListeners: Function[], + observe( + handler: (change: any, oldValue?: any) => void, fireImmediately?: boolean + ): Lambda + } + + declare interface IObservableArray { + spliceWithArray(index: number, deleteCount?: number, newItems?: T[]): T[], + observe( + listener: (changeData: IArrayChange | IArraySplice) => void, fireImmediately?: boolean + ): Lambda, + intercept(handler: IInterceptor | IArraySplice>): Lambda, + clear(): T[], + peek(): T[], + replace(newItems: T[]): T[], + find( + predicate: (item: T, index: number, array: IObservableArray) => boolean, thisArg?: any, fromIndex?: number + ): T, + remove(value: T): boolean + } + + declare interface IArrayChange { + type: "update", + object: IObservableArray, + index: number, + newValue: T, + oldValue: T + } + + declare interface IArraySplice { + type: "splice", + object: IObservableArray, + index: number, + added: T[], + addedCount: number, + removed: T[], + removedCount: number + } + + declare interface IArrayWillChange { + type: "update", + object: IObservableArray, + index: number, + newValue: T + } + + declare interface IArrayWillSplice { + type: "splice", + object: IObservableArray, + index: number, + added: T[], + removedCount: number + } + + declare interface IKeyValueMap { + [key: string]: V + } + + declare interface IMapChange { + object: ObservableMap, + type: "update" | "add" | "delete", + name: string, + newValue?: any, + oldValue?: any + } + + declare interface IMapWillChange { + object: ObservableMap, + type: "update" | "add" | "delete", + name: string, + newValue?: any + } + + declare interface IObservableObject { + "observable-object": IObservableObject + } + + declare interface IObjectChange { + name: string, + object: any, + type: "update" | "add", + oldValue?: any, + newValue: any + } + + declare interface IObjectWillChange { + object: any, + type: "update" | "add", + name: string, + newValue: any + } + + declare interface IValueWillChange { + object: any, + type: "update", + newValue: T + } + + declare interface IObservableValue { + get(): T, + set(value: T): void, + intercept(handler: IInterceptor>): Lambda, + observe( + listener: (newValue: T, oldValue: T) => void, fireImmediately?: boolean + ): Lambda + } + + declare interface Iterator { + next(): { + done: boolean, + value?: T + } + } + + declare interface Lambda { + (): void, + name?: string + } + + declare function action(target: Object, propertyKey: string, descriptor?: PropertyDescriptor): void; + declare function runInAction(name: string, block: () => T, scope?: any): T; + declare function isAction(thing: any): boolean; + declare function autorun(name: string, view: (r: IReactionPublic) => void, scope?: any): any; + declare function when(predicate: () => boolean, effect: Lambda, scope?: any): any + declare function autorunUntil( + predicate: () => boolean, effect: (r: IReactionPublic) => void, scope?: any + ): any + declare function autorunAsync(func: (r: IReactionPublic) => void, delay?: number, scope?: any): any + declare function reaction( + expression: () => T, effect: (arg: T, r: IReactionPublic) => void, fireImmediately?: boolean, delay?: number, scope?: any + ): any + + declare function computed(target: Object, key: string, baseDescriptor?: PropertyDescriptor): IComputedValue | void + declare function createTransformer( + transformer: ITransformer, onCleanup?: (resultObject: B, sourceObject?: A) => void + ): ITransformer + declare function expr(expr: () => T, scope?: any): T + declare function extendObservable(target: A, ...properties: B[]): A & B + declare function intercept(object: Object, property: string, handler: IInterceptor>): Lambda + declare function isComputed(value: any, property?: string): boolean + + declare function isObservable(value: any, property?: string): boolean + declare function observable(value: T): T & IObservableObject + declare function observe( + object: Object, property: string, listener: (newValue: any, oldValue: any) => void, fireImmediately?: boolean + ): Lambda + + declare function toJS(source: any, detectCycles: boolean, ___alreadySeen: [any, any][]): any + declare function toJSlegacy(source: any, detectCycles?: boolean, ___alreadySeen?: [any, any][]): any + declare function toJSON(source: any, detectCycles?: boolean, ___alreadySeen?: [any, any][]): any + declare function whyRun(thing?: any, prop?: string): string + declare function useStrict(strict: boolean): any + + declare function isStrictModeEnabled(): boolean + declare function untracked(action: () => T): T + + declare function spy(listener: (change: any) => void): Lambda + + declare function transaction(action: () => T, thisArg?: any, report?: boolean): T + + declare function asReference(value: T): T + declare function asStructure(value: T): T + declare function asFlat(value: T): T + declare function asMap(data: IKeyValueMap, modifierFunc?: Function): ObservableMap + declare function fastArray(initialValues?: V[]): IObservableArray + declare function isObservableArray(thing: any): boolean + + declare function map( + initialValues?: IMapEntries | IKeyValueMap, valueModifier?: Function + ): ObservableMap + + declare function isObservableObject(thing: T): boolean + + declare function isArrayLike(x: any): boolean + + declare class BaseAtom extends IAtom { + name: string; + isPendingUnobservation: boolean; + observers: any[]; + observersIndexes: {}; + diffValue: number; + lastAccessedBy: number; + lowestObserverState: IDerivationState; + constructor(name?: string): this; + onBecomeUnobserved(): void; + reportObserved(): void; + reportChanged(): void; + toString(): string + } + + declare class Atom extends BaseAtom, IAtom { + name: string; + onBecomeObservedHandler: () => void; + onBecomeUnobservedHandler: () => void; + isPendingUnobservation: boolean; + isBeingTracked: boolean; + constructor(name?: string, onBecomeObservedHandler?: () => void, onBecomeUnobservedHandler?: () => void): this; + reportObserved(): boolean; + onBecomeUnobserved(): void + } + + declare class Reaction extends IDerivation { + name: string; + observing: any[]; + newObserving: any[]; + dependenciesState: IDerivationState; + diffValue: number; + runId: number; + unboundDepsCount: number; + ___mapid: string; + isDisposed: boolean; + _isScheduled: boolean; + _isTrackPending: boolean; + _isRunning: boolean; + constructor(name: string, onInvalidate: () => void): this; + onBecomeStale(): void; + schedule(): void; + isScheduled(): boolean; + runReaction(): void; + track(fn: () => void): void; + recoverFromError(): void; + dispose(): void; + getDisposer(): Lambda & { + $mosbservable: Reaction + }; + toString(): string; + whyRun(): string + } + + declare class ObservableMap extends IInterceptable> { + $mobx: {}; + name: string; + interceptors: any; + changeListeners: any; + constructor(initialData?: IMapEntries | IKeyValueMap, valueModeFunc?: Function): this; + has(key: string): boolean; + set(key: string, value: V): void; + delete(key: string): boolean; + get(key: string): V; + keys(): string[] & Iterator; + values(): V[] & Iterator; + entries(): IMapEntries & Iterator>; + forEach( + callback: (value: V, key: string, object: IKeyValueMap) => void, thisArg?: any + ): void; + merge(other: ObservableMap | IKeyValueMap): ObservableMap; + clear(): void; + size: number; + toJS(): IKeyValueMap; + toJs(): IKeyValueMap; + toJSON(): IKeyValueMap; + toString(): string; + observe(listener: (changes: IMapChange) => void, fireImmediately?: boolean): Lambda; + intercept(handler: IInterceptor>): Lambda + } +} diff --git a/package.json b/package.json index 91437d294..382c5e635 100644 --- a/package.json +++ b/package.json @@ -73,4 +73,4 @@ "state management", "data flow" ] -} \ No newline at end of file +}