How to use the redux.applyMiddleware 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 rdrnt / tps-calls / src / js / store.js View on Github external
import { createStore, applyMiddleware } from 'redux';
import thunkMiddleware from 'redux-thunk';
import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly';

import rootReducer from './reducers';

// Store setup
const middleware = applyMiddleware(thunkMiddleware);

const store = createStore(rootReducer, {}, composeWithDevTools(middleware));

export default store;
github ealgis / ealgis / frontend / src / index.tsx View on Github external
//     const logger = createLogger({
//         level: "log", // log, console, warn, error, info
//         collapsed: true,
//         diff: true,
//     })
//     Middleware.push(logger)
// }

const ealapi = new EALGISApiClient()

const composeEnhancers = composeWithDevTools({
    // Specify name here, actionsBlacklist, actionsCreators and other options if needed
})
const store: Store = createStore(
    reducers,
    composeEnhancers(applyMiddleware(thunkMiddleware.withExtraArgument(ealapi), ...Middleware))
)

const history = syncHistoryWithStore(browserHistory as any, store)

ReactDOM.render(
    
         {}}>
            {getRoutes(store as any)}
        
    ,
    document.getElementById("ealgis")
)
github KCreate / leonardschuetz.ch / client / redux / store.js View on Github external
} from 'redux';
import rootReducer from './reducers/rootReducer';
import thunk from 'redux-thunk';

// Different middleware for production
let middleware = [thunk];
if (process.env.NODE_ENV !== 'production') {
    const logger = require('redux-logger');
    middleware = [
        ...middleware,
        // logger(),
    ];
}

const customCreateStore = compose(
    applyMiddleware(...middleware)
)(createStore);

// exports configureStore & initial state
export default function configureStore() {
    return customCreateStore(rootReducer, {
        sources: {},
    });
}
github jhewlett / redux-saga-combine-latest / test / index.js View on Github external
const spy = sinon.spy()
function* handleActions(actions) {
  spy(actions)
}

const combineLatest = createCombineLatest(effects)

function* saga() {
  yield combineLatest(['type1', 'type2'], handleActions)
}

const sagaMiddleware = createSagaMiddleware(saga)

const store = createStore(
  (state) => state,
  applyMiddleware(sagaMiddleware)
)

describe('combineLatest', () => {
  const action1 = { type: 'type1', some: 'payload' }
  const action2 = { type: 'type2', some: 'payload' }
  const action3 = { type: 'type2', other: 'payload' }

  describe('when only one action type has been dispatched', () => {
    it('should not yield saga yet', () => {
      store.dispatch(action1)
      expect(spy).not.to.be.called
    })
  })

  describe('when all action types have been dispatched', () => {
    it('should yield saga with all actions', () => {
github digidem / mapeo-mobile / src / store.js View on Github external
import { createStore, applyMiddleware, combineReducers } from 'redux'
import createLogger from 'redux-logger'

import catchErrors from './middleware/catch_errors'
import * as reducers from './reducers'

const reducer = combineReducers({
  routing: routeReducer,
  ...reducers})

const logger = createLogger()
let createStoreWithMiddleWare
if (process.env.NODE_ENV === 'development') {
  createStoreWithMiddleWare = applyMiddleware(logger)(createStore)
} else {
  createStoreWithMiddleWare = applyMiddleware(catchErrors)(createStore)
}
const store = createStoreWithMiddleWare(reducer)
syncReduxAndRouter(createBrowserHistory(), store)

export default store
github itsjeffro / deploy / resources / assets / js / app.js View on Github external
import React from 'react';
import { render } from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';

import './bootstrap';

import rootReducers from './state/rootReducers';
import Application from './Application';

if (document.getElementById('app')) {
  const store = createStore(
    rootReducers,
    applyMiddleware(thunk)
  );

  render(
    
      
    ,
    document.getElementById('app')
  )
}
github danielstern / flux-redux / src / message-board.js View on Github external
case CREATE_NEW_MESSAGE:
            const newState = [ { date: date, postedBy, content: value } , ... state ]
            return newState;
    }
    return state;
}

const combinedReducer = combineReducers({
    userStatus: userStatusReducer,
    messages: messageReducer,
    apiCommunicationStatus: apiCommunicationStatusReducer
})

const store = createStore(
    combinedReducer,
    applyMiddleware(logger())
);

const render = ()=>{
    const {messages, userStatus, apiCommunicationStatus} = store.getState();
    document.getElementById("messages").innerHTML = messages
        .sort((a,b)=>b.date - a.date)
        .map(message=>(`
    <div> 
        ${message.postedBy} : ${message.content}
    </div>`
    )).join("");

    document.forms.newMessage.newMessage.value = "";
    document.forms.newMessage.fields.disabled = (userStatus === OFFLINE) || (apiCommunicationStatus === WAITING);

}
github mathieudutour / kayero / src / js / app.js View on Github external
import 'whatwg-fetch'
import React from 'react'
import { render } from 'react-dom'
import { Provider } from 'react-redux'
import { createStore, compose, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
import bindStoreToMenu from './bindStoreToMenu'

import NotebookReducer from './reducers'
import Notebook from './Notebook'

require('../scss/main.scss')

const store = compose(
    applyMiddleware(thunk)
)(createStore)(NotebookReducer)

bindStoreToMenu(store)

render(
  
    <div>
      
    </div>
  ,
  document.getElementById('kayero')
)
github gempir / justlog / web / src / js / App.jsx View on Github external
constructor(props) {
		super(props);

		this.store = createStore(reducer, createInitialState(), applyMiddleware(thunk));
	}