我如何转换此箭头功能?

问题描述 投票:0回答:2

我不知道如何将此箭头功能转换为IE兼容功能。如果有人可以提供解决方案,我非常感谢:

const store = window.WebChat.createStore({}, ({ dispatch }) => next => async action => {
                        if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
                            // Mocking data to be sent
                            const userId = 'xyz789';
                            const payloadUserContext = action.payload;

                            action = window.simpleUpdateIn(
                                action,
                                ['payload', 'activity', 'channelData'],
                                () => ({
                                    'personId': userId,
                                    'domain': $.urlParam('d'),
                                    'environment': window.location.host,
                                    'userContext': payloadUserContext
                                })
                            )
                        }
                        return next(action);
                    });
javascript
2个回答
0
投票

只需使用https://babeljs.io/

var store = window.WebChat.createStore({}, function (_ref) {
      var dispatch = _ref.dispatch;
      return function (next) {
        return async function (action) {
          if (action.type === 'DIRECT_LINE/POST_ACTIVITY') {
            // Mocking data to be sent
            var userId = 'xyz789';
            var payloadUserContext = action.payload;
            action = window.simpleUpdateIn(action, ['payload', 'activity', 'channelData'], function () {
              return {
                'personId': userId,
                'domain': $.urlParam('d'),
                'environment': window.location.host,
                'userContext': payloadUserContext
              };
            });
          }

          return next(action);
        };
      };
    });

0
投票

您可以使用此在线babel转译器https://babeljs.io/repl(使用转译器将代码从一个版本转换为另一个版本,在这种情况下,我们要从es6转换为es5)。

您可以在https://www.w3schools.com/js/js_versions.asp中检查ES浏览器的支持>


编辑:

在网上闲逛,我发现babel会产生您可能不想使用的结果(至少对于使用async / await定义的功能而言)。

[您可以做的是使用babel进行转换,而将剩下的异步/等待方式更改为.then和.catch。

例如,

const someAsyncRequest = () => new Promise((resolve) => {
  setTimeout(() => {
    resolve("Responding")
  }, 1000)
})

const myAsyncFunction = async () => {
  console.log("Making request")
  const result = await someAsyncRequest()
  console.log(result)
  console.log("Done!")
}

function myIE9AsyncFunction() {
  console.log("Making request")
  someAsyncRequest()
    .then(function (result) {
      console.log(result)
      console.log("Done!")
    })
    .catch(function (error) {
      console.log("What the... ", error)
    })
}

myAsyncFunction()
myIE9AsyncFunction()
© www.soinside.com 2019 - 2024. All rights reserved.