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
Yo |
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
Program HarryPotter (input,output); | |
Uses CRT; | |
Var | |
Book,Chapter,Last,test,index,PW,hold,High,Low,Multiple,v,Check:Integer; | |
Part:Char; | |
Unwanted:Array [1..4] of integer; | |
Procedure Matt; | |
Var |
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
//redux-utils/types.ts | |
import { Reducer } from "redux"; | |
import { MuggleNamespaceShape } from "../data/muggles/types"; | |
import { WizardNamespaceShape } from "../data/wizards/types"; | |
export const MUGGLE_NAMESPACE_KEY = "MUGGLE_NAMESPACE"; | |
export const WIZARD_NAMESPACE_KEY = "WIZARD_NAMESPACE"; | |
export type FullStoreShape = { |
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
// redux-utils/store.ts | |
import { combineReducers, createStore, Store } from "redux"; | |
import { ReducerMap, StoreShape } from "./types"; | |
let reducerMap: ReducerMap = {}; | |
const store = createStore(combineReducers(reducerMap)); | |
export function getStore() { | |
return store; |
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
// redux-utils/selectors.ts | |
import { FullStoreShape, NamespaceKey, StoreShape } from "./types"; | |
export function getStateAtNamespaceKey<T extends NamespaceKey>( | |
state: StoreShape, | |
namespace: T | |
): FullStoreShape[T] { | |
const namespaceState = state[namespace]; | |
if (!namespaceState) { | |
throw new Error( |
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
// wizards.tsx | |
import * as React from "react"; | |
import { connect, Provider } from "react-redux"; | |
import { getStoreForWizardApp } from "./data/wizards/store"; | |
import { Wizard } from "./data/wizards/types"; | |
import { getWizards } from "./data/wizards/selectors"; | |
export function WizardApp() { | |
return ( | |
<Provider store={getStoreForWizardApp()}> |
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/store.ts | |
import { getStore, registerReducer } from "../../redux-utils/store"; | |
import { WIZARD_NAMESPACE_KEY } from "../../redux-utils/types"; | |
import { once } from "lodash"; | |
import wizardReducer from "./reducer"; | |
export const getStoreForWizardApp = once(() => { | |
registerReducer({ [WIZARD_NAMESPACE_KEY]: wizardReducer }); | |
return getStore(); | |
}); |
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/selectors.ts | |
import { getStateAtNamespaceKey } from "../../redux-utils/selectors"; | |
import { StoreShape, WIZARD_NAMESPACE_KEY } from "../../redux-utils/types"; | |
import { mapValues } from "lodash"; | |
import { Wizard } from "./types"; | |
const getWizards = (state: StoreShape) => ( | |
getStateAtNamespaceKey(state, WIZARD_NAMESPACE_KEY) | |
); |
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", |
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: [] | |
} | |
}; |
OlderNewer