Last active
March 3, 2018 14:24
-
-
Save zhirzh/26e0556e8710e6337aa14ac4ba06613a 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
+type ClearAction = {type: 'CLEAR'}; | |
+type ResetAction = {type: 'RESET', text: 'Hello World'}; | |
+type UpdateAction = {type: 'UPDATE', text: string}; | |
+ | |
+type Action = | |
+ | ClearAction | |
+ | ResetAction | |
+ | UpdateAction; | |
+ | |
const CLEAR = 'CLEAR'; | |
const RESET = 'RESET'; | |
const UPDATE = 'UPDATE'; | |
-function reducer(state: string = '', action) { | |
+function reducer(state: string = '', action: Action) { | |
switch (action.type) { | |
case CLEAR: | |
return ''; |
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
type ClearAction = {type: 'CLEAR'}; | |
type ResetAction = {type: 'RESET', text: 'Hello World'}; | |
type UpdateAction = {type: 'UPDATE', text: string}; | |
type Action = | |
| ClearAction | |
| ResetAction | |
| UpdateAction; | |
const CLEAR = 'CLEAR'; | |
const RESET = 'RESET'; | |
const UPDATE = 'UPDATE'; | |
function reducer(state: string = '', action: Action) { | |
switch (action.type) { | |
case CLEAR: | |
return ''; | |
case RESET: | |
return action.text; | |
case UPDATE: | |
return action.text; | |
default: | |
return state; | |
} | |
} | |
function clear() { | |
return { type: CLEAR }; | |
} | |
function reset() { | |
return { type: RESET, text: 'Hello World' }; | |
} | |
function update(text: string) { | |
return { type: UPDATE, text }; | |
} |
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
const CLEAR = 'CLEAR'; | |
const RESET = 'RESET'; | |
const UPDATE = 'UPDATE'; | |
function reducer(state: string = '', action) { | |
switch (action.type) { | |
case CLEAR: | |
return ''; | |
case RESET: | |
return action.text; | |
case UPDATE: | |
return action.text; | |
default: | |
return state; | |
} | |
} | |
function clear() { | |
return { type: CLEAR }; | |
} | |
function reset() { | |
return { type: RESET, text: 'Hello World' }; | |
} | |
function update(text: string) { | |
return { type: UPDATE, text }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment