Created
August 23, 2018 14:40
-
-
Save matthew-gerstman/4ce621d79bf0b86a31d9174634d89a47 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/actions.ts | |
import { AnyAction } from "redux"; | |
export type Wizard = { | |
name: string; | |
parentsAlive: boolean; | |
spells: string[]; | |
}; | |
export const enum WizardActionTypes { | |
LearnSpell = "WIZARD/LEARN_SPELL", | |
KillParents = "WIZARD/KILL_PARENTS" | |
} | |
export type WizardNamespaceShape = { | |
[id: string]: Wizard; | |
}; | |
export interface LearnSpellAction extends AnyAction { | |
type: WizardActionTypes.LearnSpell; | |
payload: { id: string; spell: string }; | |
} | |
export interface KillParentsAction extends AnyAction { | |
type: WizardActionTypes.KillParents; | |
payload: { id: string }; | |
} | |
export type WizardAction = LearnSpellAction | KillParentsAction; |
But in actions.ts
I would add this:
import shortid from 'shortid';
export function learnSpell(spell: string) {
return {
type: WizardActionTypes.LearnSpell,
payload: { id: shortid.generate(), spell }
};
}
export function killParents(id: string) {
return {
type: WizardActionTypes.KillParents,
payload: { id }
};
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @matthew-gerstman! Following your tutorial on Medium, other bits of the code indicate that this file should be
./data/wizards/types
. Or am I confused?