This file contains hidden or 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
| export const enum WizardActionTypes { | |
| Hydrate = "WIZARD/HYDRATE", | |
| LearnSpell = "WIZARD/LEARN_SPELL", | |
| KillParents = "WIZARD/KILL_PARENTS" | |
| } | |
| export interface HydrateWizardsAction extends AnyAction { | |
| type: WizardActionTypes.Hydrate; | |
| payload: WizardNamespaceShape; | |
| } |
This file contains hidden or 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
| switch (action.type) { | |
| case WizardActionTypes.Hydrate: { | |
| return { | |
| ...action.payload | |
| }; | |
| } | |
| case WizardActionTypes.KillParents: { |
This file contains hidden or 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 { WizardActionTypes, WizardNamespaceShape } from "./types"; | |
| export function hydrateWizardNamespace(initialData: WizardNamespaceShape) { | |
| return { | |
| type: WizardActionTypes.Hydrate, | |
| payload: initialData | |
| }; | |
| } |
This file contains hidden or 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
| import { getStore, registerReducer } from "../../redux-utils/store"; | |
| import { WIZARD_NAMESPACE_KEY } from "../../redux-utils/types"; | |
| import { once } from "lodash"; | |
| import wizardReducer from "./reducer"; | |
| import { WizardNamespaceShape } from "./types"; | |
| import { hydrateWizardNamespace } from "./actions"; | |
| export const getStoreForWizardApp = once( | |
| (initialData?: WizardNamespaceShape) => { | |
| registerReducer({ [WIZARD_NAMESPACE_KEY]: wizardReducer }); | |
| const store = getStore(); |
This file contains hidden or 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
| //redux-utils/types.ts | |
| import { MuggleNamespaceShape } from "../data/muggles/types"; | |
| import { WizardNamespaceShape } from "../data/wizards/types"; | |
| import { Reducer } from "redux"; | |
| export const MUGGLE_NAMESPACE_KEY = "MUGGLE_NAMESPACE"; | |
| export const WIZARD_NAMESPACE_KEY = "WIZARD_NAMESPACE"; | |
| export type FullStoreShape = { | |
| [MUGGLE_NAMESPACE_KEY]: MuggleNamespaceShape; | |
| [WIZARD_NAMESPACE_KEY]: WizardNamespaceShape; |
This file contains hidden or 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
| // redux-utils/types.ts | |
| import { MuggleNamespaceShape } from "../data/muggles/types"; | |
| import { WizardNamespaceShape } from "../data/wizards/types"; | |
| import { Reducer } from "redux"; | |
| export const MUGGLE_NAMESPACE_KEY = "MUGGLE_NAMESPACE"; | |
| export const WIZARD_NAMESPACE_KEY = "WIZARD_NAMESPACE"; | |
| export type FullStoreShape = { | |
| [MUGGLE_NAMESPACE_KEY]: MuggleNamespaceShape; |
This file contains hidden or 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
| * @returns {Store} A Redux store that lets you read the state, dispatch actions | |
| * and subscribe to changes. | |
| */ | |
| export default function createStore(reducer, preloadedState, enhancer) { |
This file contains hidden or 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
| if ( | |
| (typeof preloadedState === 'function' && typeof enhancer === 'function') || | |
| (typeof enhancer === 'function' && typeof arguments[3] === 'function') | |
| ) { | |
| throw new Error( | |
| 'It looks like you are passing several store enhancers to ' + | |
| 'createStore(). This is not supported. Instead, compose them ' + | |
| 'together to a single function' | |
| ) | |
| } |
This file contains hidden or 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
| let currentReducer = reducer | |
| let currentState = preloadedState | |
| let currentListeners = [] | |
| let nextListeners = currentListeners | |
| let isDispatching = false |
This file contains hidden or 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
| function ensureCanMutateNextListeners() { | |
| if (nextListeners === currentListeners) { | |
| nextListeners = currentListeners.slice() | |
| } | |
| } |