Состояние Redux не обновляется. Проблема.Но излишне логгер показывает правильное действие и следующее обновление состояния - PullRequest
0 голосов
/ 22 февраля 2019

Я использую Redux для своего веб-приложения.Состояние должно быть обновлено после входа пользователя.Redux logger используется для отладки.Все в редуксе логгер, но состояние не обновляется.Пожалуйста, дайте представление об этой проблеме.

Редукторы:

import { adminConstants } from '../Admin/admin.constants.js';

export function adminReducers(state={},action)
{
  switch (action.type) {
    case adminConstants.ADMIN_LOGIN_REQUEST:
      return {
        loggingIn: true,
        };
    case adminConstants.ADMIN_LOGIN_SUCCESS:
      return {
          loggedIn: true,
          admin:action.admin
      };
    case adminConstants.ADMIN_LOGIN_FAILURE:
      return {};
    case adminConstants.ADMIN_LOGOUT:
      return {};
    default:
      return state;
    }
}

CombineReducers:

const rootReducer = combineReducers({
  authentication,
  registration,
  users,
  alert,
  adminReducers
});

export default rootReducer;

mapStateToProps: (в этом файле console.log отображается пустым для всех объектов)

function mapStateToProps(state) {
    console.log("state "+ JSON.stringify(state));

    const {  adminReducers } = state;
    const { admin } = adminReducers;
    return {
           admin
    };
}
const connectedAdminPanel = connect(mapStateToProps)(AdminPanel);
export { connectedAdminPanel as AdminPanel };

Доступ к состоянию после страницы входа, но для adminReducers отображается пустым:

enter image description here

Регистратор Redux: (показать, что adminReducers в состоянии обновлен)

enter image description here

     action AD_LOGIN_REQUEST @ 07:43:40.601
redux-logger.js:400  prev state {authentication: {…}, registration: {…}, users: {…}, alert: {…}, adminReducers: {…}}adminReducers: {}__proto__: Objectalert: {}authentication: {}registration: {}users: {}__proto__: Object
redux-logger.js:404  action     {type: "AD_LOGIN_REQUEST", admin: {…}}admin: {adminname: "iamadmin"}adminname: "iamadmin"__proto__: Objecttype: "AD_LOGIN_REQUEST"__proto__: Object
redux-logger.js:413  next state {authentication: {…}, registration: {…}, users: {…}, alert: {…}, adminReducers: {…}}adminReducers: {loggingIn: true}loggingIn: true__proto__: Objectalert: {}authentication: {}registration: {}users: {}__proto__: Object
Admin.js:36 Log store {"authentication":{},"registration":{},"users":{},"alert":{},"adminReducers":{"loggingIn":true}}
admin.service.js:25 200
redux-logger.js:389  action AD_LOGIN_SUCCESS @ 07:43:40.645
redux-logger.js:400  prev state {authentication: {…}, registration: {…}, users: {…}, alert: {…}, adminReducers: {…}}adminReducers: {loggingIn: true}loggingIn: true__proto__: Objectalert: {}authentication: {}registration: {}users: {}__proto__: Object
redux-logger.js:404  action     {type: "AD_LOGIN_SUCCESS", admin: {…}}admin: {_id: "5c68451200801fc955188527", aname: "iamadmin", password: "removed", hash: "$2a$10$rDvt9fKK8mfymbKREdtILO6SneFQBllD9r/5xBHX.ynrt0Vt0u5.6", token: "removed"}type: "AD_LOGIN_SUCCESS"__proto__: Object
redux-logger.js:413  next state 
...