export default function createStore({
  history = createMemoryHistory(),
  initialState = {},
}: CreateStoreParams = {}) {
  const sagaMiddleware = createSagaMiddleware();
  const store = _createStore(
    createRootReducer({ history, reducers }),
    initialState,
    middleware({
      routerMiddleware: routerMiddleware(history),
      sagaMiddleware,
    }),
  );

  return { sagaMiddleware, store };
}
Example #2
0
export const configureMiddlewares = history => {
    let middlewares = [];
    middlewares.push(thunkMiddleware);
    middlewares.push(routerMiddleware(history));
    let sagaMiddleware = createSagaMiddleware();
    let onStoreCreated = () => configureSagas(sagaMiddleware);
    middlewares.push(sagaMiddleware);
    if (DEBUG) {
        middlewares.push(createLogger({
            collapsed: true,
            diff: true,
            actionTransformer: a => ({...a, type: a.type.toString()})
        }));
    }
    return {middlewares, onStoreCreated};
};
Example #3
0
export default function configure(initialState) {
  const enhancer = compose(
    applyMiddleware(syncHistory(hashHistory), createSagaMiddleware(sagas)),
    window.devToolsExtension ? window.devToolsExtension() : f => f
  );
  const store = createStore(rootReducer, initialState, enhancer);

  if (module.hot) {
    module.hot.accept('../reducers', () => {
      const nextReducer = require('../reducers');
      store.replaceReducer(nextReducer);
    });
  }

  return store;
}
export default (req, initialState) => {
  console.log('Server router!');

  const saga = createSagaMiddleware();

  const composeEnhancers = composeWithDevTools({});

  const enhancer = composeEnhancers(
    applyMiddleware(saga)
  );

  const store = createStore(rootReducer, initialState, enhancer);
  saga.run(rootSaga);

  return store;
};
Example #5
0
function getEnhancer() {
  const sagaMiddleware = createSagaMiddleware()
  let middleware = [routerMiddleware(browserHistory), sagaMiddleware]

  if (isDev)
    middleware = [...middleware, createLogger()]

  let enhancer = applyMiddleware(...middleware)

  if (isDev) {
    let devToolsExtension = window.devToolsExtension ? window.devToolsExtension() : f => f
    enhancer = compose(enhancer, devToolsExtension)
  }

  return { enhancer, runSaga: sagaMiddleware.run }
}
export default function configureStore() {
  const sagaMiddleware = createSagaMiddleware();

  const store = createStore(
    connectRouter(history)(rootReducer),
    composeEnhancers(
      applyMiddleware(
        routerMiddleware(history),
        sagaMiddleware
      ),
    ),
  );
  sagaMiddleware.run(saga);

  return store;
}
  $provide.factory('store', ($injector, $rootScope) => {

    // Create the sagas from their injectable factories
    var sagas = sagaFactories.map((sagaFactory)=> $injector.invoke(sagaFactory));
    middleware = [createSagaMiddleware(...flatten(sagas)), ...middleware];

    const store = createStore(
      combineReducers(reducers),
      applyMiddleware(...middleware)
    );

    // Trigger a digest (if necessary) after each change to the store
    store.subscribe(() => $rootScope.$evalAsync());

    return store;
  });
