Skip to content

Instantly share code, notes, and snippets.

View asherccohen's full-sized avatar

Asher Cohen asherccohen

View GitHub Profile
(function (history, trackingId, options) {
const generateId = () => {
return '_' + Math.random().toString(36).substr(2, 9);
};
const getId = () => {
if (!localStorage.cid) {
localStorage.cid = generateId()
}
return localStorage.cid;
};
import { combineReducers } from 'redux';
import AppReducer from './AppReducer';
import UsersReducer from './UsersReducer';
import OrderReducer from './OrderReducer';
import NotificationReducer from './NotificationReducer';
import CommentReducer from './CommentReducer';
const appReducer = combineReducers({
/* your app’s top-level reducers */
const rootReducer = (state, action) => {
if (action.type === USER_LOGGED_OUT) {
// for all keys defined in your persistConfig(s)
storage.removeItem('persist:root')
// storage.removeItem('persist:otherKey')
state = undefined;
}
return appReducer(state, action);
};
import { combineReducers } from 'redux';
import AppReducer from './AppReducer';
import UsersReducer from './UsersReducer';
import OrderReducer from './OrderReducer';
import NotificationReducer from './NotificationReducer';
import CommentReducer from './CommentReducer';
const appReducer = combineReducers({
/* your app’s top-level reducers */
const rootReducer = (state, action) => {
// when a logout action is dispatched it will reset redux state
if (action.type === 'USER_LOGGED_OUT') {
const { users, comment } = state;
state = { users, comment };
}
if (action.type === 'USER_LOGGED_IN') {
const INITIAL_STATE = {
orderList: {},
isRetrievingOrder: false,
errorRetrievingOrder: false,
errorRetrievingOrderMessage: null,
isSavingOrder: false,
errorSavingOrder: false,
errorSavingOrderMessage: null,
isCancellingOrder: false,
errorCancellingOrder: false,
import { createStore } from 'redux';
// local import
import reducers from '../reducers';
const store =
reducers &&
createStore(reducers);
export default store;
// events/reducer.js
const initialState = { todos: [] };
export const eventsReducer = (state = initialState, action) => {
switch(action.type) {
case 'GET_EVENTS_REQUEST':
return { ...state, isFetching: true };
case 'GET_EVENTS_SUCCESS':
return { ...state, isFetching: false, todos: action.payload };
case 'GET_EVENTS_FAILURE':
return { ...state, isFetching: false, errorMessage: action.payload.message };
// todo/actions.js
export const getEvents = (dispatch) => () => {
dispatch({ type: 'GET_EVENTS_REQUEST' });
return fetch('/api/v1/events')
.then((todos) => dispatch({ type: 'GET_EVENTS_SUCCESS', payload: todos })
.catch((error) => dispatch({ type: 'GET_EVENTS_FAILURE', payload: error, error: true });
};
@asherccohen
asherccohen / reducerActionTypes.JS
Created July 26, 2019 11:11
reducerActionTypes
export const FETCH_TODOS_REQUEST = 'FETCH_TODOS_REQUEST';
export const FETCH_TODOS_SUCCESS = 'FETCH_TODOS_SUCCESS';
export const FETCH_TODOS_FAILURE = 'FETCH_TODOS_FAILURE';