Skip to content

Commit 57c4e83

Browse files
refactor(overmind): flip state and value argument in mutation operator
1 parent 7c9711b commit 57c4e83

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import { Action } from './'
44
export default (action: Action) => ({
55
changeNewTodoTitle: action<React.ChangeEvent<HTMLInputElement>>()
66
.map((event) => event.currentTarget.value)
7-
.mutation((state, value) => (state.newTodoTitle = value)),
7+
.mutation((value, state) => (state.newTodoTitle = value)),
88
})

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,33 +26,33 @@ const connectCurrentPort = (action: (message: any) => void) => (
2626
MUTATIONS
2727
*/
2828

29-
const setApps = (state: State, apps: Apps) => (state.apps = apps || {})
29+
const setApps = (apps: Apps, state: State) => (state.apps = apps || {})
3030

31-
const setCurrentPort = (state: State, currentPort: string) => {
31+
const setCurrentPort = (currentPort: string, state: State) => {
3232
if (currentPort) {
3333
state.currentPort = currentPort
3434
} else if (Object.keys(state.apps).length) {
3535
state.currentPort = Object.keys(state.apps)[0]
3636
}
3737
}
3838

39-
const setError = (state: State, error: string) => (state.error = error)
39+
const setError = (error: string, state: State) => (state.error = error)
4040

41-
const setAppLoaded = (state: State) => (state.isLoading = false)
41+
const setAppLoaded = (_, state: State) => (state.isLoading = false)
4242

43-
const setNewPortValue = (state: State, value: string) =>
43+
const setNewPortValue = (value: string, state: State) =>
4444
(state.newPortValue = value)
4545

46-
const addNewApp = (state: State) =>
46+
const addNewApp = (_, state: State) =>
4747
(state.apps[state.newPortValue] = {
4848
name: null,
4949
port: state.newPortValue,
5050
messages: [],
5151
})
5252

53-
const resetNewPortValue = (state: State) => (state.newPortValue = '')
53+
const resetNewPortValue = (_, state: State) => (state.newPortValue = '')
5454

55-
const addMessageFromClient = (state: State, message: Message) => {
55+
const addMessageFromClient = (message: Message, state: State) => {
5656
state.apps[message.port].messages = state.apps[message.port].messages.concat(
5757
message.message
5858
)

packages/node_modules/overmind/src/createActionFactory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type OperatorCallback<Context, Value, NewValue = Value> = (
1414

1515
interface Operators<State, Context, InitialValue, Value> {
1616
mutation(
17-
cb: (state: State, value: Value) => any
17+
cb: (value: Value, state: State) => any
1818
): InitialValue extends undefined
1919
? NoValueAction<State, Context, InitialValue, Value>
2020
: Action<State, Context, InitialValue, Value>
@@ -99,10 +99,10 @@ export default function createActionFactory<State, Context>(proxyStateTree) {
9999
runOperators
100100
) as any,
101101
{
102-
mutation(cb: (state: State, value: Value) => any) {
102+
mutation(cb: (value: Value, state: State) => any) {
103103
const operator = (value, context) => {
104104
proxyStateTree.startMutationTracking()
105-
cb(context.state, value)
105+
cb(value, context.state)
106106
const mutations = proxyStateTree.clearMutationTracking()
107107
actionChain.emit('mutations', {
108108
mutations,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ describe('OPERATORS', () => {
5454
foo: 'bar',
5555
},
5656
actions: (action) => ({
57-
doThis: action().mutation((state) => (state.foo = 'bar2')),
57+
doThis: action().mutation((_, state) => (state.foo = 'bar2')),
5858
}),
5959
})
6060

0 commit comments

Comments
 (0)