Skip to content

Commit 17b0fee

Browse files
Merge pull request cerebral#66 from cerebral/augmentModule
feat(overmind): declare module typing
2 parents a82bd71 + d339602 commit 17b0fee

39 files changed

+354
-278
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react'
2-
import { Action } from '../app'
2+
import { Action } from 'overmind'
33
import { Todo } from './state'
44
import * as operations from './operations'
55
import * as mutations from './mutations'
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
import { Compute } from '../app'
1+
import { Compute } from 'overmind'
22

3-
export const testCount: Compute<number> = (foo) => (state) => state.count + foo
3+
export const testCount: Compute<number, number> = (foo) => (state) =>
4+
state.count + foo
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import { Derive } from '../app'
1+
import { Derive } from 'overmind'
22

3-
export const count: Derive = (state) => state.todos.length
3+
export const count: Derive<number> = (state) => state.todos.length

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import App, {
2-
TConfig,
3-
TConnect,
4-
TAction,
5-
TOperation,
6-
TDerive,
7-
TCompute,
8-
} from 'react-overmind'
1+
import App, { TConnect } from 'react-overmind'
92
import * as effects from './effects'
103
import * as actions from './actions'
114
import * as state from './state'
@@ -16,18 +9,10 @@ const config = {
169
state,
1710
}
1811

19-
type Config = TConfig<typeof config>
20-
21-
export type Action<Input = void, Output = any> = TAction<Input, Output, Config>
22-
export type Derive = TDerive<Config>
23-
export type Compute<Input> = TCompute<Input, Config>
24-
export type Mutation<Input = any> = TOperation.Mutation<Input, Config>
25-
export type Do<Input = any> = TOperation.Do<Input, Config>
26-
export type Filter<Input = any> = TOperation.Filter<Input, Config>
27-
export type When<Input = any> = TOperation.When<Input, Config>
28-
export type Fork<Input = any> = TOperation.Fork<Input, Config>
29-
export type Map<Input, Output> = TOperation.Map<Input, Output, Config>
30-
export type Try<Input, Output> = TOperation.Try<Input, Output, Config>
12+
declare module 'overmind' {
13+
interface IState extends TState<typeof config> {}
14+
interface IEffects extends TEffects<typeof config> {}
15+
}
3116

3217
const app = new App(config, {
3318
devtools: 'localhost:1234',

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Mutation } from '../app'
1+
import { Mutation } from 'overmind'
22
import { Todo } from './state'
33

44
let nextTodoId = 0
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Map, Do } from '../app'
1+
import { Operation } from 'overmind'
22

33
type ChangeEvent = React.ChangeEvent<HTMLInputElement>
44

5-
export const getEventValue: Map<ChangeEvent, string> = (_, event) =>
5+
export const getEventValue: Operation.Map<ChangeEvent, string> = (_, event) =>
66
event.currentTarget.value
77

8-
export const preventEventDefault: Do<React.FormEvent> = (_, event) =>
8+
export const preventEventDefault: Operation.Do<React.FormEvent> = (_, event) =>
99
event.preventDefault()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Action } from '../app'
1+
import { Action } from 'overmind'
22
import * as mutations from './mutations'
33
import * as operations from './operations'
44
import { Message, Tab } from './state'
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import { Component } from './state'
2-
import { Derive } from '../app'
1+
import { Derive } from 'overmind'
2+
import { Component, App, Flush, Action } from './state'
33

4-
export const currentApp: Derive = (state) => state.apps[state.currentPort]
4+
export const currentApp: Derive<App> = (state) => state.apps[state.currentPort]
55

6-
export const componentsMounted: Derive = (state) =>
6+
export const componentsMounted: Derive<Component[]> = (state) =>
77
Object.keys(state.currentApp.components).reduce(
88
(aggr, key) => {
99
if (state.currentApp.components[key].isMounted) {
@@ -15,19 +15,19 @@ export const componentsMounted: Derive = (state) =>
1515
[] as Component[]
1616
)
1717

18-
export const componentsUpdateCount: Derive = (state) =>
18+
export const componentsUpdateCount: Derive<number> = (state) =>
1919
state.componentsMounted.reduce(
2020
(aggr, component) => aggr + component.updateCount,
2121
0
2222
)
2323

24-
export const componentsStatePathCount: Derive = (state) =>
24+
export const componentsStatePathCount: Derive<number> = (state) =>
2525
state.componentsMounted.reduce(
2626
(aggr, component) => aggr + component.paths.length,
2727
0
2828
)
2929

30-
export const flushes: Derive = (state) =>
30+
export const flushes: Derive<Flush[]> = (state) =>
3131
Object.keys(state.currentApp.flushes)
3232
.sort(
3333
(idA, idB) =>
@@ -36,10 +36,10 @@ export const flushes: Derive = (state) =>
3636
)
3737
.map((id) => state.currentApp.flushes[id])
3838

39-
export const flushesMutationsCount: Derive = (state) =>
39+
export const flushesMutationsCount: Derive<number> = (state) =>
4040
state.flushes.reduce((aggr, flush) => aggr + flush.mutations.length, 0)
4141

42-
export const flushesStatePathCount: Derive = (state) =>
42+
export const flushesStatePathCount: Derive<number> = (state) =>
4343
state.flushes.reduce((aggr, flush) => {
4444
return flush.mutations.reduce(
4545
(aggr, mutation) =>
@@ -48,5 +48,5 @@ export const flushesStatePathCount: Derive = (state) =>
4848
)
4949
}, []).length
5050

51-
export const currentAction: Derive = (state) =>
51+
export const currentAction: Derive<Action> = (state) =>
5252
state.currentApp.actions[state.currentApp.currentActionId]

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

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,18 @@
1-
import App, {
2-
TConfig,
3-
TDerive,
4-
TOperation,
5-
TConnect,
6-
TAction,
7-
} from 'react-overmind'
1+
import App, { TConnect } from 'react-overmind'
82
import * as effects from './effects'
93
import * as actions from './actions'
10-
import state from './state'
4+
import * as state from './state'
115

126
const config = {
137
effects,
148
actions,
159
state,
1610
}
1711

18-
type Config = TConfig<typeof config>
19-
20-
export type Action<Input = void, Output = any> = TAction<Input, Output, Config>
21-
export type Derive = TDerive<Config>
22-
export type Mutation<Input = any> = TOperation.Mutation<Input, Config>
23-
export type Do<Input = any> = TOperation.Do<Input, Config>
24-
export type Filter<Input = any> = TOperation.Filter<Input, Config>
25-
export type When<Input = any> = TOperation.When<Input, Config>
26-
export type Fork<Input = any> = TOperation.Fork<Input, Config>
27-
export type Map<Input, Output> = TOperation.Map<Input, Output, Config>
28-
export type Try<Input, Output> = TOperation.Try<Input, Output, Config>
12+
declare module 'overmind' {
13+
interface IState extends TState<typeof config> {}
14+
interface IEffects extends TEffects<typeof config> {}
15+
}
2916

3017
const app = new App(config)
3118

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Mutation } from '../app'
1+
import { Mutation } from 'overmind'
22
import {
33
Apps,
44
Message,

0 commit comments

Comments
 (0)