Redux和x27的问题;s Store.dispatch不';我不能得到更新

Redux和x27的问题;s Store.dispatch不';我不能得到更新,redux,react-redux,Redux,React Redux,升级meteor(从1.4升级到1.7)和react(从15.3.2升级到16.8.6) 我发现我的代码无法使用store.dispatch()更新/存储,存储未更新 我的操作文件如下所示: actions/config.js ... export default { load({Meteor, Store}) { return new Promise((resolve, reject) => { Meteor.call('variables.load', null

升级meteor(从1.4升级到1.7)和react(从15.3.2升级到16.8.6)

我发现我的代码无法使用store.dispatch()更新/存储,存储未更新

我的操作文件如下所示:

actions/config.js

...
export default {
  load({Meteor, Store}) {
    return new Promise((resolve, reject) => {
      Meteor.call('variables.load', null, (err, data) => {
        if (err) {
          reject({_error: err.reason });
          return;
        }

console.log("************ Store (A) = "+JSON.stringify(Store.getState()))
        Store.dispatch({
          type: LOAD_CONFIG,
          data
        });

        resolve();
console.log("************ Store (B) = "+JSON.stringify(Store.getState()))
      });
    });
  },
...
// ------------------------------------
// Action Handlers
// ------------------------------------
const ACTION_HANDLERS = {
    [LOAD_CONFIG]: (state, action) => ({
      ...state,
      data: action.data
    })
};

// ------------------------------------
// Reducer
// ------------------------------------
const initialState = {
    data: null
};

export default function configReducer(state = initialState, action) {
console.log("************ Reducer")
    const handler = ACTION_HANDLERS[action.type];

    return handler ? handler(state, action) : state;
}
console.log()和console.log()都具有以下功能:

Store (A) = {"router":{"locationBeforeTransitions":{"pathname":"/settings/config","search":"","hash":"","action":"PUSH","key":"zif4ls","basename":"/crm","query":{}}},"form":{"config":{"syncErrors":{"reportLimit":"Required"}}},"loadingBar":{}}

Store (B) = {"router":{"locationBeforeTransitions":{"pathname":"/settings/config","search":"","hash":"","action":"PUSH","key":"zif4ls","basename":"/crm","query":{}}},"form":{"config":{"syncErrors":{"reportLimit":"Required"}}},"loadingBar":{}}
我确实希望它会有类似于
“reportLimit”:6的内容,它被确认已加载到
数据
变量中。相反,我在浏览器控制台中遇到以下错误:

Uncaught TypeError: Cannot read property 'data' of undefined
你能想到有什么错误/破坏性的变化吗?因为这些代码在升级之前一直有效


编辑:

我进一步缩小了问题的范围。可能是我的路线没有呼叫减速器

此后,我更改了路由中的代码,以消除使用require.sure的需要

routes.jsx(先前版本)

routes.jsx(最新版本,以摆脱
要求。确保

然后我注意到在减速器中:

reducer/config.js

...
export default {
  load({Meteor, Store}) {
    return new Promise((resolve, reject) => {
      Meteor.call('variables.load', null, (err, data) => {
        if (err) {
          reject({_error: err.reason });
          return;
        }

console.log("************ Store (A) = "+JSON.stringify(Store.getState()))
        Store.dispatch({
          type: LOAD_CONFIG,
          data
        });

        resolve();
console.log("************ Store (B) = "+JSON.stringify(Store.getState()))
      });
    });
  },
...
// ------------------------------------
// Action Handlers
// ------------------------------------
const ACTION_HANDLERS = {
    [LOAD_CONFIG]: (state, action) => ({
      ...state,
      data: action.data
    })
};

// ------------------------------------
// Reducer
// ------------------------------------
const initialState = {
    data: null
};

export default function configReducer(state = initialState, action) {
console.log("************ Reducer")
    const handler = ACTION_HANDLERS[action.type];

    return handler ? handler(state, action) : state;
}
根据记录,函数
configReducer
似乎没有在其他地方调用。

尝试以下操作:

 Store.dispatch({
      type: LOAD_CONFIG,
      data: data
 });
试试这个:

 Store.dispatch({
      type: LOAD_CONFIG,
      data: data
 });

经过多次尝试和错误,确认问题在于布线部分,最终更改:

routes.jsx(最终版)

要点: 1) 这就是如何从
require.确保
(由webpack使用)迁移到而不依赖webpack(这是我完全使用Meteor Atmosphere运行时的情况)
2) 
mod
require(…)。xxx
已更改为
mod.default
require(…)。如果
reducer
函数导出为
export default
,则不会调用所述的
reducer


我花了好几个星期才弄明白

经过多次尝试和错误,确认问题出在布线部分,最终更改:

routes.jsx(最终版)

要点: 1) 这就是如何从
require.确保
(由webpack使用)迁移到而不依赖webpack(这是我完全使用Meteor Atmosphere运行时的情况)
2) 
mod
require(…)。xxx
已更改为
mod.default
require(…)。如果
reducer
函数导出为
export default
,则不会调用所述的
reducer


我花了好几个星期才弄明白

你的加载函数是什么?我需要这方面的详细信息。Load函数没有问题,它正在调用服务器来访问来自MongoDB的数据,MongoDB已经返回到数据变量。(已通过日志进行测试)。创建承诺后,您是否检查了数据<代码>Meteor.call('variables.load',null,(err,data)=>{
在这一行之后,你的load func是什么?我需要这方面的详细信息。load函数没有问题,它正在调用服务器来访问MongoDB中的数据,MongoDB已经传回数据变量。(已通过日志测试)创建承诺后,您是否检查了数据?
Meteor.call('variables.load',null,(err,data)=>{
,在这一行之后
{
    path: 'config',
    getComponent(nextState, cb) {
        import('./containers/config').then(mod => {
            Store.injectReducer('config', require('./reducers/config').default);
            cb(null, mod.default);
        });
    }
}