How to use the redux.createStore function in redux

To help you get started, we’ve selected a few redux examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github openaq / openaq.org / app / assets / scripts / main.js View on Github external
import CommunityWorkshops from './views/community-workshops';
import Map from './views/map';
import LocationsHub from './views/locations-hub';
import LocationItem from './views/location';
import CountriesHub from './views/countries-hub';
import Country from './views/country';
import Compare from './views/compare';

const logger = createLogger({
  level: 'info',
  collapsed: true,
  predicate: (getState, action) => {
    return (process.env.NODE_ENV !== 'production');
  }
});
const store = createStore(reducer, applyMiddleware(thunkMiddleware, logger));
const history = syncHistoryWithStore(hashHistory, store);

// Base data.
store.dispatch(fetchBaseData());
store.dispatch(fetchBaseStats());

const scrollerMiddleware = useScroll((prevRouterProps, currRouterProps) => {
  return prevRouterProps &&
    decodeURIComponent(currRouterProps.location.pathname) !== decodeURIComponent(prevRouterProps.location.pathname);
});

render((
github kvartborg / hueify / src / store / store.js View on Github external
/* global JSON, localStorage */
import { createStore } from 'redux'
import defaultState from './defaultState'

/**
 * Create a new redux store
 * @type {Redux}
 */
const store = createStore((
  state = (JSON.parse(localStorage.getItem('store')) || defaultState),
  action
) => {
  switch (action.type) {
    case 'SET_VIEW':
      return { ...state, view: action.view }
    case 'SET_HOST':
      return { ...state, settings: { host: action.host } }
    case 'SET_BRIDGE':
      return { ...state, bridge: action.bridge }
    case 'SET_LIGHTS':
      return { ...state, lights: action.lights }
    case 'SET_GROUPS':
      return { ...state, groups: action.groups }
    default:
      return { ...state }
github opendatacam / opendatacam / statemanagement / store.js View on Github external
export const initStore = initialState => {
  if (typeof window === 'undefined') {
    let store = createStore(reducers, initialState, enhancer)
    return store
  } else {
    if (!window.store) {
      // For each key of initialState, convert to Immutable object
      // Because SSR passed it as plain object
      Object.keys(initialState).map(function (key, index) {
        initialState[key] = Immutable.fromJS(initialState[key])
      })
      window.store = createStore(reducers, initialState, enhancer)
    }
    return window.store
  }
}
github zenika-open-source / FAQ / src / store.js View on Github external
import { logic as dataLogic } from 'data/logic'
import { logic as scenesLogic } from 'scenes/logic'

/* ROOT REDUCER */
const rootReducer = combineReducers({
  data: dataReducer,
  scenes: scenesReducer
})

/* ROOT LOGIC */
const rootLogic = [...dataLogic, ...scenesLogic]
const logicMiddleware = createLogicMiddleware(rootLogic)
const middleware = applyMiddleware(logicMiddleware)

/* STORE */
const store = createStore(rootReducer, middleware)

export default store
github Monadical-SAS / redux-time / examples / ball.js View on Github external
const initial_animation_state = {
    ball: {
        style: {
            position: 'relative',
            top: '0%',
            left: '45%',
            backgroundColor: 'red',
            width: 100,
            height: 100,
            borderRadius: 50,
            zIndex: 1000,
        }
    }
}
window.store = createStore(combineReducers({
    animations: animationsReducer,
    ball: ballReducer,
}))
window.time = startAnimation(window.store, initial_animation_state)

const BOUNCE_ANIMATIONS = (start_time) =>
    RepeatSequence([
        // high bounce
        Translate({
            path: '/ball',
            start_state: {top: 0, left: 0},
            end_state:  {top: -200, left: 0},
            duration: 500,
            curve: 'easeOutQuad',
            // start_time: window.time.getWarpedTime(),         //  optional, defaults to now
            // unit: 'px',                                      //  optional, defaults to px
github mimshwright / mimstris / src / stores / index.js View on Github external
// selector-only modules
// import message from './message'
// import fallRate from './fallRate'
// import level from './level'

export const REPLACE_STATE = 'REPLACE_STATE'
export const replaceState = (state) => ({
  type: REPLACE_STATE,
  payload: state
})

export const reducer = combineReducers(
  {score, lines, nextPiece, currentPiece, board, gameState, config}
)

export default createStore(
  reducer,
  // To trigger dev tools in browser extension
  window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
)
github mui-org / material-ui / docs / src / index.js View on Github external
// import a11y from 'react-a11y';
// if (process.env.NODE_ENV !== 'production') {
//   a11y(React, { includeSrcNode: true, ReactDOM });
// }

const docs = (state = { dark: false }, action) => {
  if (action.type === 'TOGGLE_THEME_SHADE') {
    return {
      ...state,
      dark: !state.dark,
    };
  }
  return state;
};

const store = createStore(docs);
const rootEl = document.querySelector('#app');

render(
   {
      throw error;
    }}
  >
    
      
    
  ,
  rootEl,
);

if (process.env.NODE_ENV !== 'production' && module.hot) {
github btford / react-palm / src / bootstrap / bootstrap.tsx View on Github external
export function makeStore({subscribe, reducer}) {
  return createStore(
    reducer,
    applyMiddleware(
      taskMiddleware as any,
      makeSubscriptionMiddleware(subscribe)
    )
  );
}
github Lucifier129 / next-mvc / src / controller.js View on Github external
const options = {
				name: window.location.pathname + window.location.search
			}
			const reduxDevtoolsEnhancer = window.__REDUX_DEVTOOLS_EXTENSION__(options)
			if (!enhancer) {
				enhancer = reduxDevtoolsEnhancer
			} else {
				const composeEnhancers =
					window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
				enhancer = composeEnhancers(
					applyMiddleware(reduxDevtoolsEnhancer, enhancer)
				)
			}
		}

		this.store = createStore(reducer, finalInitialState, enhancer)
		return this.store
	}
github btholt / complete-intro-to-react / src / store.js View on Github external
import { createStore, compose, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import reducer from './reducers';

const store = createStore(
  reducer,
  compose(
    applyMiddleware(thunk),
    typeof window === 'object' && typeof window.devToolsExtension !== 'undefined' ? window.devToolsExtension() : f => f
  )
);

export default store;