export default function createApplicationStore() {
  const sagaMiddleware = createSagaMiddleware({
    onError(error) {
      if (get(console, 'error')) {
        // eslint-disable-next-line no-console
        console.error(error);
      }
      bugsnagClient.notify(error);
    },
  });
  const store = createStore(
    reducers,
    compose(applyMiddleware(sagaMiddleware)),
  );
  sagaMiddleware.run(rootSaga);
  return store;
}
export default function configureStore(initialState) {
  const sagaMiddleware = createSagaMiddleware();
  const store = createStore(
    combineReducers({
      ...reducers,
      routing: routerReducer
    }),
    initialState,
    applyMiddleware(
      sagaMiddleware
    )
  );

  sagaMiddleware.run(rootSaga);

  return store;
}
Example #10
0
export default function configureStore(initialState = {}, browserHistory) {
    const middlewares = [];
    const sagaMiddleware = createSagaMiddleware();
    middlewares.push(thunk);
    middlewares.push(routerMiddleware(browserHistory));
    middlewares.push(socketIoMiddleware);
    middlewares.push(sagaMiddleware);

    if (__DEVELOPMENT__) {
        const createLogger = require('redux-logger');
        const logger = createLogger({ predicate:
            (getState, action) => action.type !== 'EFFECT_TRIGGERED' &&
                                  action.type !== 'EFFECT_RESOLVED' });
        middlewares.push(logger);
    }

    if (__USE_GA__) {
        const { googleAnalyticsMiddleware } = require('../middlewares/ga');
        middlewares.push(googleAnalyticsMiddleware);
    }

    let createStoreWithMiddleware = applyMiddleware(...middlewares);

    if (__DEVTOOLS__) {
        createStoreWithMiddleware = compose(
            createStoreWithMiddleware,
            DevTools.instrument()
        );
    }

    const finalCreateStore = createStoreWithMiddleware(createStore);
    const store = finalCreateStore(reducers, initialState);
    sagaMiddleware.run(sagas);

    if (__DEVELOPMENT__) {
        if (module.hot) {
            // Enable Webpack hot module replacement for reducers
            module.hot.accept('../state', () => {
                const nextReducer = require('../state');
                store.replaceReducer(nextReducer);
            });
        }
    }

    return store;
}
Example #11
0
  function connect (select, dispatch, path=[]) {
    const dataset = { pick: select }
    let sagaEmitter

    function modelDispatch(action) {
      action.path = path
      action.pathIndex = 0
      const res = dispatch(action)
      if(sagaEmitter)
        sagaEmitter(action)
      return res
    }

    if(update.fields) {
      Object.keys(update.fields).forEach(field => {
        const getFieldState = () => select()[field]
        const fieldModel = update.fields[field]
        dataset[field] = fieldModel.connect(
          getFieldState,
          dispatch,
          push(path, field)
        )
      })
    }

    actionNames.forEach(key => {
      const action = actions[key]
      dataset[key] = action.__thunk__
        ? action(dataset)
        : (...args) => modelDispatch(action(...args))
    })

    viewNames.forEach(key => {
      const view = views[key]
      dataset[key] = () => view(select())
    })
    console.log('connected!')

    if(saga) {

      sagaEmitter = createSagaMiddleware(saga)({getState: select, dispatch: modelDispatch})(()=>{})

    }

    return dataset
  }
    it("must passes when used properly", () => {
      const logger = level => {};
      const error = (e: Error) => {};
      const error2 = () => {};

      sagaMiddlewareFactory({ sagaMonitor });
      sagaMiddlewareFactory({ logger });
      sagaMiddlewareFactory({ onError: error });
      sagaMiddlewareFactory({ onError: error2 });
      sagaMiddlewareFactory<{ someContext: string }>({
        context: { someContext: "data" }
      });

      sagaMiddlewareFactory({ effectMiddlewares: [] });
      sagaMiddlewareFactory({ effectMiddlewares: [simpleEffectMiddleware] });
    });
Example #13
0
// Creates the redux store for application state
// (both the persistent storage and the canvas state)
export default function makeStore() {
    const db = new PouchDB('reduxstore')

    const sagaMiddleware = createSagaMiddleware()

    const enhancer = compose(
        persistentStore(db),
        applyMiddleware(sagaMiddleware, thunk),
    )

    const store = createStore(rootReducer, undefined, enhancer)

    for (let saga in sagas) {
        sagaMiddleware.run(sagas[saga])
    }

    return store
}
Example #14
0
 componentWillMount() {
   const sagaMiddleware = createSagaMiddleware();
   const composeEnhancers = composeWithDevTools({});
   this.history = createHistory();
   const routerReduxMiddleware = routerMiddleware(this.history);
   const middlewares = [
     routerReduxMiddleware,
     sagaMiddleware,
   ];
   this.store = createStore(
     combineReducers({
       ...reducers,
       router: routerReducer
     }),
     composeEnhancers(applyMiddleware(...middlewares))
   );
   sagaMiddleware.run(sagas);
 }
