Skip to content

Instantly share code, notes, and snippets.

@matthew-gerstman
Created August 23, 2018 14:40
Show Gist options
  • Save matthew-gerstman/4ce621d79bf0b86a31d9174634d89a47 to your computer and use it in GitHub Desktop.
Save matthew-gerstman/4ce621d79bf0b86a31d9174634d89a47 to your computer and use it in GitHub Desktop.
// 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;
@vincentreynaud
Copy link

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?

@vincentreynaud
Copy link

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