Skip to content

Commit 8e7ba90

Browse files
refactor(overmind): pass parent state as first type to Derive
1 parent d188d6a commit 8e7ba90

File tree

9 files changed

+24
-24
lines changed

9 files changed

+24
-24
lines changed

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, pipe, OnInitialize, Operator, map } from 'overmind'
1+
import { Action, pipe, OnInitialize, Operator } from 'overmind'
22
import {
33
Message,
44
Tab,

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ type State = {
2020
expandedStatePaths: string[]
2121
expandAllActionDetails: boolean
2222
expandedComponents: string[]
23-
currentAction: Derive<Action, State>
24-
currentApp: Derive<App, State>
25-
componentsMounted: Derive<Component[], State>
26-
componentsUpdateCount: Derive<number, State>
27-
componentsStatePathCount: Derive<number, State>
28-
flushes: Derive<Flush[], State>
29-
flushesMutationsCount: Derive<number, State>
30-
flushesStatePathCount: Derive<number, State>
31-
groupedComponents: Derive<GroupedComponents, State>
23+
currentAction: Derive<State, Action>
24+
currentApp: Derive<State, App>
25+
componentsMounted: Derive<State, Component[]>
26+
componentsUpdateCount: Derive<State, number>
27+
componentsStatePathCount: Derive<State, number>
28+
flushes: Derive<State, Flush[]>
29+
flushesMutationsCount: Derive<State, number>
30+
flushesStatePathCount: Derive<State, number>
31+
groupedComponents: Derive<State, GroupedComponents>
3232
}
3333

3434
const state: State = {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('Derived', () => {
99
test('should instantiate app with derived state', () => {
1010
type State = {
1111
foo: string
12-
upperFoo: Derive<string, State>
12+
upperFoo: Derive<State, string>
1313
}
1414
const state: State = {
1515
foo: 'bar',
@@ -23,7 +23,7 @@ describe('Derived', () => {
2323
state: typeof state
2424
}>
2525

26-
type Derive<Value, Parent extends object> = TDerive<IApp, Value, Parent>
26+
type Derive<Parent extends object, Value> = TDerive<IApp, Parent, Value>
2727

2828
const app = new Overmind(config)
2929

@@ -35,7 +35,7 @@ describe('Derived', () => {
3535
const changeFoo: Action = ({ state }) => (state.foo = 'bar2')
3636
type State = {
3737
foo: string
38-
upperFoo: Derive<string, State>
38+
upperFoo: Derive<State, string>
3939
}
4040
const state: State = {
4141
foo: 'bar',
@@ -56,7 +56,7 @@ describe('Derived', () => {
5656
actions: typeof config.actions
5757
}>
5858
type Action<Input = void> = TAction<IApp, Input>
59-
type Derive<Value, Parent extends object> = TDerive<IApp, Value, Parent>
59+
type Derive<Parent extends object, Value> = TDerive<IApp, Parent, Value>
6060

6161
const app = new Overmind(config)
6262
function render() {
@@ -75,7 +75,7 @@ describe('Derived', () => {
7575
expect.assertions(1)
7676
type State = {
7777
foo: string
78-
upperFoo: Derive<string, State>
78+
upperFoo: Derive<State, string>
7979
}
8080
const state: State = {
8181
foo: 'bar',
@@ -100,7 +100,7 @@ describe('Derived', () => {
100100
actions: typeof config.actions
101101
}>
102102
type Action<Input = void> = TAction<IApp, Input>
103-
type Derive<Value, Parent extends object> = TDerive<IApp, Value, Parent>
103+
type Derive<Parent extends object, Value> = TDerive<IApp, Parent, Value>
104104

105105
const app = new Overmind(config)
106106

@@ -113,7 +113,7 @@ describe('Derived', () => {
113113
expect(state.upperFoo).toBe('BAR2')
114114
}
115115

116-
const derived: Derive<string, State> = (_, parent) =>
116+
const derived: Derive<State, string> = (_, parent) =>
117117
parent.foo.toUpperCase()
118118

119119
const config = {
@@ -133,7 +133,7 @@ describe('Derived', () => {
133133
actions: typeof config.actions
134134
}>
135135
type Action<Input = void> = TAction<IApp, Input>
136-
type Derive<Value, Parent extends object> = TDerive<IApp, Value, Parent>
136+
type Derive<Parent extends object, Value> = TDerive<IApp, Parent, Value>
137137

138138
const app = new Overmind(config)
139139

packages/node_modules/overmind/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export type Action<Value = void> = TAction<App, Value>
3737

3838
export type Context = TContext<App>
3939

40-
export type Derive<Value, Parent extends object> = TDerive<App, Value, Parent>
40+
export type Derive<Parent extends object, Value> = TDerive<App, Parent, Value>
4141

4242
export type Reaction = TReaction<App>
4343

packages/node_modules/overmind/src/internalTypes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export type TBaseContext<App extends BaseApp> = App['effects'] & {
116116
}
117117

118118
export type ResolveState<State extends object> = {
119-
[P in keyof State]: State[P] extends TDerive<any, any>
119+
[P in keyof State]: State[P] extends TDerive<any, any, any>
120120
? ReturnType<State[P]>
121121
: State[P] extends Array<any>
122122
? State[P]

packages/node_modules/overmind/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export type TOperator<Input, Output, OperatorContext extends TContext<any>> = (
5050
final?: (err, Error, val?: TValueContext<OperatorContext, Output>) => void
5151
) => void
5252

53-
export type TDerive<App extends BaseApp, Value, Parent extends object = {}> = (
53+
export type TDerive<App extends BaseApp, Parent extends object, Value> = (
5454
parent: ResolveState<Parent>,
5555
state: App['state']
5656
) => Value

packages/overmind-website/examples/guide/managinglists/derivetolist.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type Post {
1515
1616
export type State = {
1717
posts: { [id: string] : Post }
18-
postsList: Derive<Post[], State>
18+
postsList: Derive<State, Post[]>
1919
}
2020
2121
export const state: State = {

packages/overmind-website/examples/guide/managinglists/filtering.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export type Post {
1616
export type State = {
1717
posts: { [id: string] : Post }
1818
showCount: number
19-
postsList: Derive<Post[], State>
19+
postsList: Derive<State, Post[]>
2020
}
2121
2222
export const state: State = {

packages/overmind-website/examples/guide/managinglists/sort.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type Post {
1515
1616
export type State = {
1717
posts: { [id: string] : Post }
18-
postsList: Derive<Post[], State>
18+
postsList: Derive<State, Post[]>
1919
}
2020
2121
export const state: State = {

0 commit comments

Comments
 (0)