Skip to content

Commit af30335

Browse files
fix(overmind): use actual rehydrate, DOH
1 parent 2e105df commit af30335

File tree

2 files changed

+3
-19
lines changed

2 files changed

+3
-19
lines changed

packages/node_modules/overmind/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,9 @@ import {
5959
getActionPaths,
6060
getFunctionName,
6161
isPromise,
62-
runMutation,
6362
processState,
6463
} from './utils'
65-
64+
import { rehydrate } from './rehydrate'
6665
export * from './types'
6766

6867
export { createOperator, createMutationOperator, ResolveState, ResolveActions }
@@ -952,9 +951,10 @@ export class Overmind<ThisConfig extends IConfiguration>
952951
this.actions = this.getActions(configuration.actions)
953952
this.effects = configuration.effects || {}
954953

954+
// We do one at a time as they might error due to changed state structure
955955
this.reydrateMutationsForHotReloading.forEach((mutation) => {
956956
try {
957-
runMutation(this.state, mutation)
957+
rehydrate(this.state as any, [mutation])
958958
} catch (error) {
959959
// No worries, structure changed and we do not want to mutate anyways
960960
}

packages/node_modules/overmind/src/utils.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,22 +90,6 @@ export function deepCopy(obj) {
9090
return obj
9191
}
9292

93-
export const runMutation = (state: any, mutation: IMutation) => {
94-
const pathArray = mutation.path.split(mutation.delimiter)
95-
const key = pathArray.pop() as string
96-
const target = pathArray.reduce((current, pathKey) => current[pathKey].__CLASS__ ? current[pathKey].value : current[pathKey], state)
97-
98-
switch (mutation.method) {
99-
case 'set':
100-
target[key] = mutation.args[0]
101-
break
102-
case 'unset':
103-
delete target[key]
104-
break
105-
default:
106-
target[key][mutation.method](...mutation.args)
107-
}
108-
}
10993

11094

11195
export function getActionPaths(actions = {}, currentPath: string[] = []) {

0 commit comments

Comments
 (0)