我的客户要求我们的聊天机器人支持 IE11。我不得不修改网络聊天代码以不使用箭头函数等 es6 功能,因为 IE11/es5 不支持它们。在大多数情况下,我是成功的,但我无法开始工作的一件事是发送我正在发送的消息事件。新代码在 Chrome 中有效,但我在 IE11 中收到预期标识符错误消息。以下是相关代码:
const store = window.WebChat.createStore({}, function({dispatch}) { return function(next) { return function(action) {
if (action.type === 'WEB_CHAT/SEND_MESSAGE') {
// Message sent by the user
PageTitleNotification.Off();
clearTimeout(interval);
} else if (action.type === 'DIRECT_LINE/INCOMING_ACTIVITY' && action.payload.activity.name !== "inactive") {
// Message sent by the bot
clearInterval(interval);
interval = setTimeout(function() {
// Change title to flash the page
PageTitleNotification.On('Are you still there?');
// Notify bot the user has been inactive
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'inactive',
value: ''
}
});
}, 3000)
}
return next(action);
}}});
以前第一行看起来像
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
问题来了function({dispatch})
。IE 控制台说需要一个标识符并且整个网络聊天无法加载。它在 Chrome 中运行良好。如果我更改function({dispatch})
为 just function(dispatch)
,机器人会呈现,但发送非活动消息到机器人(如下)的调度语句不再在 IE或Chrome 中起作用。
// Notify bot the user has been inactive
dispatch({
type: 'WEB_CHAT/SEND_EVENT',
payload: {
name: 'inactive',
value: ''
}
});
为什么 IE 无法识别{dispatch}
为标识符,我该怎么做才能使其正常工作?