2016-09-29 50 views
2

我试图在减速器中做到这一点;为什么我在React Redux Reducer中收到有关合成事件的警告?

case actions.DATA_RETURNED: 
    newState = Object.assign({}, state); 
    newState.status = 'complete'; 
    if (resp) { 
    var newItems = newState.items.map(item => { 
     var newItem = Object.assign({}, item); 
     var match = _.find(resp, { id: item._id }); 
     newItem._rev = match.rev; 
     return newItem; 
    }); 
    } 
    break; 

我试过几种变化,他们都失败了;

warning.js:36 Warning: This synthetic event is reused for performance reasons. If you're seeing this, you're accessing the property cancelable on a released/nullified synthetic event. This is set to null. If you must keep the original synthetic event around, use event.persist(). See https://facebook.github.io/react/docs/events.html#event-pooling for more information. 

除非我除去newItem._rev = match.rev或设置match是一个硬编码的字符串。所以看起来问题在于试图在Array.map里使用lodash的find,但我不明白为什么这是一个问题。我并没有自觉地对事件做任何事情,所以我很难找到解决方案。

编辑:如果它是相关的,这里是我如何派遣的行动;

return syncChangedItemsToDB(itemsChanged).then((resp) => { 
    dispatch({type: actions.DATA_RETURNED, resp}); 
}); 

有没有人知道是什么原因导致了这个警告,我该如何解决它?

+0

这是关于反应事件,您的代码中没有可见的事件。你可以在哪里发布你的动作? – Maxx

+0

我更新了我的问题,并告诉我如何调度该操作。原来我得到了我的代码工作。我会在下面添加一个答案,但我仍在寻找更多解释。 –

回答

1

如果我使用Object.assign复制lodash的find的结果,事情似乎没有问题,所以这段代码工作。我仍然不确定为什么这是必要的,所以任何解释将不胜感激。

newItems = newState.items.map(item => { 
    var match = Object.assign({}, _.find(resp, { id: item._id })); 
    if (match.rev) item._rev = match.rev; 
    return item; 
}); 
相关问题