Example #15
0
export const getStore = ()=>{
    const sagaMiddleware = createSagaMiddleware();
    const middleWares = [sagaMiddleware,thunk];
    if (getQuery()['logger']) { middleWares.push(logger)}
    const composables = [applyMiddleware(...middleWares)
    //    , window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
    ];
    const enhancer = compose(
        ... composables
);
    const store = createStore(
        reducer,
        defaultState,
        enhancer,
    );
    initSagas(sagaMiddleware);
    return store;
};
export function createNewStore() {
  const initialState = new Map({});

  const sagaMiddleware = createSagaMiddleware();
  const store = createStore(rootReducer, initialState, compose(
    applyMiddleware(
      createDebounce({ simple: 1000 }),
      createLogger({
        stateTransformer: state => state.toJS ? state.toJS() : state,
        actionTransformer: action => (action.payload && action.payload.toJS) ? action.payload.toJS() : action
      }),
      sagaMiddleware
    ),
    typeof window === 'object' && typeof window.devToolsExtension !== 'undefined' ? window.devToolsExtension() : f => f
  ));
  sagaMiddleware.run(rootSaga);
  return store;
};
Example #17
0
export default function configureStore(history, initialState) {
  const sagaMiddleware = createSagaMiddleware();

  const middlewares = [
    sagaMiddleware,
    routerMiddleware(history),
  ];

  const store = createStore(
    rootReducer,
    applyMiddleware(...middlewares),
    initialState,
  );

  sagaMiddleware.run(rootSaga);

  return store;
}
export default function configureStore(initialState = {}) {
  const sagaMiddleware = createSagaMiddleware();

  const store = createStore(reducer, initialState, compose(
    applyMiddleware(sagaMiddleware),
    window.devToolsExtension ? window.devToolsExtension() : f => f
  ));

  sagaMiddleware.run(sagas);

  if (module.hot) {
    module.hot.accept('./modules/reducer', () => {
      store.replaceReducer(require('./modules/reducer')); // eslint-disable-line
    });
  }

  return store;
}
Example #19
0
export default function configureStore(preloadedState) {
  const sagaMiddleware = createSagaMiddleware()
  const store = createStore(
    rootReducer,
    preloadedState,
    compose(
      applyMiddleware(
        sagaMiddleware,
        logger()
      ),
      window.devToolsExtension ? window.devToolsExtension() : f => f
    )
  )

  sagaMiddleware.run(rootSaga)

  return store
}
export default function configureStore(initialState)
{
	
	const store = createStore(
		RootReducer,
		initialState,
		compose(
			ElectronReduxCommEnhancer({
				windowName: 'main',
				debug: {
					enabled            : true,
					numOfActionsToStore: 20,
				},
				subscribeTo: [{
					windowName: 'window1',
					stateFilter: {
						App: {
							Counters: {
								itemsIds: {
									'[FILTER]': true,
									editPath  : '=/windows/window1/CounterItems',
									selectRoot: ['Counters'],
									selectKeys: ['counterIds', ['counters', 0]],
									filterKeys: {
										id   : true,
										count: true,
										name : true,
									}
								}
							},
						}

					},
				},
				]
			}),
			applyMiddleware(createSagaMiddleware(...RootSaga), thunk),
			DevTools.instrument()
		)
	);
	

	return store;
}
Example #21
0
document.addEventListener('DOMContentLoaded', () => {
    const store = createStore(
        redux,
        applyMiddleware(
            createSagaMiddleware(...sagas)
        )
    );

    ReactDOM.render(
        <div className={style.applicationWrapper}>
            <h1>Redux Saga Demo</h1>

            <Provider store={store}>
                <Game />
            </Provider>
        </div>,
        document.getElementById('appContainer')
    );
});
Example #22
0
// a function which can create our store and auto-persist the data
export default () => {
  const store = createStore(
    rootReducer,
    applyMiddleware(
      logger,
      sagaMiddleware(...sagas)
    ),
    (Config.reduxPersist) ? autoRehydrate() : null
  )

  if (Config.reduxPersist) {
    persistStore(store, {
      storage: AsyncStorage,
      blacklist: persistentStoreBlacklist
    })
  }

  return store
}
export default function configureStore(rootReducer, initialState) {
    let enhancers = [
        applyMiddleware(
            createSagaMiddleware(sagas),
            routerMiddleware(hashHistory),
            thunkMiddleware
        ),
    ];

    if (FRONTEND__APP__ENABLE_DEV_TOOLS) { // eslint-disable-line no-undef
        const DevTools = require('./DevTools');
        enhancers = [
            ...enhancers,
            DevTools.instrument(),
        ];
    }

    return createStore(rootReducer, initialState, compose(...enhancers));
}
Example #24
0
export default function configureStore(initialState, history) {
  const sagaMiddleware = createSagaMiddleware();

  const middleware = applyMiddleware(sagaMiddleware, routerMiddleware(history));

  const composedStoreEnhancer = compose(middleware, reduxDevTool());

  const store = composedStoreEnhancer(createStore)(rootReducer, initialState);

  sagaMiddleware.run(sagas);

  if (module.hot) {
    module.hot.accept('./rootReducers', () => {
      store.replaceReducer(require('./rootReducers'));
    });
  }

  return store;
}
Example #25
0
test('should return error stack if primitive is thrown', t => {
  const actual = []
  const middleware = sagaMiddleware({
    onError(error, { sagaStack }) {
      actual.push(error, sagaStack)
    },
  })

  createStore(() => ({}), {}, applyMiddleware(middleware))

  middleware
    .run(primitiveErrorSaga)
    .toPromise()
    .catch((/* error */) => {
      const expected = ['error reason', 'The above error occurred in task primitiveErrorSaga  src/sagas/index.js?83\n']
      t.deepEqual(actual, expected)
      t.end()
    })
})
Example #26
0
const configureStore = (initialState = {}, initialEntries = []) => {
  const router = connectRoutes(routesMap, {
    ...routerOptions,
    initialDispatch: false,
    initialEntries,
  })
  const sagaMiddleware = createSagaMiddleware({
    onError:
      process.env.NODE_ENV == 'production'
        ? e => Raven.captureException(e)
        : console.error,
  })
  const warez = [sagaMiddleware, router.middleware]
  // if (process.env.NODE_ENV == 'development') warez.push(logger)

  const middlewares = compose(
    router.enhancer,
    applyMiddleware(...warez),
  )
  const rootReducer = combineReducers({ [SLICE]: router.reducer, ...reducers })
  const store = createStore(rootReducer, initialState, middlewares)
  let sagaTask = sagaMiddleware.run(rootSaga)
  router.initialDispatch() // dispatch first route after saga is started.
  if (module.hot) {
    module.hot.accept('./reducer.js', () => {
      const reducers = require('./reducer.js').default
      const newReducer = combineReducers({
        [SLICE]: router.reducer,
        ...reducers,
      })
      store.replaceReducer(newReducer)
    })
    // Hot module replacement for saga
    module.hot.accept('./saga.js', () => {
      sagaTask.cancel() // stop old saga
      sagaTask.done.then(() => {
        sagaTask = sagaMiddleware.run(require('./saga.js').default)
      })
    })
  }
  return store
}
Example #27
0
// a function which can create our store and auto-persist the data
export default () => {
  // create the saga middleware
  const sagaMonitor = process.env.NODE_ENV !== 'production'
    ? console.tron.createSagaMonitor()
    : null
  const sagaMiddleware = createSagaMiddleware({ sagaMonitor })

  // add our normal middleware to the list
  const middleware = applyMiddleware(logger, sagaMiddleware)

  // create the store with a root reducer & a composed list of enhancers
  const store = process.env.NODE_ENV === 'production'
    ? createStore(rootReducer, middleware)
    : console.tron.createStore(rootReducer, middleware)

  // kick off the root saga
  sagaMiddleware.run(rootSaga)

  return store
}
Example #28
0
export default ({
    authProvider,
    customReducers = {},
    customSagas = [],
    dataProvider,
    i18nProvider = defaultI18nProvider,
    history,
    initialState,
    locale = 'en',
}) => {
    const messages = i18nProvider(locale);
    const appReducer = createAppReducer(customReducers, locale, messages);

    const resettableAppReducer = (state, action) =>
        appReducer(action.type !== USER_LOGOUT ? state : undefined, action);
    const saga = function* rootSaga() {
        yield all(
            [
                adminSaga(dataProvider, authProvider, i18nProvider),
                ...customSagas,
            ].map(fork)
        );
    };
    const sagaMiddleware = createSagaMiddleware();
    const store = createStore(
        resettableAppReducer,
        initialState,
        compose(
            applyMiddleware(
                sagaMiddleware,
                formMiddleware,
                routerMiddleware(history)
            ),
            typeof window !== 'undefined' && window.devToolsExtension
                ? window.devToolsExtension()
                : f => f
        )
    );
    sagaMiddleware.run(saga);
    return store;
};
Example #29
0
function configureStore(browserHist) {
  console.log("configuring store")
  const loggerMiddleware = createLogger({
    level: 'info',
    collapsed: true
  });

  const sagaMiddleware = createSagaMiddleware()

  const reduxRouterMiddleware = routerMiddleware(browserHist);

  const redux_dev_tool = window.devToolsExtension ? window.devToolsExtension() : f => f

  const enhancer = compose(
      applyMiddleware(reduxRouterMiddleware, sagaMiddleware, loggerMiddleware),
      redux_dev_tool
    )

  return {store: createStore(reducers, enhancer), sagaMiddleware: sagaMiddleware };

}
Example #30
0
export default function configureStore(initialState) {
  let middlewares = [];

  if (process.env.NODE_ENV !== 'production') {
    const logger = require('redux-logger').default;
    middlewares.push(logger);
  }

  const sagaMiddleware = createSagaMiddleware();
  middlewares.push(sagaMiddleware);

  const store = createStore(
    reducer,
    initialState,
    applyMiddleware(...middlewares)
  );

  sagaMiddleware.run(rootSaga);

  return store;
}