Skip to content

Commit

Permalink
Prepared for the ultimate fix to circular deps
Browse files Browse the repository at this point in the history
  • Loading branch information
mweststrate committed Nov 22, 2017
1 parent f913939 commit 5ae3485
Show file tree
Hide file tree
Showing 33 changed files with 312 additions and 224 deletions.
14 changes: 10 additions & 4 deletions packages/mobx-state-tree/src/core/action.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import { action as mobxAction } from "mobx"

import {
INode,
getStateTreeNode,
IStateTreeNode,
fail,
argsToArray,
IDisposer,
getRoot
} from "../internal"

export type IMiddlewareEventType =
| "action"
| "process_spawn"
Expand Down Expand Up @@ -156,7 +166,3 @@ function runMiddleWares(node: INode, baseCall: IMiddlewareEvent, originalFn: Fun
}
return runNextMiddleware(baseCall)
}

import { INode, getStateTreeNode, IStateTreeNode } from "./node"
import { fail, argsToArray, IDisposer } from "../utils"
import { getRoot } from "./mst-operations"
5 changes: 0 additions & 5 deletions packages/mobx-state-tree/src/core/index.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/mobx-state-tree/src/core/json-patch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { fail } from "../internal"

// https://tools.ietf.org/html/rfc6902
// http://jsonpatch.com/

Expand Down Expand Up @@ -80,5 +82,3 @@ export function splitJsonPath(path: string): string[] {
// path '../../b/c -> .. .. b c
return parts[0] === "" ? parts.slice(1) : parts
}

import { fail } from "../utils"
31 changes: 21 additions & 10 deletions packages/mobx-state-tree/src/core/mst-operations.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
import { IObservableArray, ObservableMap } from "mobx"
import {
INode,
getStateTreeNode,
IStateTreeNode,
isStateTreeNode,
IJsonPatch,
splitJsonPath,
asArray,
EMPTY_OBJECT,
fail,
IDisposer,
ISnapshottable,
IType,
isType
} from "../internal"

/**
* Returns the _actual_ type of the given tree node. (Or throws)
*
Expand Down Expand Up @@ -216,10 +233,10 @@ export function protect(target: IStateTreeNode) {
* }))
*
* const todo = Todo.create()
* todo.done = true // throws!
* todo.toggle() // OK
* unprotect(todo)
* todo.done = false // OK
* todo.done = true // throws!
* todo.toggle() // OK
* unprotect(todo)
* todo.done = false // OK
*/
export function unprotect(target: IStateTreeNode) {
// check all arguments
Expand Down Expand Up @@ -644,9 +661,3 @@ export function walk(target: IStateTreeNode, processor: (item: IStateTreeNode) =
})
processor(node.storedValue)
}

import { IObservableArray, ObservableMap } from "mobx"
import { INode, getStateTreeNode, IStateTreeNode, isStateTreeNode } from "./node"
import { IJsonPatch, splitJsonPath } from "./json-patch"
import { asArray, EMPTY_OBJECT, fail, IDisposer } from "../utils"
import { ISnapshottable, IType, isType } from "./type"
19 changes: 13 additions & 6 deletions packages/mobx-state-tree/src/core/node/create-node.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
import {
canAttachNode,
isStateTreeNode,
getStateTreeNode,
INode,
identity,
noop,
fail,
ObjectNode,
ScalarNode,
IType
} from "../../internal"

