Skip to content

Commit 075deb7

Browse files
Merge pull request cerebral#19 from cerebral/unionTypesFix
fix(action-chain): fix setting union type as value type
2 parents 2dcda6c + 303592b commit 075deb7

File tree

6 files changed

+21
-37
lines changed

6 files changed

+21
-37
lines changed

packages/node_modules/action-chain/src/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import {
1010
interface Operators<Context, InitialValue, Value> {
1111
test(
1212
cb: (value: Value, context: Context) => void
13-
): InitialValue extends undefined
13+
): [InitialValue] extends [void]
1414
? NoValueAction<Context, InitialValue, Value>
1515
: Action<Context, InitialValue, Value>
1616
testFork(
1717
action: Action<Context, Value>
18-
): InitialValue extends undefined
18+
): [InitialValue] extends [void]
1919
? NoValueAction<Context, InitialValue, Value>
2020
: Action<Context, InitialValue, Value>
2121
}

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Action } from './'
22
import * as mutations from './mutations'
33
import * as helpers from './helpers'
4-
import { Message } from './state'
4+
import { Message, Tab } from './state'
55

66
export default (action: Action) => {
77
const onMessage = action<Message>()
@@ -30,13 +30,7 @@ export default (action: Action) => {
3030
.mutation(mutations.resetNewPortValue)
3131
.do(helpers.storeApps)
3232

33-
const openState = action().mutation(mutations.openState)
34-
35-
const openConsole = action().mutation(mutations.openConsole)
36-
37-
const openComponents = action().mutation(mutations.openComponents)
38-
39-
const openFlushes = action().mutation(mutations.openFlushes)
33+
const changeTab = action<Tab>().mutation(mutations.changeTab)
4034

4135
const openApp = action<string>()
4236

@@ -49,10 +43,7 @@ export default (action: Action) => {
4943
setError,
5044
changeNewPortValue,
5145
addPort,
52-
openState,
53-
openConsole,
54-
openComponents,
55-
openFlushes,
46+
changeTab,
5647
openApp,
5748
toggleExpandState,
5849
}

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

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,7 @@ export const addMessagesFromClient = (message: Message, state: State) => {
4141
)
4242
}
4343

44-
export const openState = (_, state: State) => (state.currentTab = Tab.State)
45-
46-
export const openConsole = (_, state: State) => (state.currentTab = Tab.Console)
47-
48-
export const openComponents = (_, state: State) =>
49-
(state.currentTab = Tab.Components)
50-
51-
export const openFlushes = (_, state: State) => (state.currentTab = Tab.Flushes)
44+
export const changeTab = (tab: Tab, state: State) => (state.currentTab = tab)
5245

5346
export const toggleExpandStatePath = (path: string[], state: State) => {
5447
const pathString = path.join('.')

packages/node_modules/overmind-devtools/src/components/Tabs/index.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@ const Tabs: React.SFC<Connect> = ({ app }) => (
1010
<Tooltip text="State">
1111
<Button
1212
active={app.state.currentTab === Tab.State}
13-
onClick={app.actions.openState}
13+
onClick={() => app.actions.changeTab(Tab.State)}
1414
>
1515
<Icon>database</Icon>
1616
</Button>
1717
</Tooltip>
1818
<Tooltip text="Components">
1919
<Button
2020
active={app.state.currentTab === Tab.Components}
21-
onClick={app.actions.openComponents}
21+
onClick={() => app.actions.changeTab(Tab.Components)}
2222
>
2323
<Icon>code</Icon>
2424
</Button>
2525
</Tooltip>
2626
<Tooltip text="Flushes">
2727
<Button
2828
active={app.state.currentTab === Tab.Flushes}
29-
onClick={app.actions.openFlushes}
29+
onClick={() => app.actions.changeTab(Tab.Flushes)}
3030
>
3131
<Icon>save</Icon>
3232
</Button>
3333
</Tooltip>
3434
<Tooltip text="Console">
3535
<Button
3636
active={app.state.currentTab === Tab.Console}
37-
onClick={app.actions.openConsole}
37+
onClick={() => app.actions.changeTab(Tab.Console)}
3838
>
3939
<Icon>terminal</Icon>
4040
</Button>

packages/node_modules/overmind/src/createActionFactory.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ interface Operators<State, Context, InitialValue, Value> {
1616
fork<Paths>(
1717
cb: (value: Value, context: Context) => keyof Paths,
1818
paths: Paths
19-
): InitialValue extends void
19+
): [InitialValue] extends [void]
2020
? NoValueAction<State, Context, InitialValue, Value>
2121
: Action<State, Context, InitialValue, Value>
2222
mutation(
2323
cb: (value: Value, state: State) => any
24-
): InitialValue extends void
24+
): [InitialValue] extends [void]
2525
? NoValueAction<State, Context, InitialValue, Value>
2626
: Action<State, Context, InitialValue, Value>
2727
do(
2828
cb: (value: Value, context: Context) => void
29-
): InitialValue extends void
29+
): [InitialValue] extends [void]
3030
? NoValueAction<State, Context, InitialValue, Value>
3131
: Action<State, Context, InitialValue, Value>
3232
map<NewValue>(
3333
cb: (value: Value, context: Context) => NewValue | Promise<NewValue>
34-
): InitialValue extends void
34+
): [InitialValue] extends [void]
3535
? NoValueAction<State, Context, InitialValue, NewValue>
3636
: Action<State, Context, InitialValue, NewValue>
3737
try<ResolveValue, RejectValue, NewValue>(
@@ -50,7 +50,7 @@ interface Operators<State, Context, InitialValue, Value> {
5050
RejectValue
5151
>
5252
}
53-
): InitialValue extends void
53+
): [InitialValue] extends [void]
5454
? NoValueAction<State, Context, InitialValue, ResolveValue | RejectValue>
5555
: Action<State, Context, InitialValue, ResolveValue | RejectValue>
5656
when<TrueValue, FalseValue>(
@@ -59,17 +59,17 @@ interface Operators<State, Context, InitialValue, Value> {
5959
true: Action<State, Context, Value, TrueValue>
6060
false: Action<State, Context, Value, FalseValue>
6161
}
62-
): InitialValue extends void
62+
): [InitialValue] extends [void]
6363
? NoValueAction<State, Context, InitialValue, TrueValue | FalseValue>
6464
: Action<State, Context, InitialValue, TrueValue | FalseValue>
6565
filter(
6666
cb: (value: Value, context: Context) => boolean
67-
): InitialValue extends void
67+
): [InitialValue] extends [void]
6868
? NoValueAction<State, Context, InitialValue, Value>
6969
: Action<State, Context, InitialValue, Value>
7070
debounce(
7171
timer: number
72-
): InitialValue extends void
72+
): [InitialValue] extends [void]
7373
? NoValueAction<State, Context, InitialValue, Value>
7474
: Action<State, Context, InitialValue, Value>
7575
}
@@ -95,7 +95,7 @@ export default function createActionFactory<State, Context>(proxyStateTree) {
9595
value: any,
9696
executionContext: ExecutionContext
9797
) => any | Promise<any>
98-
): InitialValue extends void
98+
): [InitialValue] extends [void]
9999
? NoValueAction<State, Context, InitialValue, Value>
100100
: Action<State, Context, InitialValue, Value> {
101101
return Object.assign(

packages/node_modules/overmind/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export type TContext<State, Providers = {}> = Providers & {
2727
}
2828

2929
export interface IAction<State, Context> {
30-
<InitialValue = void>(): InitialValue extends void
30+
<InitialValue = void>(): [InitialValue] extends [void]
3131
? NoValueAction<State, Context, InitialValue>
3232
: Action<State, Context, InitialValue>
3333
}
@@ -71,7 +71,7 @@ export default class App<
7171
State,
7272
Providers & { state: State }
7373
>(proxyStateTree)
74-
const action = function<InitialValue>(): InitialValue extends void
74+
const action = function<InitialValue>(): [InitialValue] extends [void]
7575
? NoValueAction<State, Providers & { state: State }, InitialValue>
7676
: Action<State, Providers & { state: State }, InitialValue> {
7777
return actionFactory<InitialValue>(actionChain)

0 commit comments

Comments
 (0)