Skip to content

Instantly share code, notes, and snippets.

@tamizhvendan
Created April 22, 2016 13:24
Show Gist options
  • Select an option

  • Save tamizhvendan/b75e486c183f75dd12739458494d011e to your computer and use it in GitHub Desktop.

Select an option

Save tamizhvendan/b75e486c183f75dd12739458494d011e to your computer and use it in GitHub Desktop.
Redux sample implementation
const statusMessagesReducer = (state = [], action) => {
if (action.type === "ADD_STATUS") {
return state.concat(action.statusMessage);
}
return state;
};
const notificationsReducer = (state = [], action) => {
if (action.type === "ADD_NOTIFICATION") {
return state.concat(action.notification);
}
return state;
};
const store = Redux.createStore(Redux.combineReducers({
statusMessages: statusMessagesReducer,
notifications: notificationsReducer,
}));
let addStatusMessage = (statusMessage) => {
return {
type : "ADD_STATUS",
statusMessage : statusMessage
};
};
let addNotification = (notification) => {
return {
type : "ADD_NOTIFICATION",
notification : notification
};
};
let unsubscribe = store.subscribe(() =>
console.log(store.getState())
)
store.dispatch(addStatusMessage({
message : "Redux looks cool",
likesCount: 23,
postedAt: "12/12/2015"
}));
store.dispatch(addNotification({
message : "Some liked your status"
}));
unsubscribe();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment