Last active
August 23, 2018 15:48
-
-
Save matthew-gerstman/7447b9ae50d93c4f6123a970bcb170b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// data/wizards/reducer.ts | |
import { WizardAction, WizardActionTypes, WizardNamespaceShape } from "./types"; | |
const defaultState: WizardNamespaceShape = { | |
harryPotter: { | |
name: "Harry Potter", | |
parentsAlive: false, | |
spells: [] | |
} | |
}; | |
export default function reducer( | |
state: WizardNamespaceShape, | |
action: WizardAction | |
) { | |
switch (action.type) { | |
case WizardActionTypes.KillParents: { | |
const { id } = action.payload; | |
return { | |
...state, | |
[id]: { | |
...state[id], | |
parentsAlive: false | |
} | |
}; | |
} | |
case WizardActionTypes.LearnSpell: { | |
const { id, spell } = action.payload; | |
return { | |
...state, | |
[id]: { | |
...state[id], | |
spells: [...state[id].spells, spell] | |
} | |
}; | |
} | |
default: { | |
return state; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment