redux-saga-sugar
v0.3.1
Published
redux-saga utilities.
Downloads
26
Readme
redux-saga-sugar
redux-saga utilities.
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 }));
}