How to use redux-logic - 10 common examples

To help you get started, we’ve selected a few redux-logic 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 popcodeorg / popcode / src / createApplicationStore.js View on Github external
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 sagaEnhancer = applyMiddleware(sagaMiddleware);

  const logicMiddleware = createLogicMiddleware(rootLogic);
  const logicEnhancer = applyMiddleware(logicMiddleware);

  const store = createStore(reducers, compose(sagaEnhancer, logicEnhancer));
  sagaMiddleware.run(rootSaga);

  return store;
}
github jeffbski / redux-logic / examples / single-file-redux / src / index.js View on Github external
console.error(err); // might be a render err
        dispatch({
          type: USERS_FETCH_REJECTED,
          payload: err,
          error: true
        });
      })
      .then(() => done()); // call done when finished dispatching
  }
});

const deps = { // injected dependencies for logic
  httpClient: axios
};
const arrLogic = [usersFetchLogic];
const logicMiddleware = createLogicMiddleware(arrLogic, deps);
const store = createStore(reducer, initialState,
                          applyMiddleware(logicMiddleware));

const containerDiv = document.getElementById('container');
store.subscribe(() => {
  const state = store.getState();
  console.log('state fetchStatus:%o list:%o', state.fetchStatus, state.list);
  containerDiv.innerHTML += formatStateForHTML(state);
});

