Skip to content

jasonHzq/redux-saga-sugar

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redux-saga-sugar

redux-saga utilities.

npm version build status npm downloads

Getting started

Install

$ npm i -S redux-saga-sugar

Documentation

pollingSagaMiddleware

实时中间件

export function* rootSaga() {
  yield fork(Sugar.pollingSagaMiddleware);
}

const actions = Sugar.createActions({
  beginPolling: {
    pollingSUrl: Urlmap.polling,
    types: [load, pollingSuccess, failure],
  },
  stopPolling: {
    type: pollingSuccess,
    stopPolling: true,
  },
});

createActions / createAction

  • createAction(SWITCH_TAB)

function(payload) {
  return {
    type: SWITCH_TAB,
    payload
  };
}
  • createAction({ type: SWITCH_TAB })

function() {
  return {
    type: SWITCH_TAB,
  };
}
import Sugar from 'redux-saga-sugar';

export const actions = Sugar.createActions({
  loadBasicData: {
    url: getUrl('loadBasicData'),
    types: [LOAD_BASIC_DATA_LOAD, LOAD_BASIC_DATA_SUCCESS, LOAD_BASIC_DATA_FAILURE],
  },
  loadData: {
    url: getUrl('loadData'),
    types: [LOAD_DATA_LOAD, LOAD_DATA_SUCCESS, LOAD_DATA_FAILURE],
  },
  switchTab: SWITCH_TAB,
  beginLoad: BEGIN_LOAD,
});

createWatch

yield Sugar.createWatch(pattern, saga, ...args)

yield fork(function* () {
  yield takeEvery(pattern, saga, ...args);
});

例子:

export function saga() {
  yield Sugar.createWatch([SWITCH_TAB, BEGIN_LOAD], loadDataSaga);
}

get

yield Sugar.get(path);

yield select(state => {
  return _.get(state, path);
});

例子:

function* loadDataSaga() {
  const id = yield Sugar.get(`${currPath}.id`);
  yield put(actions.loadData({ id }));
}

License

MIT

About

redux-saga utilities

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published