Created
September 29, 2019 18:06
-
-
Save wuzzeb/b33e1866f165b880fc9a742ad7617881 to your computer and use it in GitHub Desktop.
Sample typescript redux 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
export interface SampleState { | |
num: number; | |
} | |
export enum SampleActionType { | |
IncrementNum = "Sample_Increment", | |
DecrementNum = "Sample_Decrement" | |
} | |
export type SampleAction = | |
| { type: SampleActionType.IncrementNum; by: number } | |
| { type: SampleActionType.DecrementNum }; | |
export function sampleReducer(s: SampleState | undefined, a: SampleAction): SampleState { | |
if (s === undefined) { | |
return { num: 100 }; | |
} | |
switch (a.type) { | |
case SampleActionType.IncrementNum: | |
return { num: s.num + a.by }; | |
case SampleActionType.DecrementNum: | |
return { num: s.num - 1 }; | |
default: | |
return s; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment