// @flow export 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, getGlobalState: () => any, getObserverTree: (thing: any, property?: string) => IObserverTree, isComputingDerivation: () => boolean, isSpyEnabled: () => boolean, resetGlobalState: () => void, shareGlobalState: () => void, spyReport: (event: any) => boolean, spyReportEnd: (change?: any) => void, spyReportStart: (event: any) => void, setReactionScheduler: (fn: (f: () => void) => void) => void, onReactionError: (func: (error: Error) => void) => void } declare export var extras: Extras export type IObservableMapInitialValues = IMapEntries | KeyValueMap | IMap export interface IReactionOptions { context?: any, fireImmediately?: boolean, delay?: number, compareStructural?: boolean, name?: string } export interface IInterceptable { interceptors: IInterceptor[] | any, intercept(handler: IInterceptor): Lambda } export type _ = { getAdministration: (thing: any, property?: string) => any, resetGlobalState: () => void } export type ITransformer = (object: A) => B export type IInterceptor = (change: T) => T export type IMapEntry = [string, V] export type IMapEntries = IMapEntry[] export interface IMap { clear(): void, delete(key: K): boolean, forEach(callbackfn: (value: V, index: K, map: IMap) => void, thisArg?: any): void, get(key: K): V | any, has(key: K): boolean, set(key: K, value?: V): any, size: number } declare export function isObservableMap (x: any): boolean declare type ISimpleEventListener = { (): void } export interface IComputedValueOptions { 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 export interface IComputed { (func: () => T, setter?: (value: T) => void): IComputedValue, (func: () => T, options: IComputedValueOptions): IComputedValue, (target: Object, key: string, baseDescriptor?: PropertyDescriptor): void, struct(target: Object, key: string, baseDescriptor?: PropertyDescriptor): void } export interface IDependencyTree { name: string, dependencies?: IDependencyTree[] } export interface IObserverTree { name: string, observers?: IObserverTree[] } export interface IAtom {} export interface IComputedValue { get(): T, set(value: T): void, observe(listener: (newValue: T, oldValue: T) => void, fireImmediately?: boolean): Lambda } export interface IObservable { diffValue: number, lastAccessedBy: number, lowestObserverState: IDerivationState, isPendingUnobservation: boolean, observers: IDerivation[], observersIndexes: {}, onBecomeUnobserved(): any } export interface IDepTreeNode { name: string, observing?: IObservable[] } export interface IDerivation { name: string, observing: IObservable[], newObserving: ?(IObservable[]), dependenciesState: IDerivationState, runId: number, unboundDepsCount: number, ___mapid: string, onBecomeStale(): any, recoverFromError(): any } export interface IReactionPublic { dispose: () => void } declare export class IListenable { changeListeners: any, observe(handler: (change: any, oldValue?: any) => void, fireImmediately?: boolean): Lambda } export interface IObservableArray extends Array { spliceWithArray(index: number, deleteCount?: number, newItems?: T[]): T[], observe( listener: (changeData: IArrayChange | IArraySplice) => void, fireImmediately?: boolean ): Lambda, intercept(handler: IInterceptor | IArrayWillSplice>): Lambda, intercept(handler: IInterceptor | IArraySplice>): Lambda, // TODO: remove in 4.0 intercept(handler: IInterceptor | IArraySplice>): Lambda, // TODO: remove in 4.0 clear(): T[], peek(): T[], replace(newItems: T[]): T[], find( predicate: (item: T, index: number, array: Array) => boolean, thisArg?: any, fromIndex?: number ): T | any, findIndex( predicate: (item: T, index: number, array: Array) => boolean, thisArg?: any, fromIndex?: number ): number, remove(value: T): boolean } export interface IArrayChange { type: "update", object: IObservableArray, index: number, newValue: T, oldValue: T } export interface IArraySplice { type: "splice", object: IObservableArray, index: number, added: T[], addedCount: number, removed: T[], removedCount: number } export interface IArrayWillChange { type: "update", object: IObservableArray, index: number, newValue: T } export interface IArrayWillSplice { type: "splice", object: IObservableArray, index: number, added: T[], removedCount: number } export type KeyValueMap = { [key: string]: V } export interface IMapChange { object: ObservableMap, type: "update" | "add" | "delete", name: string, newValue?: any, oldValue?: any } export interface IMapWillChange { object: ObservableMap, type: "update" | "add" | "delete", name: string, newValue?: any } export interface IObservableObject {} export interface IObjectChange { name: string, object: any, type: "update" | "add", oldValue?: any, newValue: any } export interface IObjectWillChange { object: any, type: "update" | "add", name: string, newValue: any } export interface IValueWillChange { object: any, type: "update", newValue: T } export interface IValueDidChange extends IValueWillChange { oldValue: ?T } export interface IObservableValue { get(): T, set(value: T): void, intercept(handler: IInterceptor>): Lambda, observe(listener: (change: IValueDidChange) => void, fireImmediately?: boolean): Lambda } export interface IEnhancer { (newValue: T, oldValue: T | void, name: string): T, } export interface IModifierDescriptor { isMobxModifierDescriptor: boolean, initialValue: T | void, enhancer: IEnhancer, } export interface IObservableFactory { // observable overloads (target: Object, key: string, baseDescriptor?: PropertyDescriptor): any, (value: Array): IObservableArray, (value: string): IObservableValue, (value: boolean): IObservableValue, (value: number): IObservableValue, (value: Date): IObservableValue, (value: RegExp): IObservableValue, (value: Function): IObservableValue, (value: null | void): IObservableValue, (value: null | void): IObservableValue, (): IObservableValue, (value: IMap): ObservableMap, (value: IModifierDescriptor): T, (value: T): T, (value: T): IObservableValue, (): IObservableValue, } declare export class IObservableFactories { box(value?: T, name?: string): IObservableValue, shallowBox(value?: T, name?: string): IObservableValue, array(initialValues?: T[], name?: string): IObservableArray, shallowArray(initialValues?: T[], name?: string): IObservableArray, map(initialValues?: IObservableMapInitialValues, name?: string): ObservableMap, shallowMap( initialValues?: IObservableMapInitialValues, name?: string ): ObservableMap, object(props: T, name?: string): T & IObservableObject, shallowObject(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 } export interface Iterator { next(): { done: boolean, value?: T } } export interface Lambda { (): void, name?: string } export interface IActionFactory { (a1: any, a2?: any, a3?: any, a4?: any, a6?: any): any, bound(target: Object, propertyKey: string, descriptor?: PropertyDescriptor): void } declare export class ObservableMap { $mobx: {}, name: string, interceptors: any, changeListeners: any, constructor(initialData?: IMapEntries | KeyValueMap, 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: KeyValueMap) => void, thisArg?: any ): void, merge(other: ObservableMap | KeyValueMap): ObservableMap, clear(): void, replace(other: ObservableMap | KeyValueMap): ObservableMap, size: number, toJS(): KeyValueMap, toJs(): KeyValueMap, toJSON(): KeyValueMap, toString(): string, observe(listener: (changes: IMapChange) => void, fireImmediately?: boolean): Lambda, intercept(handler: IInterceptor>): Lambda } declare export function extendShallowObservable(target: any): any declare export function action( targetOrName: any, propertyKeyOrFuc?: any, descriptor?: PropertyDescriptor ): any declare export function action(name: string, func: T): T declare export function action(func: T): T declare export function runInAction(name: string, block: () => T, scope?: any): T declare export function runInAction(block: () => T, scope?: any): T declare export function isAction(thing: any): boolean declare export function autorun( nameOrFunction: string | ((r: IReactionPublic) => any), viewOrScope?: any, scope?: any ): any declare export function when(name: string, cond: () => boolean, effect: Lambda, scope?: any): any declare export function when(cond: () => boolean, effect: Lambda, scope?: any): any declare export function autorunAsync( func: (r: IReactionPublic) => any, delay?: number, scope?: any ): any declare export function reaction( expression: (r: IReactionPublic) => T, effect: (arg: T, r: IReactionPublic) => void, fireImmediately?: boolean, delay?: number, scope?: any ): any declare export function computed( target: any, key?: string, baseDescriptor?: PropertyDescriptor ): any declare export function createTransformer( transformer: ITransformer, onCleanup?: (resultObject: ?B | any, sourceObject?: A) => void ): ITransformer declare export function expr(expr: () => T, scope?: any): T declare export function extendObservable(target: A, ...properties: B[]): A & B declare export function intercept(object: Object, property: string, handler: IInterceptor): Lambda declare export function isComputed(value: any, property?: string): boolean declare export function isObservable(value: any, property?: string): boolean declare export var observable: IObservableFactory & IObservableFactories & { deep: { struct(initialValue?: T): T }, ref: { struct(initialValue?: T): T } } declare export function observe( value: IObservableValue | IComputedValue, listener: (change: IValueDidChange) => void, fireImmediately?: boolean ): Lambda declare export function observe( observableArray: IObservableArray, listener: (change: IArrayChange | IArraySplice) => void, fireImmediately?: boolean ): Lambda declare export function observe( observableMap: ObservableMap, listener: (change: IMapChange) => void, fireImmediately?: boolean ): Lambda declare export function observe( observableMap: ObservableMap, property: string, listener: (change: IValueDidChange) => void, fireImmediately?: boolean ): Lambda declare export function observe( object: any, listener: (change: IObjectChange) => void, fireImmediately?: boolean ): Lambda declare export function observe( object: any, property: string, listener: (change: IValueDidChange) => void, fireImmediately?: boolean ): Lambda declare export function toJS(source: any, detectCycles?: boolean, ___alreadySeen?: [any, any][]): any declare export function toJSlegacy( source: any, detectCycles?: boolean, ___alreadySeen?: [any, any][] ): any declare export function whyRun(thing?: any, prop?: string): string declare export function useStrict(strict: boolean): void declare export function isStrictModeEnabled(): boolean declare export function untracked(action: () => T): T declare export function spy(listener: (change: any) => void): Lambda declare export function transaction(action: () => T, thisArg?: any, report?: boolean): T declare export function asReference(value: T): T declare export function asStructure(value: T): T declare export function asFlat(value: T): T declare export function asMap(data: KeyValueMap, modifierFunc?: Function): ObservableMap declare export function isObservableArray(thing: any): boolean declare export function map( initialValues?: IMapEntries | KeyValueMap, valueModifier?: Function ): ObservableMap declare export function isObservableObject(thing: T): boolean declare export function isArrayLike(x: any): boolean declare export class BaseAtom { 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 export class Atom { name: string, onBecomeObservedHandler: () => void, onBecomeUnobservedHandler: () => void, isPendingUnobservation: boolean, isBeingTracked: boolean, constructor( name?: string, onBecomeObservedHandler?: () => void, onBecomeUnobservedHandler?: () => void ): this, reportObserved(): boolean, onBecomeUnobserved(): void } declare export class Reaction { 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 }