Skip to content

Instantly share code, notes, and snippets.

@samsch
Created February 9, 2016 19:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samsch/63a54e868d7fa2b6023a to your computer and use it in GitHub Desktop.
Save samsch/63a54e868d7fa2b6023a to your computer and use it in GitHub Desktop.
Possible solution to Redux action type name confilcts.
//Action type constants don't have to have the same name as their value.
//Really, the const string value doesn't even have to be related to the action itself.
const UPDATE = 'randomValueGeneratedSomehow';
let updateThing = function(newValue) {
return {
type: UPDATE,
payload: newValue,
}
}
module.exports = {
UPDATE,
updateThing,
}
//The reducer doesn't care about the action type string value, only that the constant matches.
//So this constant name can be used by other reducers in other files without conflicting with this one.
let { UPDATE } = require('./actions.js');
function thingReducer(state = {}, action) {
if(action.type === UPDATE) {
return action.payload;
}
return state;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment