Skip to content

Commit 4291cff

Browse files
feat(overmind): refactor to interface based typing and expose actions to actions and effects to comp
BREAKING CHANGE: use interfaces instead of types
1 parent 5986e0a commit 4291cff

File tree

41 files changed

+209
-243
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+209
-243
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { EventType, Overmind, TApp, Configuration } from 'overmind'
44
import { NgZone } from '@angular/core'
55
import { IMutation } from 'proxy-state-tree'
66

7-
export type TConnect<Config extends Configuration> = {
7+
export interface IConnect<Config extends Configuration> {
88
state: TApp<Config>['state']
99
actions: TApp<Config>['actions']
10+
effects: TApp<Config>['effects']
1011
addMutationListener: (cb: (mutation: IMutation) => void) => () => void
1112
}
1213

@@ -31,6 +32,7 @@ export const createConnect = <A extends Overmind<any>>(overmind: A) => () => {
3132
this.overmind = {
3233
state: this.__tree.state,
3334
actions: overmind.actions,
35+
effects: overmind.effects,
3436
addMutationListener: overmind.addMutationListener,
3537
}
3638
this.__shouldUpdatePaths = false

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Overmind, TConfig } from 'overmind'
1+
import { Overmind, IConfig } from 'overmind'
22
import { createHook } from 'overmind-react'
33

44
import * as actions from './actions'
@@ -13,7 +13,7 @@ const config = {
1313
}
1414

1515
declare module 'overmind' {
16-
interface IConfig extends TConfig<typeof config> {}
16+
interface Config extends IConfig<typeof config> {}
1717
}
1818

1919
export const overmind = new Overmind(config, {

packages/node_modules/overmind-devtools/src/overmind/operators.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,6 @@ export const forkEachMessage: (
326326
) => Operator<AppMessage<any>[]> = (paths) =>
327327
forEach(fork(({ value }) => value.type, paths) as Operator<AppMessage<any>>)
328328

329-
export const updateOperatorAsync = action<AsyncOperatorMessage>(() => {})
329+
export const updateOperatorAsync: Operator<AsyncOperatorMessage> = action(
330+
() => {}
331+
)

packages/node_modules/overmind-react/src/index.test.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Overmind, TAction } from 'overmind'
1+
import { Overmind, IAction } from 'overmind'
22
import * as React from 'react'
33
import * as renderer from 'react-test-renderer'
4-
import { TConnect, createConnect } from './'
4+
import { IConnect, createConnect } from './'
55

66
describe('React', () => {
77
test('should connect state and actions to stateless components', () => {
@@ -29,11 +29,11 @@ describe('React', () => {
2929

3030
const app = new Overmind(config)
3131

32-
type Action<Input = void> = TAction<IConfig, Input>
32+
interface Action<Input = void> extends IAction<IConfig, Input> {}
3333

3434
const connect = createConnect(app)
3535

36-
const Component: React.SFC<TConnect<IConfig>> = ({ overmind }) => {
36+
const Component: React.SFC<IConnect<IConfig>> = ({ overmind }) => {
3737
overmind.actions.doThis()
3838
return <h1>{overmind.state.foo}</h1>
3939
}
@@ -68,11 +68,11 @@ describe('React', () => {
6868

6969
const app = new Overmind(config)
7070

71-
type Action<Input = void> = TAction<IConfig, Input>
71+
interface Action<Input = void> extends IAction<IConfig, Input> {}
7272

7373
const connect = createConnect(app)
7474

75-
class Component extends React.Component<TConnect<IConfig>> {
75+
class Component extends React.Component<IConnect<IConfig>> {
7676
componentDidMount() {
7777
this.props.overmind.actions.doThis()
7878
}
@@ -101,7 +101,7 @@ describe('React', () => {
101101

102102
const connect = createConnect(app)
103103

104-
class Component extends React.Component<TConnect<typeof config>> {
104+
class Component extends React.Component<IConnect<typeof config>> {
105105
render() {
106106
const { overmind } = this.props
107107

@@ -120,7 +120,7 @@ describe('React', () => {
120120
const app = new Overmind({})
121121
const connect = createConnect(app)
122122

123-
class FooComponent extends React.Component<TConnect<{}>> {
123+
class FooComponent extends React.Component<IConnect<{}>> {
124124
render() {
125125
return <h1>hop</h1>
126126
}
@@ -161,11 +161,11 @@ describe('React', () => {
161161

162162
const app = new Overmind(config)
163163

164-
type Action<Input = void> = TAction<IConfig, Input>
164+
interface Action<Input = void> extends IAction<IConfig, Input> {}
165165

166166
const connect = createConnect(app)
167167

168-
class FooComponent extends React.Component<TConnect<typeof config>> {
168+
class FooComponent extends React.Component<IConnect<typeof config>> {
169169
shouldComponentUpdate(nextProps) {
170170
return this.props.overmind !== nextProps.overmind
171171
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ type Omit<T, K extends keyof T> = Pick<
2929
{ [P in K]: never } & { [x: string]: never; [x: number]: never })[keyof T]
3030
>
3131

32-
export type TConnect<Config extends Configuration> = {
32+
export interface IConnect<Config extends Configuration> {
3333
overmind: {
3434
state: TApp<Config>['state']
3535
actions: TApp<Config>['actions']
36+
effects: TApp<Config>['effects']
3637
addMutationListener: (cb: (mutation: IMutation) => void) => () => void
3738
}
3839
}
@@ -44,6 +45,7 @@ export const createHook = <A extends Overmind<Configuration>>(
4445
): (() => {
4546
state: A['state']
4647
actions: A['actions']
48+
effects: A['effects']
4749
addMutationListener: (cb: (mutation: IMutation) => void) => () => void
4850
}) => {
4951
let currentComponentInstanceId = 0
@@ -128,6 +130,7 @@ export const createHook = <A extends Overmind<Configuration>>(
128130
return {
129131
state: tree.state,
130132
actions: overmind.actions,
133+
effects: overmind.effects,
131134
addMutationListener: overmind.addMutationListener,
132135
}
133136
}
@@ -140,7 +143,7 @@ export const createConnect = <A extends Overmind<Configuration>>(
140143
component: IReactComponent<
141144
Props & { overmind: { state: A['state']; actions: A['actions'] } }
142145
>
143-
): IReactComponent<Omit<Props & TConnect<A>, keyof TConnect<A>>> => {
146+
): IReactComponent<Omit<Props & IConnect<A>, keyof IConnect<A>>> => {
144147
let componentInstanceId = 0
145148
const name = component.name
146149
const populatedComponent = component as any
@@ -171,6 +174,7 @@ export const createConnect = <A extends Overmind<Configuration>>(
171174
this.state = {
172175
overmind: {
173176
state: this.tree.state,
177+
effects: overmind.effects,
174178
actions: overmind.actions,
175179
addMutationListener: overmind.addMutationListener,
176180
onUpdate: this.onUpdate,
@@ -185,6 +189,7 @@ export const createConnect = <A extends Overmind<Configuration>>(
185189
this.setState({
186190
overmind: {
187191
state: this.tree.state,
192+
effects: overmind.effects,
188193
actions: overmind.actions,
189194
addMutationListener: overmind.addMutationListener,
190195
onUpdate: this.onUpdate,
@@ -223,6 +228,7 @@ export const createConnect = <A extends Overmind<Configuration>>(
223228
this.state = {
224229
overmind: {
225230
state: this.tree.state,
231+
effects: overmind.effects,
226232
actions: overmind.actions,
227233
addMutationListener: overmind.addMutationListener,
228234
onUpdate: this.onUpdate,
@@ -260,6 +266,7 @@ export const createConnect = <A extends Overmind<Configuration>>(
260266
this.setState({
261267
overmind: {
262268
state: this.tree.state,
269+
effects: overmind.effects,
263270
actions: overmind.actions,
264271
addMutationListener: overmind.addMutationListener,
265272
onUpdate: this.onUpdate,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EventType, Overmind } from 'overmind'
1+
import { EventType } from 'overmind'
22

33
let nextComponentId = 0
44

@@ -19,6 +19,7 @@ export const createConnect = (overmind) => (options) => {
1919
this.overmind = {
2020
state: this.__tree.state,
2121
actions: overmind.actions,
22+
effects: overmind.effects,
2223
addMutationListener: overmind.addMutationListener,
2324
}
2425
this.__tree.track(this.__onUpdate)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Configuration, TAction } from '../'
1+
import { Configuration, IAction } from '../'
22

33
type SubType<Base, Condition> = Pick<
44
Base,
@@ -256,7 +256,7 @@ export function lazy<T extends LazyConfiguration, B = T>(
256256
object
257257
> & {
258258
lazy: {
259-
loadConfig: TAction<any, keyof T>
259+
loadConfig: IAction<any, keyof T>
260260
}
261261
}
262262
} {

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

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

33
type State = {
44
foo: string
@@ -19,15 +19,10 @@ describe('Derived', () => {
1919
state,
2020
}
2121

22-
type Config = {
23-
state: typeof state
24-
}
22+
type Config = typeof config
2523

26-
type Derive<Parent extends TStateObject, Value> = TDerive<
27-
Config,
28-
Parent,
29-
Value
30-
>
24+
interface Derive<Parent extends TStateObject, Value>
25+
extends IDerive<Config, Parent, Value> {}
3126

3227
const app = new Overmind(config)
3328

@@ -59,12 +54,9 @@ describe('Derived', () => {
5954
}
6055
actions: typeof config.actions
6156
}
62-
type Action<Input = void> = TAction<Config, Input>
63-
type Derive<Parent extends TStateObject, Value> = TDerive<
64-
Config,
65-
Parent,
66-
Value
67-
>
57+
interface Action<Input = void> extends IAction<Config, Input> {}
58+
interface Derive<Parent extends TStateObject, Value>
59+
extends IDerive<Config, Parent, Value> {}
6860

6961
const app = new Overmind(config)
7062
const trackStateTree = app.getTrackStateTree()
@@ -102,19 +94,10 @@ describe('Derived', () => {
10294
changeFoo,
10395
},
10496
}
105-
type Config = {
106-
state: {
107-
foo: string
108-
upperFoo: string
109-
}
110-
actions: typeof config.actions
111-
}
112-
type Action<Input = void> = TAction<Config, Input>
113-
type Derive<Parent extends TStateObject, Value> = TDerive<
114-
Config,
115-
Parent,
116-
Value
117-
>
97+
type Config = typeof config
98+
interface Action<Input = void> extends IAction<Config, Input> {}
99+
interface Derive<Parent extends TStateObject, Value>
100+
extends IDerive<Config, Parent, Value> {}
118101

119102
const app = new Overmind(config)
120103

@@ -139,19 +122,10 @@ describe('Derived', () => {
139122
changeFoo,
140123
},
141124
}
142-
type Config = {
143-
state: {
144-
foo: string
145-
upperFoo: string
146-
}
147-
actions: typeof config.actions
148-
}
149-
type Action<Input = void> = TAction<Config, Input>
150-
type Derive<Parent extends TStateObject, Value> = TDerive<
151-
Config,
152-
Parent,
153-
Value
154-
>
125+
type Config = typeof config
126+
interface Action<Input = void> extends IAction<Config, Input> {}
127+
interface Derive<Parent extends TStateObject, Value>
128+
extends IDerive<Config, Parent, Value> {}
155129

156130
const app = new Overmind(config)
157131

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { EventType, Overmind, TAction } from './'
1+
import { EventType, Overmind, IAction } from './'
22
import { namespaced } from './config'
33

44
function toJSON(obj) {
@@ -60,12 +60,9 @@ function createDefaultOvermind() {
6060
effects,
6161
}
6262

63-
type Config = {
64-
state: typeof state
65-
actions: typeof actions
66-
effects: typeof effects
67-
}
68-
type Action<Value = void> = TAction<Config, Value>
63+
type Config = typeof config
64+
65+
interface Action<Value = void> extends IAction<Config, Value> {}
6966

7067
const app = new Overmind(config)
7168

0 commit comments

Comments
 (0)