export function createNode<S, T>(
type: IType<S, T>,
parent: INode | null,
Expand Down Expand Up @@ -50,9 +63,3 @@ export function createNode<S, T>(
export function isNode(value: any): value is INode {
return value instanceof ScalarNode || value instanceof ObjectNode
}

import { canAttachNode, isStateTreeNode, getStateTreeNode, INode } from "./node-utils"
import { identity, noop, fail } from "../../utils"
import { ObjectNode } from "./object-node"
import { ScalarNode } from "./scalar-node"
import { IType } from "../type"
8 changes: 3 additions & 5 deletions packages/mobx-state-tree/src/core/node/identifier-cache.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { observable, IObservableArray } from "mobx"
import { fail, IType, INode } from "../../internal"

export class IdentifierCache {
private cache = observable.map<IObservableArray<INode>>()

Expand Down Expand Up @@ -63,8 +66,3 @@ export class IdentifierCache {
}
}
}

import { fail } from "../../utils"
import { observable, IObservableArray } from "mobx"
import { IType } from "../type"
import { INode } from "./node-utils"
2 changes: 0 additions & 2 deletions packages/mobx-state-tree/src/core/node/index.ts

This file was deleted.

16 changes: 10 additions & 6 deletions packages/mobx-state-tree/src/core/node/node-utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import {
IType,
IdentifierCache,
IReversibleJsonPatch,
IJsonPatch,
IDisposer,
fail,
IMiddlewareHandler
} from "../../internal"

export interface INode {
readonly type: IType<any, any>

Expand Down Expand Up @@ -99,9 +109,3 @@ export function canAttachNode(value: any) {
export function toJSON(this: IStateTreeNode) {
return getStateTreeNode(this).snapshot
}

import { IType } from "../type"
import { IdentifierCache } from "./identifier-cache"
import { IJsonPatch, IReversibleJsonPatch } from "../json-patch"
import { IDisposer, fail } from "../../utils"
import { IMiddlewareHandler } from "../action"
28 changes: 20 additions & 8 deletions packages/mobx-state-tree/src/core/node/object-node.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
import { reaction } from "mobx"
import { ScalarNode } from "./scalar-node"
import {
ScalarNode,
INode,
isStateTreeNode,
getStateTreeNode,
IJsonPatch,
IReversibleJsonPatch,
splitJsonPath,
splitPatch,
IType,
IDisposer,
extend,
noop,
fail,
registerEventHandler,
addReadOnlyProp,
walk,
IMiddlewareHandler,
createActionInvoker
} from "../../internal"

export class ObjectNode extends ScalarNode implements INode {
middlewares: IMiddlewareHandler[]
Expand Down Expand Up @@ -156,10 +175,3 @@ export class ObjectNode extends ScalarNode implements INode {
this.type.applyPatchLocally(this, subpath, patch)
}
}

import { INode, isStateTreeNode, getStateTreeNode } from "./node-utils"
import { IJsonPatch, IReversibleJsonPatch, splitJsonPath, splitPatch } from "../json-patch"
import { IType } from "../type"
import { IDisposer, extend, noop, fail, registerEventHandler, addReadOnlyProp } from "../../utils"
import { walk } from "../mst-operations"
import { IMiddlewareHandler, createActionInvoker } from "../action"
42 changes: 20 additions & 22 deletions packages/mobx-state-tree/src/core/node/scalar-node.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
import { observable, action, computed } from "mobx"
import { observable, computed } from "mobx"

import {
INode,
toJSON,
IdentifierCache,
escapeJsonPath,
splitJsonPath,
IJsonPatch,
IReversibleJsonPatch,
joinJsonPath,
EMPTY_ARRAY,
noop,
addHiddenFinalProp,
fail,
freeze,
IDisposer,
IType,
IMiddlewareHandler
} from "../../internal"

let nextNodeId = 1
export class ScalarNode implements INode {
Expand Down Expand Up @@ -342,24 +361,3 @@ export class ScalarNode implements INode {
throw fail(`ImmutableNode does not support the addDisposer operation`)
}
}

import { INode, toJSON } from "./node-utils"
import { IdentifierCache } from "./identifier-cache"
import {
escapeJsonPath,
splitJsonPath,
IJsonPatch,
IReversibleJsonPatch,
joinJsonPath
} from "../json-patch"
import {
EMPTY_ARRAY,
noop,
identity,
addHiddenFinalProp,
fail,
freeze,
IDisposer
} from "../../utils"
import { IType } from "../type"
import { IMiddlewareHandler } from "../action"
17 changes: 9 additions & 8 deletions packages/mobx-state-tree/src/core/process.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import {
IMiddlewareEventType,
runWithActionContext,
getActionContext,
getNextActionId,
fail,
argsToArray
} from "../internal"

// based on: https://github.com/mobxjs/mobx-utils/blob/master/src/async-action.ts

export function process<R>(generator: () => IterableIterator<any>): () => Promise<R>
Expand Down Expand Up @@ -137,11 +146,3 @@ export function createProcessSpawner(name: string, generator: Function) {
}
return spawner
}

import {
IMiddlewareEventType,
runWithActionContext,
getActionContext,
getNextActionId
} from "./action"
import { fail, argsToArray } from "../utils"
2 changes: 0 additions & 2 deletions packages/mobx-state-tree/src/core/type/index.ts

This file was deleted.

15 changes: 10 additions & 5 deletions packages/mobx-state-tree/src/core/type/type-checker.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
import {
IType,
fail,
EMPTY_ARRAY,
isPrimitive,
getStateTreeNode,
isStateTreeNode,
isPrimitiveType
} from "../../internal"

export interface IContextEntry {
path: string
type?: IType<any, any>
Expand Down Expand Up @@ -112,8 +122,3 @@ export function typecheckPublic(type: IType<any, any>, value: any): void {
)
}
}

import { IType } from "./type"
import { fail, EMPTY_ARRAY, isPrimitive } from "../../utils"
import { getStateTreeNode, isStateTreeNode } from "../node/node-utils"
import { isPrimitiveType } from "../../types/primitives"
30 changes: 17 additions & 13 deletions packages/mobx-state-tree/src/core/type/type.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import { action } from "mobx"

import {
EMPTY_ARRAY,
fail,
isMutable,
isStateTreeNode,
getStateTreeNode,
IContext,
IValidationResult,
typecheck,
typeCheckFailure,
typeCheckSuccess,
INode,
IStateTreeNode,
IJsonPatch,
getType
} from "../../internal"

export interface ISnapshottable<S> {}

export interface IType<S, T> {
Expand Down Expand Up @@ -197,16 +214,3 @@ export abstract class Type<S, T> extends ComplexType<S, T> implements IType<S, T
export function isType(value: any): value is IType<any, any> {
return typeof value === "object" && value && value.isType === true
}

import { EMPTY_ARRAY, fail, isMutable } from "../../utils"
import { isStateTreeNode, getStateTreeNode } from "../node/node-utils"
import {
IContext,
IValidationResult,
typecheck,
typeCheckFailure,
typeCheckSuccess
} from "./type-checker"
import { INode, IStateTreeNode } from "../node/node-utils"
import { IJsonPatch } from "../json-patch"
import { getType } from "../mst-operations"
Loading

0 comments on commit 5ae3485

Please sign in to comment.