Skip to content

Commit

Permalink
To single module import
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed May 25, 2018
1 parent 1ca32f5 commit e7f32aa
Show file tree
Hide file tree
Showing 43 changed files with 432 additions and 286 deletions.
13 changes: 10 additions & 3 deletions src/api/action.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { invariant, fail, addHiddenProp } from "../utils/utils"
import { createAction, executeAction, IAction } from "../core/action"
import { namedActionDecorator, boundActionDecorator } from "./actiondecorator"
import {
IAction,
addHiddenProp,
boundActionDecorator,
createAction,
executeAction,
fail,
invariant,
namedActionDecorator
} from "../internal"

export interface IActionFactory {
// nameless actions
Expand Down
12 changes: 8 additions & 4 deletions src/api/actiondecorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { fail, addHiddenProp } from "../utils/utils"
import { createAction } from "../core/action"
import { BabelDescriptor } from "../utils/decorators2"
import { action, defineBoundAction } from "./action"
import {
BabelDescriptor,
action,
addHiddenProp,
createAction,
defineBoundAction,
fail
} from "../internal"

function dontReassignFields() {
fail(process.env.NODE_ENV !== "production" && "@action fields are not reassignable")
Expand Down
21 changes: 16 additions & 5 deletions src/api/autorun.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { Lambda, getNextId, invariant, EMPTY_OBJECT } from "../utils/utils"
import { Reaction, IReactionPublic, IReactionDisposer } from "../core/reaction"
import { action, isAction } from "./action"
import { IEqualsComparer, comparer } from "../utils/comparer"
import {
EMPTY_OBJECT,
IEqualsComparer,
IReactionDisposer,
IReactionPublic,
Lambda,
Reaction,
action,
comparer,
getNextId,
invariant,
isAction
} from "../internal"

export interface IAutorunOptions {
delay?: number
Expand Down Expand Up @@ -79,7 +88,9 @@ const run = (f: Lambda) => f()
function createSchedulerFromOptions(opts: IReactionOptions) {
return opts.scheduler
? opts.scheduler
: opts.delay ? (f: Lambda) => setTimeout(f, opts.delay!) : run
: opts.delay
? (f: Lambda) => setTimeout(f, opts.delay!)
: run
}

export function reaction<T>(
Expand Down
18 changes: 10 additions & 8 deletions src/api/become-observed.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { IObservableArray } from "../types/observablearray"
import { ObservableMap } from "../types/observablemap"
import { IComputedValue } from "../core/computedvalue"
import { Lambda } from "../utils/utils"
import { getAtom } from "../types/type-utils"
import { IObservable } from "../core/observable"
import { fail } from "../utils/utils"
import {
IComputedValue,
IObservable,
IObservableArray,
Lambda,
ObservableMap,
fail,
getAtom
} from "../internal"

export function onBecomeObserved(
value: IObservable | IComputedValue<any> | IObservableArray<any> | ObservableMap<any, any>,
Expand Down Expand Up @@ -34,7 +36,7 @@ export function onBecomeUnobserved(thing, arg2, arg3?): Lambda {

function interceptHook(hook: "onBecomeObserved" | "onBecomeUnobserved", thing, arg2, arg3) {
const atom: IObservable =
typeof arg2 === "string" ? getAtom(thing, arg2) : getAtom(thing) as any
typeof arg2 === "string" ? getAtom(thing, arg2) : (getAtom(thing) as any)
const cb = typeof arg2 === "string" ? arg3 : arg2
const orig = atom[hook]

Expand Down
15 changes: 9 additions & 6 deletions src/api/computed.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { comparer } from "../utils/comparer"
import { IComputedValueOptions } from "../core/computedvalue"
import { asObservableObject } from "../types/observableobject"
import { invariant } from "../utils/utils"
import { ComputedValue, IComputedValue } from "../core/computedvalue"
import { createPropDecorator } from "../utils/decorators2"
import {
ComputedValue,
IComputedValue,
IComputedValueOptions,
asObservableObject,
comparer,
createPropDecorator,
invariant
} from "../internal"

export interface IComputed {
<T>(options: IComputedValueOptions<T>): any // decorator
Expand Down
3 changes: 1 addition & 2 deletions src/api/configure.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { globalState, isolateGlobalState } from "../core/globalstate"
import { setReactionScheduler } from "../core/reaction"
import { globalState, isolateGlobalState, setReactionScheduler } from "../internal"

export function configure(options: {
enforceActions?: boolean | "strict"
Expand Down
2 changes: 1 addition & 1 deletion src/api/decorate.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { invariant, isPlainObject } from "../utils/utils"
import { invariant, isPlainObject } from "../internal"

export function decorate<T>(
clazz: new (...args: any[]) => T,
Expand Down
24 changes: 14 additions & 10 deletions src/api/extendobservable.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { isObservableMap } from "../types/observablemap"
import { asObservableObject } from "../types/observableobject"
import { isObservable } from "./isobservable"
import { invariant, fail } from "../utils/utils"
import { startBatch, endBatch } from "../core/observable"
import {
CreateObservableOptions,
asCreateObservableOptions,
asObservableObject,
computedDecorator,
deepDecorator,
refDecorator
} from "./observable"
import { isComputed } from "./iscomputed"
import { computedDecorator } from "./computed"
endBatch,
fail,
invariant,
isComputed,
isObservable,
isObservableMap,
refDecorator,
startBatch
} from "../internal"

export function extendObservable<A extends Object, B extends Object>(
target: A,
Expand Down Expand Up @@ -62,7 +64,9 @@ export function extendObservable<A extends Object, B extends Object>(
const decorator =
decorators && key in decorators
? decorators[key]
: descriptor.get ? computedDecorator : defaultDecorator
: descriptor.get
? computedDecorator
: defaultDecorator

This comment has been minimized.

Copy link
@Beloin

Beloin Jul 6, 2021

Provide null

if (process.env.NODE_ENV !== "production" && typeof decorator !== "function")
return fail(`Not a valid decorator for '${key}', got: ${decorator}`)

Expand Down
4 changes: 1 addition & 3 deletions src/api/extras.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { IDepTreeNode, getObservers, hasObservers } from "../core/observable"
import { unique } from "../utils/utils"
import { getAtom } from "../types/type-utils"
import { IDepTreeNode, getAtom, getObservers, hasObservers, unique } from "../internal"

export interface IDependencyTree {
name: string
Expand Down
3 changes: 1 addition & 2 deletions src/api/flow.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { action } from "./action"
import { fail, noop } from "../utils/utils"
import { action, fail, noop } from "../internal"

let generatorId = 0

Expand Down
18 changes: 12 additions & 6 deletions src/api/intercept-read.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { fail, Lambda } from "../utils/utils"
import { IObservableArray, isObservableArray } from "../types/observablearray"
import { isObservableMap, ObservableMap } from "../types/observablemap"
import { isObservableObject } from "../types/observableobject"
import { IObservableValue, isObservableValue } from "../types/observablevalue"
import { getAdministration } from "../types/type-utils"
import {
IObservableArray,
IObservableValue,
Lambda,
ObservableMap,
fail,
getAdministration,
isObservableArray,
isObservableMap,
isObservableObject,
isObservableValue
} from "../internal"

export type ReadInterceptor<T> = (value: any) => T

Expand Down
20 changes: 13 additions & 7 deletions src/api/intercept.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { IInterceptor } from "../types/intercept-utils"
import { IObservableArray, IArrayWillChange, IArrayWillSplice } from "../types/observablearray"
import { ObservableMap, IMapWillChange } from "../types/observablemap"
import { IObjectWillChange } from "../types/observableobject"
import { IValueWillChange, IObservableValue } from "../types/observablevalue"
import { Lambda } from "../utils/utils"
import { getAdministration } from "../types/type-utils"
import {
IArrayWillChange,
IArrayWillSplice,
IInterceptor,
IMapWillChange,
IObjectWillChange,
IObservableArray,
IObservableValue,
IValueWillChange,
Lambda,
ObservableMap,
getAdministration
} from "../internal"

export function intercept<T>(
value: IObservableValue<T>,
Expand Down
5 changes: 1 addition & 4 deletions src/api/iscomputed.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { isObservableObject } from "../types/observableobject"
import { getAtom } from "../types/type-utils"
import { isComputedValue } from "../core/computedvalue"
import { fail, $mobx } from "../internal"
import { $mobx, fail, getAtom, isComputedValue, isObservableObject } from "../internal"

export function _isComputed(value, property?: string): boolean {
if (value === null || value === undefined) return false
Expand Down
18 changes: 11 additions & 7 deletions src/api/isobservable.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { isObservableArray } from "../types/observablearray"
import { isObservableMap } from "../types/observablemap"
import { isObservableObject, ObservableObjectAdministration } from "../types/observableobject"
import { isAtom } from "../core/atom"
import { isComputedValue } from "../core/computedvalue"
import { isReaction } from "../core/reaction"
import { fail, $mobx } from "../internal"
import {
$mobx,
ObservableObjectAdministration,
fail,
isAtom,
isComputedValue,
isObservableArray,
isObservableMap,
isObservableObject,
isReaction
} from "../internal"

function _isObservable(value, property?: string): boolean {
if (value === null || value === undefined) return false
Expand Down
21 changes: 13 additions & 8 deletions src/api/object-api.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import { isObservableMap, ObservableMap } from "../types/observablemap"
import {
isObservableObject,
$mobx,
IIsObservableObject,
ObservableObjectAdministration
} from "../types/observableobject"
import { isObservableArray, IObservableArray } from "../types/observablearray"
import { fail, invariant, $mobx } from "../internal"
import { startBatch, endBatch } from "../core/observable"
import { getAdministration } from "../types/type-utils"
IObservableArray,
ObservableMap,
ObservableObjectAdministration,
endBatch,
fail,
getAdministration,
invariant,
isObservableArray,
isObservableMap,
isObservableObject,
startBatch
} from "../internal"

export function keys<K>(map: ObservableMap<K, any>): ReadonlyArray<K>
export function keys<T extends Object>(obj: T): ReadonlyArray<string>
Expand Down
42 changes: 27 additions & 15 deletions src/api/observable.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { fail, isES6Map, isPlainObject } from "../utils/utils"
import {
IEnhancer,
IObservableArray,
IObservableDecorator,
IObservableMapInitialValues,
IObservableObject,
IObservableValue,
ObservableMap,
ObservableValue,
createDecoratorForEnhancer,
createDynamicObservableObject,
createObservableArray,
deepEnhancer,
referenceEnhancer,
shallowEnhancer,
extendObservable,
fail,
isES6Map,
isObservable,
isPlainObject,
refStructEnhancer,
IEnhancer
} from "../types/modifiers"
import { IObservableValue, ObservableValue } from "../types/observablevalue"
import { IObservableArray, createObservableArray } from "../types/observablearray"
import { createDecoratorForEnhancer, IObservableDecorator } from "./observabledecorator"
import { isObservable } from "./isobservable"
import { IObservableObject } from "../types/observableobject"
import { extendObservable } from "./extendobservable"
import { IObservableMapInitialValues, ObservableMap } from "../types/observablemap"
import { createDynamicObservableObject } from "../types/dynamicobject"
referenceEnhancer,
shallowEnhancer
} from "../internal"

export type CreateObservableOptions = {
name?: string
Expand Down Expand Up @@ -50,7 +56,9 @@ export function asCreateObservableOptions(thing: any): CreateObservableOptions {
function getEnhancerFromOptions(options: CreateObservableOptions): IEnhancer<any> {
return options.defaultDecorator
? options.defaultDecorator.enhancer
: options.deep === false ? referenceEnhancer : deepEnhancer
: options.deep === false
? referenceEnhancer
: deepEnhancer
}

export const deepDecorator = createDecoratorForEnhancer(deepEnhancer)
Expand All @@ -74,7 +82,11 @@ function createObservable(v: any, arg2?: any, arg3?: any) {
// something that can be converted and mutated?
const res = isPlainObject(v)
? observable.object(v, arg2, arg3)
: Array.isArray(v) ? observable.array(v, arg2) : isES6Map(v) ? observable.map(v, arg2) : v
: Array.isArray(v)
? observable.array(v, arg2)
: isES6Map(v)
? observable.map(v, arg2)
: v

// this value could be converted to a new observable data structure, return it
if (res !== v) return res
Expand Down
16 changes: 11 additions & 5 deletions src/api/observabledecorator.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { asObservableObject } from "../types/observableobject"
import { fail, invariant } from "../utils/utils"
import { IEnhancer } from "../types/modifiers"
import { createPropDecorator, BabelDescriptor } from "../utils/decorators2"
import {
BabelDescriptor,
IEnhancer,
asObservableObject,
createPropDecorator,
fail,
invariant
} from "../internal"

export type IObservableDecorator = {
(target: Object, property: string, descriptor?: PropertyDescriptor): void
Expand All @@ -25,7 +29,9 @@ export function createDecoratorForEnhancer(enhancer: IEnhancer<any>): IObservabl
)
}
const initialValue = descriptor
? descriptor.initializer ? descriptor.initializer.call(target) : descriptor.value
? descriptor.initializer
? descriptor.initializer.call(target)
: descriptor.value
: undefined
asObservableObject(target).addObservableProp(propertyName, initialValue, enhancer)
}
Expand Down
21 changes: 13 additions & 8 deletions src/api/observe.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import { IObservableArray, IArrayChange, IArraySplice } from "../types/observablearray"
import { ObservableMap, IMapDidChange } from "../types/observablemap"
import { IObjectDidChange } from "../types/observableobject"
import { IComputedValue } from "../core/computedvalue"

import { IObservableValue, IValueDidChange } from "../types/observablevalue"
import { Lambda } from "../utils/utils"
import { getAdministration } from "../types/type-utils"
import {
IArrayChange,
IArraySplice,
IComputedValue,
IMapDidChange,
IObjectDidChange,
IObservableArray,
IObservableValue,
IValueDidChange,
Lambda,
ObservableMap,
getAdministration
} from "../internal"

export function observe<T>(
value: IObservableValue<T> | IComputedValue<T>,
Expand Down
Loading

0 comments on commit e7f32aa

Please sign in to comment.