佐贺没有被召唤反应原生

时间:2018-04-30 12:21:09

标签: reactjs react-native redux-saga

我有这个saga-reducer-store代码,理论上应该在dispatch上触发一个传奇事件,但我发现根本没有动作。这段代码可以用于反应。

相关的SO问题是Redux saga - Worker saga not getting called on react native,但由于take*表单redux-saga已被弃用,解决方案已过时。

以下代码 -

  • App.js调用configureStore()返回商店并运行saga 中间件。
  • 存储调用rootSaga.js,返回所有传闻。
  • rootSaga.js调用loginSaga.js(userLogin)Saga

rootSaga.js

import { takeEvery } from "redux-saga/effects";
export function* rootSaga() {
    yield takeEvery(LoginSagaConstants.LOGIN, userLogin)
}

loginSaga.js

export function* userLogin(action) {
   console.log("userLogin not getting called");
   const response = yield call(LoginAPI.login, action.user);
   console.log(response);
   ...
}

loginScreen.js

console.log("start dispatching");
dispatch({
    type: sagaConstants.LOGIN,
    user: {
        username: "username",
        password: "password",
        robottest : "robottest"
    }
});

store.js

import {createStore, applyMiddleware, compose} from "redux";
import {createLogger} from 'redux-logger'
import createSagaMiddleware from 'redux-saga'
const initialState = {};

// import all Reducers
import {reducers} from "./reducers";

// import all Sagas
import { rootSaga } from "./sagas";

// define middlewares
let middlewares = [];

// create and add the saga middleware
const sagaMiddleware = createSagaMiddleware();
middlewares.push(sagaMiddleware);

//add the freeze and logger dev middleware
if (process.env.NODE_ENV !== 'production') {
    middlewares.push(createLogger());
}

// apply the middleware
let middleware = applyMiddleware(...middlewares);

const enhancer = compose(
    middleware
)

export default function configureStore() {
    const store = createStore(reducers, initialState, enhancer);
    // run saga middleware
    sagaMiddleware.run(rootSaga);
    return store;
}

App.js

...
import configureStore from './store'
const store = configureStore();
...
render() {
     return (
         <Provider store={store}>
             <RootStack/>
         </Provider>
    );
}

我的控制台只打印start dispatching,没有其他事情发生。

0 个答案:

没有答案