Skip to content

Instantly share code, notes, and snippets.

@urmastalimaa
Last active April 29, 2016 08:48
Show Gist options
  • Save urmastalimaa/fd2855b7f13cc169d9b1c3467cd2d83f to your computer and use it in GitHub Desktop.
Save urmastalimaa/fd2855b7f13cc169d9b1c3467cd2d83f to your computer and use it in GitHub Desktop.
Embrace simplicity
// 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