Skip to content

Commit 6a3cf80

Browse files
feat(overmind): refactor typing to use I prefix
BREAKING CHANGE: TStateObject is now IState
1 parent 815b394 commit 6a3cf80

File tree

10 files changed

+237
-199
lines changed

10 files changed

+237
-199
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TApp, Configuration, EventType, Overmind } from 'overmind'
1+
import { IConfiguration, IContext, EventType, Overmind } from 'overmind'
22
import {
33
// @ts-ignore
44
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
@@ -32,30 +32,30 @@ type Omit<T, K extends keyof T> = Pick<
3232
{ [P in K]: never } & { [x: string]: never; [x: number]: never })[keyof T]
3333
>
3434

35-
export interface IConnect<Config extends Configuration> {
35+
export interface IConnect<Config extends IConfiguration> {
3636
overmind: {
37-
state: TApp<Config>['state']
38-
actions: TApp<Config>['actions']
39-
effects: TApp<Config>['effects']
37+
state: IContext<Config, any>['state']
38+
actions: IContext<Config, any>['actions']
39+
effects: IContext<Config, any>['effects']
4040
addMutationListener: (cb: (mutation: IMutation) => void) => () => void
4141
}
4242
}
4343

44-
const context = createContext<Overmind<Configuration>>({} as Overmind<
45-
Configuration
44+
const context = createContext<Overmind<IConfiguration>>({} as Overmind<
45+
IConfiguration
4646
>)
4747
let nextComponentId = 0
4848

4949
export const Provider: React.ProviderExoticComponent<
50-
React.ProviderProps<Overmind<Configuration>>
50+
React.ProviderProps<Overmind<IConfiguration>>
5151
> = context.Provider
5252

53-
export const createHook = <Config extends Configuration>(
53+
export const createHook = <Config extends IConfiguration>(
5454
overmindInstance?: Overmind<Config>
5555
): (() => {
56-
state: TApp<Config>['state']
57-
actions: TApp<Config>['actions']
58-
effects: TApp<Config>['effects']
56+
state: IContext<Config, any>['state']
57+
actions: IContext<Config, any>['actions']
58+
effects: IContext<Config, any>['effects']
5959
addMutationListener: (cb: (mutation: IMutation) => void) => () => void
6060
}) => {
6161
let currentComponentInstanceId = 0
@@ -149,7 +149,7 @@ export const createHook = <Config extends Configuration>(
149149
}
150150
}
151151

152-
export const createConnect = <A extends Overmind<Configuration>>(
152+
export const createConnect = <A extends Overmind<IConfiguration>>(
153153
overmind: A
154154
) => {
155155
return <Props>(

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

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

33
type SubType<Base, Condition> = Pick<
44
Base,
@@ -9,35 +9,35 @@ type SubType<Base, Condition> = Pick<
99
MERGE
1010
*/
1111

12-
export function merge<A extends Configuration, B extends Configuration>(
12+
export function merge<A extends IConfiguration, B extends IConfiguration>(
1313
configA: A,
1414
configB: B
1515
): A & B
1616
export function merge<
17-
A extends Configuration,
18-
B extends Configuration,
19-
C extends Configuration
17+
A extends IConfiguration,
18+
B extends IConfiguration,
19+
C extends IConfiguration
2020
>(configA: A, configB: B, configC: C): A & B & C
2121
export function merge<
22-
A extends Configuration,
23-
B extends Configuration,
24-
C extends Configuration,
25-
D extends Configuration
22+
A extends IConfiguration,
23+
B extends IConfiguration,
24+
C extends IConfiguration,
25+
D extends IConfiguration
2626
>(configA: A, configB: B, configC: C, configD: D): A & B & C & D
2727
export function merge<
28-
A extends Configuration,
29-
B extends Configuration,
30-
C extends Configuration,
31-
D extends Configuration,
32-
E extends Configuration
28+
A extends IConfiguration,
29+
B extends IConfiguration,
30+
C extends IConfiguration,
31+
D extends IConfiguration,
32+
E extends IConfiguration
3333
>(configA: A, configB: B, configC: C, configD: D, configE: E): A & B & C & D & E
3434
export function merge<
35-
A extends Configuration,
36-
B extends Configuration,
37-
C extends Configuration,
38-
D extends Configuration,
39-
E extends Configuration,
40-
F extends Configuration
35+
A extends IConfiguration,
36+
B extends IConfiguration,
37+
C extends IConfiguration,
38+
D extends IConfiguration,
39+
E extends IConfiguration,
40+
F extends IConfiguration
4141
>(
4242
configA: A,
4343
configB: B,
@@ -47,13 +47,13 @@ export function merge<
4747
configF: F
4848
): A & B & C & D & E & F
4949
export function merge<
50-
A extends Configuration,
51-
B extends Configuration,
52-
C extends Configuration,
53-
D extends Configuration,
54-
E extends Configuration,
55-
F extends Configuration,
56-
G extends Configuration
50+
A extends IConfiguration,
51+
B extends IConfiguration,
52+
C extends IConfiguration,
53+
D extends IConfiguration,
54+
E extends IConfiguration,
55+
F extends IConfiguration,
56+
G extends IConfiguration
5757
>(
5858
configA: A,
5959
configB: B,
@@ -64,14 +64,14 @@ export function merge<
6464
configG: G
6565
): A & B & C & D & E & F & G
6666
export function merge<
67-
A extends Configuration,
68-
B extends Configuration,
69-
C extends Configuration,
70-
D extends Configuration,
71-
E extends Configuration,
72-
F extends Configuration,
73-
G extends Configuration,
74-
H extends Configuration
67+
A extends IConfiguration,
68+
B extends IConfiguration,
69+
C extends IConfiguration,
70+
D extends IConfiguration,
71+
E extends IConfiguration,
72+
F extends IConfiguration,
73+
G extends IConfiguration,
74+
H extends IConfiguration
7575
>(
7676
configA: A,
7777
configB: B,
@@ -83,15 +83,15 @@ export function merge<
8383
configH: H
8484
): A & B & C & D & E & F & G & H
8585
export function merge<
86-
A extends Configuration,
87-
B extends Configuration,
88-
C extends Configuration,
89-
D extends Configuration,
90-
E extends Configuration,
91-
F extends Configuration,
92-
G extends Configuration,
93-
H extends Configuration,
94-
I extends Configuration
86+
A extends IConfiguration,
87+
B extends IConfiguration,
88+
C extends IConfiguration,
89+
D extends IConfiguration,
90+
E extends IConfiguration,
91+
F extends IConfiguration,
92+
G extends IConfiguration,
93+
H extends IConfiguration,
94+
I extends IConfiguration
9595
>(
9696
configA: A,
9797
configB: B,
@@ -103,7 +103,7 @@ export function merge<
103103
configH: H,
104104
configI: I
105105
): A & B & C & D & E & F & G & H & I
106-
export function merge(...configurations: Configuration[]): Configuration {
106+
export function merge(...configurations: IConfiguration[]): IConfiguration {
107107
const initializers = configurations.reduce(
108108
(aggr, config) =>
109109
config.onInitialize ? aggr.concat(config.onInitialize) : aggr,
@@ -156,9 +156,9 @@ interface NamespacedConfiguration {
156156
function parseNamespacedConfig(
157157
result: { actions: any; effects: any; state: any; initializers: any[] },
158158
name: string,
159-
config: Configuration
159+
config: IConfiguration
160160
) {
161-
const { actions, effects, onInitialize, state }: Configuration = config
161+
const { actions, effects, onInitialize, state }: IConfiguration = config
162162

163163
if (actions) {
164164
result.actions[name] = actions
@@ -289,11 +289,14 @@ export function lazy<T extends LazyConfiguration, B = T>(
289289
if (newConfig.actions && newConfig.actions[key])
290290
app.actions[key] = app.getActions(newConfig.actions[key])
291291
if (newConfig.onInitialize)
292-
newConfig.onInitialize({
293-
value: app,
294-
state,
295-
...rest,
296-
})
292+
newConfig.onInitialize(
293+
{
294+
value: app,
295+
state,
296+
...rest,
297+
},
298+
app
299+
)
297300
})
298301
},
299302
},

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, IAction, IDerive, TStateObject } from './'
1+
import { Overmind, IAction, IDerive, IState } from './'
22

33
type State = {
44
foo: string
@@ -21,7 +21,7 @@ describe('Derived', () => {
2121

2222
type Config = typeof config
2323

24-
interface Derive<Parent extends TStateObject, Value>
24+
interface Derive<Parent extends IState, Value>
2525
extends IDerive<Config, Parent, Value> {}
2626

2727
const app = new Overmind(config)
@@ -55,7 +55,7 @@ describe('Derived', () => {
5555
actions: typeof config.actions
5656
}
5757
interface Action<Input = void> extends IAction<Config, Input> {}
58-
interface Derive<Parent extends TStateObject, Value>
58+
interface Derive<Parent extends IState, Value>
5959
extends IDerive<Config, Parent, Value> {}
6060

6161
const app = new Overmind(config)
@@ -96,7 +96,7 @@ describe('Derived', () => {
9696
}
9797
type Config = typeof config
9898
interface Action<Input = void> extends IAction<Config, Input> {}
99-
interface Derive<Parent extends TStateObject, Value>
99+
interface Derive<Parent extends IState, Value>
100100
extends IDerive<Config, Parent, Value> {}
101101

102102
const app = new Overmind(config)
@@ -124,7 +124,7 @@ describe('Derived', () => {
124124
}
125125
type Config = typeof config
126126
interface Action<Input = void> extends IAction<Config, Input> {}
127-
interface Derive<Parent extends TStateObject, Value>
127+
interface Derive<Parent extends IState, Value>
128128
extends IDerive<Config, Parent, Value> {}
129129

130130
const app = new Overmind(config)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function createDefaultOvermind() {
2727
await Promise.resolve()
2828
context.state.foo = 'bar2'
2929
}
30-
const changeValue: Action<{ isAwesome: boolean }> = (context, value) => {
30+
const changeValue: Action<{ isAwesome: boolean }> = (_, value) => {
3131
value.isAwesome = !value.isAwesome
3232
}
3333
const changeFormValue: Action<{

0 commit comments

Comments
 (0)