function formatStateForHTML(state) {
  return (
  `<div>
     <div>State at: ${Date.now()}</div>
     <div>fetchStatus: ${state.fetchStatus}</div>
     <ul></ul></div>
github jeffbski / redux-logic / examples / notification / src / notify / logic.js View on Github external
import { createLogic } from 'redux-logic';

import { NOTIFY_CREATE, NOTIFY_REMOVE, NOTIFY_QUEUE,
         NOTIFY_DISPLAY_QUEUED,
         notifyQueue, notifyRemove, notifyDisplayQueued
       } from './actions';

import { selectors as notifySel } from './reducer';

export const MAX_DISPLAY = 3;
export const DISPLAY_TIME = 3000;

export const notifyCreateLogic = createLogic({
  type: NOTIFY_CREATE,

  // check to see if we can add directly
  validate({ getState, action }, allow, reject) {
    const state = getState();
    const current = notifySel.messages(state);
    const queue = notifySel.queue(state);
    if (current.length &lt; MAX_DISPLAY &amp;&amp; !queue.length) {
      allow(action);
    } else {
      reject(notifyQueue(action.payload));
    }
  },

  // if we had added directly then schedule remove
  process({ action }, dispatch, done) {
github jaganathanb / vilaippattiyal / src / app / store / configureStore.dev.js View on Github external
import rootReducer from '../reducers';
import rootActions from '../actions';

import logic from '../logics';

import api from '../../db';

const history = createHashHistory();

const deps = {
  // injected dependencies for logic
  Db: api.Db
};

const logicMiddleware = createLogicMiddleware(logic, deps);

const configureStore = initialState => {
  // Redux Configuration
  const middleware = [];
  const enhancers = [];

  // Thunk Middleware
  middleware.push(logicMiddleware);

  // Logging Middleware
  const logger = createLogger({
    level: 'info',
    collapsed: true
  });

  // Skip redux logs in console during the tests
github jeffbski / redux-logic / examples / async-rxjs-ajax-proc-options / src / configureStore.js View on Github external
import logic from './rootLogic';

import { ajax } from 'rxjs/ajax';

// selectively just getting ajax and map from rxjs to keep size smaller
// be sure to add everything you need in your logic
// import 'rxjs/Observable';
// import 'rxjs/add/operator/catch';
// import 'rxjs/add/operator/map';
// import { ajax } from 'rxjs/observable/dom/ajax';

const deps = { // injected dependencies for logic
  httpClient: ajax.getJSON // RxJS ajax
};

const logicMiddleware = createLogicMiddleware(logic, deps);

const middleware = applyMiddleware(
  logicMiddleware
);


// using compose to allow for applyMiddleware, just add it in
const enhancer = (typeof devToolsExtension !== 'undefined') ?
      compose(
        middleware,
        devToolsExtension()
      ) :
      middleware;

export default function configureStore() {
  const store = createStore(rootReducer, enhancer);
github jeffbski / redux-logic-test / examples / nodejs-basic / index.js View on Github external
const expect = require('expect');
const createMockStore = require('redux-logic-test').default.createMockStore;
const createLogic = require('redux-logic').default.createLogic;

const fooLogic = createLogic({
  type: 'FOO',
  process(deps, dispatch, done) {
    const API = deps.API;
    API.get()
       .then(results => {
         dispatch({ type: 'FOO_SUCCESS', payload: results });
         done();
       });
  }
});

const api = {
  get() { return Promise.resolve(42); }
};
github yatsu / react-tornado-graphql-example / src / ducks / todoPubSub.js View on Github external
return;
    }
    const sub = apolloClient.subscribe({ query: newTodosQuery }).subscribe({
      next(todo) {
        dispatch(todoReceived(todo));
      },
      error(err) {
        console.error('todo subscription error', err);
      }
    });
    subscriptions['todo'] = sub
    dispatch(subscribeTodosSucceeded(sub._networkSubscriptionId));
  }
});

export const todoUnsubscribeLogic = createLogic({
  type: UNSUBSCRIBE,
  latest: true,

  process({ apolloClient, subscriptions }, dispatch) {
    const sub = subscriptions['todo'];
    sub.unsubscribe();
    subscriptions['todo'] = null;
    dispatch(unsubscribeTodosSucceeded(sub._networkSubscriptionId));
  }
});

export const todoCreateLogic = createLogic({
  type: CREATE,

  processOptions: {
    dispatchReturn: true,
github jaganathanb / vilaippattiyal / src / app / features / shared / logic.js View on Github external
import { createLogic } from 'redux-logic';

import { LOGIN_CHECK, LOGOUT, LOGIN_SUCCESS, LOGIN_FAILURE } from './actions';

const logoutLogic = createLogic({
  type: LOGOUT,
  process({ action }, dispatch, done) {
    localStorage.removeItem('user');
    sessionStorage.removeItem('loggedIn');
    dispatch({
      type: LOGIN_CHECK
    });
    done();
  }
});

const loginCheckLogic = createLogic({
  type: LOGIN_CHECK,
  async process({ Db }, dispatch, done) {
    let user;
    try {
github Kaniwani / kw-frontend / app / features / quiz / QuizSession / QuizAnswer / logic.js View on Github external
if (!isValid) {
      dispatch(quiz.answer.update({ isMarked: true, isValid: false }));
    }

    if (isValid && !isDisabled) {
      dispatch(quiz.answer.check());
    }
    if (isValid && isDisabled) {
      dispatch(quiz.answer.confirm());
    }
    done();
  },
});

export const confirmAnswerLogic = createLogic({
  type: quiz.answer.confirm,
  latest: true,
  validate({ getState, action }, allow, reject) {
    const { value, isValid, isDisabled, isIgnored } = selectAnswer(getState());
    if (value && isValid && isDisabled && !isIgnored) {
      allow(action);
    } else {
      reject();
    }
  },
  process(_, dispatch, done) {
    dispatch(quiz.answer.record.request());
    done();
  },
});
github FreemapSlovakia / freemap-v3-react / src / logic / trackViewerLogic.js View on Github external
})
        .then(({ data }) => {
          dispatch(trackViewerSetTrackUID(data.uid));
        })
        .catch((e) => {
          dispatch(toastsAddError(`Nepodarilo sa nahrať súbor: ${e.message}`));
        })
        .then(() => {
          storeDispatch(stopProgress(pid));
          done();
        });
    }
  },
});

export const gpxLoadLogic = createLogic({
  type: 'GPX_LOAD',
  process({ getState }, dispatch, done) {
    const pid = Math.random();
    dispatch(startProgress(pid));

    axios.get(getState().trackViewer.gpxUrl, { validateStatus: status => status === 200 })
      .then(({ data }) => {
        dispatch(trackViewerSetData({ trackGpx: data }));
      })
      .catch((e) => {
        dispatch(toastsAddError(`Nastala chyba pri získavaní GPX záznamu: ${e.message}`));
      })
      .then(() => {
        dispatch(stopProgress(pid));
        done();
      });

redux-logic

Redux middleware for organizing all your business logic. Intercept actions and perform async processing.

MIT
Latest version published 1 year ago

Package Health Score

57 / 100
Full package analysis