Skip to content

Commit c96e3de

Browse files
Merge pull request cerebral#169 from cerebral/fixes5
Fixes5
2 parents 215562c + 1d54ded commit c96e3de

File tree

16 files changed

+60
-68
lines changed

16 files changed

+60
-68
lines changed

packages/node_modules/overmind-angular/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@
2929
"es",
3030
"react"
3131
],
32-
"engines": {
33-
"browsers": [
34-
"last 1 Chrome versions"
35-
]
36-
},
3732
"dependencies": {
3833
"@types/node": "^10.5.1",
3934
"overmind": "next",

packages/node_modules/overmind-devtools/src/components/ActionOperator/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const ActionOperator: SFC<Props> = ({
2525
const { state, actions } = useOvermind()
2626
const isExpanded = state.expandAllActionDetails || !operator.isCollapsed
2727

28+
console.log(operator.mutations)
2829
return (
2930
<div>
3031
{value === undefined ? null : (

packages/node_modules/overmind-react/package.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131
"es",
3232
"react"
3333
],
34-
"engines": {
35-
"browsers": [
36-
"last 1 Chrome versions"
37-
]
38-
},
3934
"dependencies": {
4035
"@types/node": "^10.5.1",
4136
"overmind": "next",
@@ -45,7 +40,7 @@
4540
"@types/jest": "^23.1.4",
4641
"@types/react": "^16.7.13",
4742
"jest": "^23.5.0",
48-
"react": "^16.7.0-alpha.1",
43+
"react": "^16.7.0-alpha.2",
4944
"react-test-renderer": "^16.4.1",
5045
"rimraf": "^2.6.2",
5146
"ts-jest": "^23.10.4",

packages/node_modules/overmind-react/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export const createConnect = <A extends Overmind<Configuration>>(
145145
componentInstanceId = componentInstanceId++
146146
currentFlushId = 0
147147
componentDidMount() {
148+
console.log(this.tree)
148149
overmind.eventHub.emitAsync(EventType.COMPONENT_ADD, {
149150
componentId: populatedComponent.__componentId,
150151
componentInstanceId: this.componentInstanceId,

packages/node_modules/overmind-vue/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131
"es",
3232
"react"
3333
],
34-
"engines": {
35-
"browsers": [
36-
"last 1 Chrome versions"
37-
]
38-
},
3934
"dependencies": {
4035
"@types/node": "^10.5.1",
4136
"overmind": "next",

packages/node_modules/overmind/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131
"es",
3232
"config"
3333
],
34-
"engines": {
35-
"browsers": [
36-
"last 1 Chrome versions"
37-
]
38-
},
3934
"dependencies": {
4035
"@types/node": "^10.5.1",
4136
"is-plain-object": "^2.0.4",

packages/node_modules/overmind/src/derived.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Overmind, TAction, TDerive, StateObject } from './'
1+
import { Overmind, TAction, TDerive, TStateObject } from './'
22

33
type State = {
44
foo: string
@@ -23,7 +23,7 @@ describe.only('Derived', () => {
2323
state: typeof state
2424
}
2525

26-
type Derive<Parent extends StateObject, Value> = TDerive<
26+
type Derive<Parent extends TStateObject, Value> = TDerive<
2727
Config,
2828
Parent,
2929
Value
@@ -60,7 +60,7 @@ describe.only('Derived', () => {
6060
actions: typeof config.actions
6161
}
6262
type Action<Input = void> = TAction<Config, Input>
63-
type Derive<Parent extends StateObject, Value> = TDerive<
63+
type Derive<Parent extends TStateObject, Value> = TDerive<
6464
Config,
6565
Parent,
6666
Value
@@ -110,7 +110,7 @@ describe.only('Derived', () => {
110110
actions: typeof config.actions
111111
}
112112
type Action<Input = void> = TAction<Config, Input>
113-
type Derive<Parent extends StateObject, Value> = TDerive<
113+
type Derive<Parent extends TStateObject, Value> = TDerive<
114114
Config,
115115
Parent,
116116
Value
@@ -147,7 +147,7 @@ describe.only('Derived', () => {
147147
actions: typeof config.actions
148148
}
149149
type Action<Input = void> = TAction<Config, Input>
150-
type Derive<Parent extends StateObject, Value> = TDerive<
150+
type Derive<Parent extends TStateObject, Value> = TDerive<
151151
Config,
152152
Parent,
153153
Value

packages/node_modules/overmind/src/index.ts

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ import {
1616
TConfig,
1717
TDerive,
1818
TOperator,
19-
TReaction,
2019
TValueContext,
2120
TOnInitialize,
22-
StateObject,
21+
TStateObject,
2322
} from './types'
2423

2524
export * from './types'
@@ -34,14 +33,12 @@ type TheConfig = IConfig & TConfig<{ actions: {} }>
3433

3534
export type Action<Value = void> = TAction<TheConfig, Value>
3635

37-
export type Derive<Parent extends StateObject, Value> = TDerive<
36+
export type Derive<Parent extends TStateObject, Value> = TDerive<
3837
TheConfig,
3938
Parent,
4039
Value
4140
>
4241

43-
export type Reaction = TReaction<TheConfig>
44-
4542
export type OnInitialize = TOnInitialize<TheConfig>
4643

4744
const isPlainObject = require('is-plain-object')
@@ -179,6 +176,7 @@ export class Overmind<Config extends Configuration> implements Configuration {
179176
operatorId: -1,
180177
path: [],
181178
emit: this.eventHub.emit.bind(this.eventHub),
179+
send: this.devtools ? this.devtools.send.bind(this.devtools) : () => {},
182180
}
183181
}
184182
private createContext(value, execution, tree) {
@@ -745,13 +743,27 @@ export function mutate<Input, Config extends Configuration = TheConfig>(
745743
if (err) next(err)
746744
else {
747745
startDebugOperator('mutate', operation, context)
748-
const mutationsTree = context.proxyStateTree.getMutationTree()
749-
operation({ ...context, state: mutationsTree.state })
750-
const newContext = createContext(context, context.value)
751-
context.execution.emit(EventType.MUTATIONS, {
752-
...newContext.execution,
753-
mutations: mutationsTree.mutations,
746+
const mutationTree = context.proxyStateTree.getMutationTree()
747+
if (!IS_PRODUCTION) {
748+
mutationTree.onMutation((mutation) => {
749+
context.execution.emit(EventType.MUTATIONS, {
750+
...context.execution,
751+
operatorId: context.execution.operatorId + 1,
752+
mutations: [mutation],
753+
})
754+
})
755+
}
756+
const maybePromise: any = operation({
757+
...context,
758+
state: mutationTree.state,
754759
})
760+
const newContext = createContext(
761+
context,
762+
maybePromise instanceof Promise
763+
? maybePromise.then(() => context.value)
764+
: context.value
765+
)
766+
755767
stopDebugOperator(newContext)
756768
next(null, newContext)
757769
}

packages/node_modules/overmind/src/internalTypes.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IMutation, ProxyStateTree } from 'proxy-state-tree'
2-
import { Configuration, TAction, TOperator, StateObject } from './types'
2+
import { Configuration, TAction, TOperator, TStateObject } from './types'
33

44
export type SubType<Base, Condition> = Pick<
55
Base,
@@ -115,14 +115,14 @@ export type TBaseContext<Config extends Configuration> = Config['effects'] & {
115115

116116
type Derived = (parent: any, config: any) => any
117117

118-
export type ResolveState<State extends StateObject> = State extends undefined
118+
export type ResolveState<State extends TStateObject> = State extends undefined
119119
? {}
120120
: {
121121
[P in keyof State]: State[P] extends Derived
122122
? ReturnType<State[P]>
123123
: State[P] extends Array<any>
124124
? State[P]
125-
: State[P] extends StateObject
125+
: State[P] extends TStateObject
126126
? ResolveState<State[P]>
127127
: State[P]
128128
}

packages/node_modules/overmind/src/types.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ export type BaseApp = {
1818
actions: {}
1919
}
2020

21-
export type StateObject =
21+
export type TStateObject =
2222
| {
2323
[key: string]:
24-
| StateObject
24+
| TStateObject
2525
| string
2626
| TDerive<any, any, any>
2727
| number
@@ -68,20 +68,13 @@ export type TOperator<Config extends Configuration, Input, Output> = (
6868

6969
export type TDerive<
7070
Config extends Configuration,
71-
Parent extends StateObject,
71+
Parent extends TStateObject,
7272
Value
7373
> = (
7474
parent: ResolveState<Parent>,
7575
state: ResolveState<Config['state'] & {}>
7676
) => Value
7777

78-
export type TReaction<Config extends Configuration> = (
79-
reaction: (
80-
getState: (state: ResolveState<Config['state']>) => any,
81-
action: TAction<Config, void> | TOperator<Config, void, any>
82-
) => any
83-
) => any
84-
8578
export type TOnInitialize<Config extends Configuration> = (
8679
context: TValueContext<Config, Overmind<Config>>
8780
) => void

0 commit comments

Comments
 (0)