Last active
April 29, 2016 08:48
-
-
Save urmastalimaa/fd2855b7f13cc169d9b1c3467cd2d83f to your computer and use it in GitHub Desktop.
Embrace simplicity
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
// Given an initial state | |
const initialState = { | |
inputWord: null, | |
completedWords: [], | |
startTime: null, | |
words: [], | |
gameHasStarted: false, | |
highestWordsPerMinute: "0", | |
highestAccuracy: "0", | |
wordFetchInProgress: false | |
}; | |
// and a reducer | |
const reducer = (state, action) => { | |
return R.merge(state, { | |
inputWord: action.payload.inputWord, | |
completedWords: action.payload.completedWords, | |
startTime: action.payload.startTime, | |
words: action.payload.words, | |
gameHasStarted: action.payload.gameHasStarted, | |
highestWordsPerMinute: action.payload.highestWordsPerMinute, | |
highestAccuracy: action.payload.highestAccuracy, | |
wordFetchInProgress: action.payload.wordFetchInProgress | |
}); | |
} | |
// What is the reducer equivalent to? | |
const betterReducer = (state, action) => { | |
return action.payload; | |
} | |
const pointFreeReducer = R.compose(R.prop('payload'), R.nthArg(1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment