UNPKG

@chief-editor/flow

Version:

Old核心数据流

1 lines 1.03 kB
"use strict";function extractEvents(e,t){var n={},r=t&&t.eventList||[];if(!r||!r.length)return n;var o={};return r.forEach((function(t){var n=t.eventType,r=t.eventFun,c=t.isStop,s=t.isPrevent,i=e.getHook(r);null!=i?(o[n]=o[n]||[],o[n].push({isStop:c,isPrevent:s,func:i})):console.error("invalid hook function name = "+r)})),Object.keys(o).forEach((function(t){n[t]=wrapEventFunc(o[t],e)})),n}function wrapEventFunc(e,t){return function(n,r){var o=!1,c=!1,s=e.map((function(e){e.isPrevent&&!o&&(o=!0,"string"!=typeof n&&n.preventDefault()),e.isStop&&!c&&(c=!0,"string"!=typeof n&&n.stopPropagation());try{var s=e.func.call(t,n,t,r);return null!=s&&"object"==typeof s&&"function"==typeof s.then?s:Promise.resolve()}catch(e){return Promise.reject(e.message)}}));Promise.all(s).then((function(){return Promise.resolve()})).catch((function(e){console.error("dispatch event error, name = "+("string"==typeof n?n:n.type)),console.error(e)}))}}Object.defineProperty(exports,"__esModule",{value:!0}),exports.extractEvents=extractEvents;