Skip to content

Commit 9a377d0

Browse files
refactor(overmind): use TConfig instead of TApp
1 parent 029f931 commit 9a377d0

File tree

7 files changed

+67
-64
lines changed

7 files changed

+67
-64
lines changed

packages/demos/react-typescript-todomvc/src/app/actions.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react'
2-
32
import { Action } from './'
43
import * as mutations from './mutations'
54
import * as operations from './operations'
Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import App, {
22
TAction,
3-
TApp,
3+
TConfig,
44
TContext,
55
TDerive,
66
TMutate,
@@ -12,7 +12,7 @@ import * as actions from './actions'
1212
import * as context from './context'
1313
import * as state from './state'
1414

15-
const config = {
15+
export const config = {
1616
context,
1717
actions,
1818
state,
@@ -24,32 +24,36 @@ export type Connect = TConnect<typeof app>
2424

2525
export const connect = createConnect(app)
2626

27-
type IApp = TApp<typeof config>
27+
/*
28+
OVERMIND TYPES
29+
*/
2830

29-
export default app
30-
31-
// ==== The following types are copied from overmind documentation ====
31+
type Config = TConfig<typeof config>
3232

3333
export type Action<Value = void, ReturnValue = Value> = TAction<
34-
IApp,
34+
Config,
3535
Value,
3636
ReturnValue
3737
>
3838

39-
export type Mutate<Value = any> = TMutate<IApp, Value>
39+
export type Mutate<Value = any> = TMutate<Config, Value>
4040

41-
export type Context<Value> = TContext<IApp, Value>
41+
export type Context<Value> = TContext<Config, Value>
4242

43-
// Operations
4443
export type Map<Value, ReturnValue = Value> = (
4544
ctx: Context<Value>
4645
) => ReturnValue
46+
4747
export type Filter<Value = any> = (ctx: Context<Value>) => boolean
48+
4849
export type When<Value = any> = (ctx: Context<Value>) => boolean
50+
4951
export type Run<Value = any> = (ctx: Context<Value>) => void
52+
5053
export type Fork<Value = any> = (ctx: Context<Value>) => string
54+
5155
export type Attempt<Value, ReturnValue> = (ctx: Context<Value>) => ReturnValue
5256

53-
export type Derive<Value> = TDerive<IApp, Value>
57+
export type Derive<Value> = TDerive<Config, Value>
5458

55-
export type Reaction = TReaction<IApp>
59+
export type Reaction = TReaction<Config>

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import App, { TAction, TApp, TDerive } from './'
1+
import App, { TAction, TConfig, TDerive } from './'
22

33
type State = {
44
foo: string
@@ -16,11 +16,11 @@ describe('Derived', () => {
1616
state,
1717
}
1818

19-
type IApp = TApp<{
19+
type Config = TConfig<{
2020
state: typeof state
2121
}>
2222

23-
type Derive<Value> = TDerive<IApp, Value>
23+
type Derive<Value> = TDerive<Config, Value>
2424

2525
const app = new App(config)
2626

@@ -43,15 +43,15 @@ describe('Derived', () => {
4343
changeFoo,
4444
},
4545
}
46-
type IApp = TApp<{
46+
type Config = TConfig<{
4747
state: {
4848
foo: string
4949
upperFoo: string
5050
}
5151
actions: typeof config.actions
5252
}>
53-
type Action<Input = void, Output = any> = TAction<IApp, Input, Output>
54-
type Derive<Value> = TDerive<IApp, Value>
53+
type Action<Input = void, Output = any> = TAction<Config, Input, Output>
54+
type Derive<Value> = TDerive<Config, Value>
5555

5656
const app = new App(config)
5757
function render() {
@@ -86,15 +86,15 @@ describe('Derived', () => {
8686
changeFoo,
8787
},
8888
}
89-
type IApp = TApp<{
89+
type Config = TConfig<{
9090
state: {
9191
foo: string
9292
upperFoo: string
9393
}
9494
actions: typeof config.actions
9595
}>
96-
type Action<Input = void, Output = any> = TAction<IApp, Input, Output>
97-
type Derive<Value> = TDerive<IApp, Value>
96+
type Action<Input = void, Output = any> = TAction<Config, Input, Output>
97+
type Derive<Value> = TDerive<Config, Value>
9898

9999
const app = new App(config)
100100
app.actions.changeFoo()

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

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import App, { Action, TAction, TApp, modules } from './'
1+
import App, { Action, TAction, TConfig, modules } from './'
22

33
describe('Overmind', () => {
44
test('should instantiate app with state', () => {
@@ -74,7 +74,7 @@ describe('Overmind', () => {
7474
},
7575
})
7676

77-
type App = TApp<{
77+
type Config = TConfig<{
7878
state: {
7979
foo: typeof config.state.foo
8080
bar: typeof config.state.bar
@@ -87,7 +87,7 @@ describe('Overmind', () => {
8787
bar: typeof config.actions.bar
8888
}
8989
}>
90-
type Action<Input = void, Output = any> = TAction<App, Input, Output>
90+
type Action<Input = void, Output = any> = TAction<Config, Input, Output>
9191

9292
const app = new App(config)
9393

@@ -135,10 +135,10 @@ describe('OPERATORS', () => {
135135
doThis,
136136
},
137137
}
138-
type IApp = TApp<{
138+
type Config = TConfig<{
139139
actions: typeof config.actions
140140
}>
141-
type Action<Input = void, Output = any> = TAction<IApp, Input, Output>
141+
type Action<Input = void, Output = any> = TAction<Config, Input, Output>
142142

143143
const app = new App(config)
144144

@@ -156,13 +156,13 @@ describe('OPERATORS', () => {
156156
doThis,
157157
},
158158
}
159-
type IApp = TApp<{
159+
type Config = TConfig<{
160160
state: {
161161
foo: string
162162
}
163163
actions: typeof config.actions
164164
}>
165-
type Action<Input = void, Output = any> = TAction<IApp, Input, Output>
165+
type Action<Input = void, Output = any> = TAction<Config, Input, Output>
166166

167167
const app = new App(config)
168168

@@ -190,7 +190,7 @@ describe('OPERATORS', () => {
190190
doThis,
191191
},
192192
}
193-
type IApp = TApp<{
193+
type Config = TConfig<{
194194
state: {
195195
foo: string
196196
}
@@ -199,7 +199,7 @@ describe('OPERATORS', () => {
199199
}
200200
actions: typeof config.actions
201201
}>
202-
type Action<Input = void, Output = any> = TAction<IApp, Input, Output>
202+
type Action<Input = void, Output = any> = TAction<Config, Input, Output>
203203

204204
const app = new App(config)
205205
return app.actions
@@ -217,10 +217,10 @@ describe('OPERATORS', () => {
217217
doThis,
218218
},
219219
}
220-
type IApp = TApp<{
220+
type Config = TConfig<{
221221
actions: typeof config.actions
222222
}>
223-
type Action<Input = void, Output = any> = TAction<IApp, Input, Output>
223+
type Action<Input = void, Output = any> = TAction<Config, Input, Output>
224224

225225
const app = new App(config)
226226

@@ -239,10 +239,10 @@ describe('OPERATORS', () => {
239239
doThis,
240240
},
241241
}
242-
type IApp = TApp<{
242+
type Config = TConfig<{
243243
actions: typeof config.actions
244244
}>
245-
type Action<Input = void, Output = any> = TAction<IApp, Input, Output>
245+
type Action<Input = void, Output = any> = TAction<Config, Input, Output>
246246
const app = new App(config)
247247

248248
return Promise.resolve(app.actions.doThis()).then((value) => {
@@ -262,10 +262,10 @@ describe('OPERATORS', () => {
262262
doThis,
263263
},
264264
}
265-
type IApp = TApp<{
265+
type Config = TConfig<{
266266
actions: typeof config.actions
267267
}>
268-
type Action<Input = void, Output = any> = TAction<IApp, Input, Output>
268+
type Action<Input = void, Output = any> = TAction<Config, Input, Output>
269269
const app = new App(config)
270270
return Promise.resolve(app.actions.doThis()).then((value) => {
271271
expect(value).toBe('bar')
@@ -283,10 +283,10 @@ describe('OPERATORS', () => {
283283
doThis,
284284
},
285285
}
286-
type IApp = TApp<{
286+
type Config = TConfig<{
287287
actions: typeof config.actions
288288
}>
289-
type Action<Input = void, Output = any> = TAction<IApp, Input, Output>
289+
type Action<Input = void, Output = any> = TAction<Config, Input, Output>
290290
const app = new App(config)
291291
expect(app.actions.doThis()).toBe('foo')
292292
})
@@ -303,10 +303,10 @@ describe('OPERATORS', () => {
303303
doThis,
304304
},
305305
}
306-
type IApp = TApp<{
306+
type Config = TConfig<{
307307
actions: typeof config.actions
308308
}>
309-
type Action<Input = void, Output = any> = TAction<IApp, Input, Output>
309+
type Action<Input = void, Output = any> = TAction<Config, Input, Output>
310310
const app = new App(config)
311311

312312
expect(app.actions.doThis()).toBe('bar')
@@ -321,10 +321,10 @@ describe('OPERATORS', () => {
321321
doThis,
322322
},
323323
}
324-
type IApp = TApp<{
324+
type Config = TConfig<{
325325
actions: typeof config.actions
326326
}>
327-
type Action<Input = void, Output = any> = TAction<IApp, Input, Output>
327+
type Action<Input = void, Output = any> = TAction<Config, Input, Output>
328328
const app = new App(config)
329329
expect(app.actions.doThis('foo')).toBe('bar')
330330
})
@@ -337,10 +337,10 @@ describe('OPERATORS', () => {
337337
doThis,
338338
},
339339
}
340-
type IApp = TApp<{
340+
type Config = TConfig<{
341341
actions: typeof config.actions
342342
}>
343-
type Action<Input = void, Output = any> = TAction<IApp, Input, Output>
343+
type Action<Input = void, Output = any> = TAction<Config, Input, Output>
344344
const app = new App(config)
345345

346346
expect(app.actions.doThis('foo')).toEqual({ value: 'foo' })
@@ -360,10 +360,10 @@ describe('OPERATORS', () => {
360360
doThis,
361361
},
362362
}
363-
type IApp = TApp<{
363+
type Config = TConfig<{
364364
actions: typeof config.actions
365365
}>
366-
type Action<Input = void, Output = any> = TAction<IApp, Input, Output>
366+
type Action<Input = void, Output = any> = TAction<Config, Input, Output>
367367
const app = new App(config)
368368

369369
return Promise.resolve(app.actions.doThis()).then((value) => {
@@ -383,10 +383,10 @@ describe('OPERATORS', () => {
383383
doThis,
384384
},
385385
}
386-
type IApp = TApp<{
386+
type Config = TConfig<{
387387
actions: typeof config.actions
388388
}>
389-
type Action<Input = void, Output = any> = TAction<IApp, Input, Output>
389+
type Action<Input = void, Output = any> = TAction<Config, Input, Output>
390390
const app = new App(config)
391391
app.actions.doThis()
392392
expect(mockCallback.mock.calls.length).toBe(1)
@@ -403,10 +403,10 @@ describe('OPERATORS', () => {
403403
doThis,
404404
},
405405
}
406-
type IApp = TApp<{
406+
type Config = TConfig<{
407407
actions: typeof config.actions
408408
}>
409-
type Action<Input = void, Output = any> = TAction<IApp, Input, Output>
409+
type Action<Input = void, Output = any> = TAction<Config, Input, Output>
410410
const app = new App(config)
411411
app.actions.doThis()
412412
expect(mockCallback.mock.calls.length).toBe(1)

packages/node_modules/overmind/src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Derived from './derived'
77
import Devtools, { Message, safeValue } from './Devtools'
88
import { EventType, Events, Options } from './internalTypes'
99
import Reaction from './reaction'
10-
import { BaseApp, Configuration, TApp } from './types'
10+
import { BaseApp, Configuration, TConfig } from './types'
1111

1212
export * from './types'
1313

@@ -25,10 +25,10 @@ export default class App<Config extends Configuration> implements BaseApp {
2525
initialized: Promise<any>
2626
eventHub: EventEmitter<Events>
2727
devtools: Devtools
28-
actions: TApp<Config>['actions']
29-
state: TApp<Config>['state']
28+
actions: TConfig<Config>['actions']
29+
state: TConfig<Config>['state']
3030
// We add the context here so that App implements BaseApp (makes types simpler).
31-
context: TApp<Config>['context'] & { state: TApp<Config>['state'] }
31+
context: TConfig<Config>['context'] & { state: TConfig<Config>['state'] }
3232
constructor(configuration: Config, options: Options = {}) {
3333
const name = options.name || 'MyApp'
3434

@@ -313,7 +313,7 @@ export default class App<Config extends Configuration> implements BaseApp {
313313
return {
314314
add(
315315
name: string,
316-
stateCb: (state: TApp<Config>['state']) => any,
316+
stateCb: (state: TConfig<Config>['state']) => any,
317317
cb: Function
318318
) {
319319
const reaction = new Reaction(

0 commit comments

Comments
 (0)