Javascript 响应未调用的函数

Javascript 响应未调用的函数,javascript,reactjs,react-native,redux,redux-saga,Javascript,Reactjs,React Native,Redux,Redux Saga,我一直在开发一个react原生项目,我正在尝试调用redux saga函数。它没有被调用(我没有收到任何错误) 这是我的组件,我在其中调用了登录操作 ... <TouchableOpacity style={{ backgroundColor: '#4368b2', borderColor: '#3464c8', borderRadius: 5 }} onPress={login(this.props.email,this.props.pass

我一直在开发一个react原生项目,我正在尝试调用redux saga函数。它没有被调用(我没有收到任何错误)

这是我的组件,我在其中调用了登录操作

...
<TouchableOpacity 
  style={{ 
    backgroundColor: '#4368b2', 
    borderColor: '#3464c8', 
    borderRadius: 5 
  }}
  onPress={login(this.props.email,this.props.password)}> //call login action
  <Text style={commonStyle.buttonText}>{this.props.type}</Text>
</TouchableOpacity>
    ...
这是我的rootSaga.js

import { all, fork } from 'redux-saga/effects';
import { loginFlow } from './AuthSagas';

export default function* rootSaga() {
  yield fork(loginFlow);
}
这是AuthSagas.js。应用程序启动时,启动loginFlow功能的console.log正在工作

import { put, call, take } from 'redux-saga/effects';
import { takeEvery } from 'redux-saga';
import auth from './../auth';
import { LOGIN_ACTION } from './../action/types';
import { setLoginSuccess, setLoginError } from './../action';

function* authorize(credentials) {
  try {
    const token = yield call(auth.login(credentials));
    console.log(token);
    if (!token.error) {
      yield put(setLoginSuccess(token, credentials.username, credentials.password));
      return token;
    }
    yield put(setLoginError(token));
    return undefined;
  } catch (error) {
    console.log(error);
    return undefined;
  }
}

export function* loginFlow() {
  console.log('saga-alert'); 
  const { username, password } = yield take(LOGIN_ACTION);
  yield call(authorize, { username, password });
}
上面是我的代码。我的应用程序正在运行,但没有错误。但这部传奇并没有被称为传奇。单击touchableopacity时。

rootSaga.js:

import { all } from 'redux-saga/effects';
import { loginFlow } from './AuthSagas';

export default function* rootSaga() {
  yield all([
    loginFlow(),
  ]);
}

你的减速器在哪里?没有用于登录操作的减速器。你是否尝试过使用takeLatest而不是
fork
fork
在传奇需要启动非阻塞任务时很有用是的。不工作。
import { all, fork } from 'redux-saga/effects';
import { loginFlow } from './AuthSagas';

export default function* rootSaga() {
  yield fork(loginFlow);
}
import { put, call, take } from 'redux-saga/effects';
import { takeEvery } from 'redux-saga';
import auth from './../auth';
import { LOGIN_ACTION } from './../action/types';
import { setLoginSuccess, setLoginError } from './../action';

function* authorize(credentials) {
  try {
    const token = yield call(auth.login(credentials));
    console.log(token);
    if (!token.error) {
      yield put(setLoginSuccess(token, credentials.username, credentials.password));
      return token;
    }
    yield put(setLoginError(token));
    return undefined;
  } catch (error) {
    console.log(error);
    return undefined;
  }
}

export function* loginFlow() {
  console.log('saga-alert'); 
  const { username, password } = yield take(LOGIN_ACTION);
  yield call(authorize, { username, password });
}
import { all } from 'redux-saga/effects';
import { loginFlow } from './AuthSagas';

export default function* rootSaga() {
  yield all([
    loginFlow(),
  ]);
}