gpt4 book ai didi

javascript - 为什么传奇效应没有被调用?

转载 作者:行者123 更新时间:2023-12-01 01:15:05 25 4
gpt4 key购买 nike

我正在尝试在我的应用程序上添加多个 Action 效果。但我想我错过了一些东西。效果函数没有被调用。我希望命名有问题吗?理想情况下 yield all([ 这应该可以解决问题,对吧?帮我想想办法。

action.js

import {
DEFAULT_ACTION,
POST_ADMIN_LOGIN_REQUEST,
POST_ADMIN_LOGIN_REQUEST_SUCCESS,
POST_ADMIN_LOGIN_REQUEST_ERROR,
POST_ADMIN_USER_DETAILS,
} from './constants';

import { setCookie } from '../../utils/helpers';

...... //rest of my actions

export function postAdminUserDetails(token) {
console.log(token);
// I see token in the console
return {
type: POST_ADMIN_USER_DETAILS,
token,
};
}

常量.js

export const POST_ADMIN_USER_DETAILS = 'app/AdminLogin/POST_ADMIN_USER_DETAILS';

saga.js

import { takeLatest, call, put, all } from 'redux-saga/effects';
import request from 'utils/request';

import { POST_ADMIN_LOGIN_REQUEST, POST_ADMIN_USER_DETAILS } from './constants';

console.log(POST_ADMIN_USER_DETAILS)

import {
postAdminLoginRequestSuccess,
postAdminLoginRequestError,
} from './actions';

export function* triggerLogin({ params }) {
const requestURL = new URL(`${API}/login`);

...... //rest of the logis, which is working
}

export function* triggerGetUser({ token }) {
const requestURL = new URL(`${API}/profile`);

console.log('callllled');
// this is not even getting called :(
}

export default function* defaultSaga() {
console.log('POST_ADMIN_USER_DETAILS')
yield all([
takeLatest(POST_ADMIN_LOGIN_REQUEST, triggerLogin),
takeLatest(POST_ADMIN_USER_DETAILS, triggerGetUser),
]);
}

reducer .js

import { fromJS } from 'immutable';
import {
DEFAULT_ACTION,
POST_ADMIN_LOGIN_REQUEST,
POST_ADMIN_LOGIN_REQUEST_SUCCESS,
POST_ADMIN_LOGIN_REQUEST_ERROR,
POST_ADMIN_USER_DETAILS,
} from './constants';

export const initialState = fromJS({
isLogin: false,
hasError: false,
loginResponse: null,
});

function adminLoginReducer(state = initialState, action) {
switch (action.type) {
case DEFAULT_ACTION:
return state;
case POST_ADMIN_LOGIN_REQUEST:
return state
.set('isLogin', true)
.set('hasError', false)
.set('errorMessage', null)
.set('loginResponse', null);
case POST_ADMIN_LOGIN_REQUEST_SUCCESS:
return state
.set('isLogin', false)
.set('hasError', false)
.set('loginResponse', action.response);
case POST_ADMIN_LOGIN_REQUEST_ERROR:
return state
.set('isLogin', false)
.set('hasError', true)
.set('errorMessage', action.errorMessage);
case POST_ADMIN_USER_DETAILS:
return state;
default:
return state;
}
}

export default adminLoginReducer;

最佳答案

我也遇到过同样的问题,通过更改文件夹路径解决了它。因此,请尝试相同的操作,或者尝试将 saga 文件保留在与组件文件相同的文件夹级别。

关于javascript - 为什么传奇效应没有被调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54835561/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com