Skip to content

Commit 93576a5

Browse files
Merge pull request cerebral#37 from cerebral/effects
refactor(overmind): replace context and providers term with effects
2 parents f785f6e + 1830809 commit 93576a5

File tree

11 files changed

+109
-109
lines changed

11 files changed

+109
-109
lines changed
File renamed without changes.

packages/demos/todomvc/src/app/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
import App, { TConnect, TContext, IAction } from 'overmind/react'
2-
import * as providers from './providers'
1+
import App, { TConnect, TEffects, TAction } from 'overmind/react'
2+
import * as effects from './effects'
33
import actions from './actions'
44
import state from './state'
55

6-
export type Context = TContext<typeof state, typeof providers>
6+
export type Effects = TEffects<typeof state, typeof effects>
77

8-
export type Action = IAction<typeof state, Context>
8+
export type Action = TAction<typeof state, Effects>
99

1010
const app = new App(
1111
{
1212
state,
1313
actions,
14-
providers,
14+
effects,
1515
},
1616
{
1717
devtools: 'localhost:1234',

packages/node_modules/action-chain/src/ActionBase.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ export class StopExecution {
66
this.value = value
77
}
88
}
9-
export class ActionBase<Context, InitialValue, Value = InitialValue> {
9+
export class ActionBase<Effects, InitialValue, Value = InitialValue> {
1010
static nextActionId: number = 0
1111
private initialActionId: number
12-
private actionChain: ActionChain<Context>
12+
private actionChain: ActionChain<Effects>
1313
private runOperators: (
1414
value: any,
1515
executionContext: {
@@ -19,7 +19,7 @@ export class ActionBase<Context, InitialValue, Value = InitialValue> {
1919
newPath?: string
2020
) => any | Promise<any>
2121
constructor(
22-
actionChain: ActionChain<Context>,
22+
actionChain: ActionChain<Effects>,
2323
initialActionId: number = ActionBase.nextActionId++,
2424
runOperators?: (
2525
value: any,
@@ -88,7 +88,7 @@ export class ActionBase<Context, InitialValue, Value = InitialValue> {
8888
type: string,
8989
name: string,
9090
cb: any
91-
): [ActionChain<Context>, number, any] => {
91+
): [ActionChain<Effects>, number, any] => {
9292
return [
9393
this.actionChain,
9494
this.initialActionId,
@@ -117,7 +117,7 @@ export class ActionBase<Context, InitialValue, Value = InitialValue> {
117117

118118
const path = executionContextWithPath.__path
119119

120-
const context = this.actionChain.getContext(
120+
const effects = this.actionChain.getEffects(
121121
thisExecution,
122122
executionContextWithPath
123123
)
@@ -128,7 +128,7 @@ export class ActionBase<Context, InitialValue, Value = InitialValue> {
128128
path,
129129
...thisExecution,
130130
})
131-
const result = cb(context, currentValue)
131+
const result = cb(effects, currentValue)
132132

133133
if (result instanceof Promise) {
134134
this.actionChain.emit('operator:async', {

packages/node_modules/action-chain/src/ActionChain.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ function isObject(value) {
6161
return typeof value === 'object' && !Array.isArray(value) && value !== null
6262
}
6363

64-
export class ActionChain<Context> extends EventEmitter<ActionChainEvents> {
64+
export class ActionChain<Effects> extends EventEmitter<ActionChainEvents> {
6565
constructor(
66-
private context: Context,
66+
private effects: Effects,
6767
private options: ActionChainOptions = {}
6868
) {
6969
super()
@@ -107,26 +107,26 @@ export class ActionChain<Context> extends EventEmitter<ActionChainEvents> {
107107
}
108108
}
109109

110-
getContext(thisExecution: Execution, executionContext: ExecutionContext) {
111-
let context = this.context
110+
getEffects(thisExecution: Execution, executionContext: ExecutionContext) {
111+
let effects = this.effects
112112

113113
if (IS_DEVELOPMENT) {
114-
context = Object.keys(this.context).reduce((currentContext, key) => {
114+
effects = Object.keys(this.effects).reduce((currentEffects, key) => {
115115
if (
116116
this.options.providerExceptions.indexOf(key) === -1 &&
117-
isObject(this.context[key])
117+
isObject(this.effects[key])
118118
) {
119-
currentContext[key] = new Proxy(this.context[key], {
119+
currentEffects[key] = new Proxy(this.effects[key], {
120120
get: this.createGetHandler(thisExecution, key),
121121
})
122122
} else {
123-
currentContext[key] = this.context[key]
123+
currentEffects[key] = this.effects[key]
124124
}
125125

126-
return currentContext
127-
}, {}) as Context
126+
return currentEffects
127+
}, {}) as Effects
128128
}
129129

130-
return Object.assign({}, context, executionContext)
130+
return Object.assign({}, effects, executionContext)
131131
}
132132
}

packages/node_modules/action-chain/src/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe('CONTEXT', () => {
127127
})
128128

129129
describe('PROVIDER', () => {
130-
test('should track execution of providers', () => {
130+
test('should track execution of effects', () => {
131131
expect.assertions(2)
132132
const fn = action().test(({ foo }) => {
133133
expect(foo.bar()).toBe('baz')
@@ -146,7 +146,7 @@ describe('PROVIDER', () => {
146146
})
147147
fn()
148148
})
149-
test('should track execution of namespaced providers', () => {
149+
test('should track execution of namespaced effects', () => {
150150
expect.assertions(2)
151151
const fn = action().test(({ foo }) => {
152152
expect(foo.nestedProvider.bar()).toBe('baz')
@@ -165,7 +165,7 @@ describe('PROVIDER', () => {
165165
})
166166
fn()
167167
})
168-
test('should track execution of class instance providers', () => {
168+
test('should track execution of class instance effects', () => {
169169
expect.assertions(2)
170170
const fn = action().test(({ test }) => {
171171
expect(test.foo()).toBe('bar')

packages/node_modules/overmind-devtools/src/app/providers.ts renamed to packages/node_modules/overmind-devtools/src/app/effects.ts

File renamed without changes.

packages/node_modules/overmind-devtools/src/app/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import App, { TConnect, TContext, IAction } from 'overmind/react'
2-
import * as providers from './providers'
1+
import App, { TConnect, TEffects, TAction } from 'overmind/react'
2+
import * as effects from './effects'
33
import actions from './actions'
44
import state from './state'
55

6-
export type Context = TContext<typeof state, typeof providers>
6+
export type Context = TEffects<typeof state, typeof effects>
77

8-
export type Action = IAction<typeof state, Context>
8+
export type Action = TAction<typeof state, Context>
99

1010
const app = new App({
1111
state,
1212
actions,
13-
providers,
13+
effects,
1414
})
1515

1616
export type Connect = TConnect<typeof app.state, typeof app.actions>

0 commit comments

Comments
 (0)