@chief-editor/flow
Version:
Old核心数据流
1 lines • 930 B
JavaScript
export function extractEvents(e,n){var t={},r=n&&n.eventList||[];if(!r||!r.length)return t;var o={};return r.forEach((function(n){var t=n.eventType,r=n.eventFun,c=n.isStop,i=n.isPrevent,s=e.getHook(r);null!=s?(o[t]=o[t]||[],o[t].push({isStop:c,isPrevent:i,func:s})):console.error("invalid hook function name = "+r)})),Object.keys(o).forEach((function(n){t[n]=wrapEventFunc(o[n],e)})),t}function wrapEventFunc(e,n){return function(t,r){var o=!1,c=!1,i=e.map((function(e){e.isPrevent&&!o&&(o=!0,"string"!=typeof t&&t.preventDefault()),e.isStop&&!c&&(c=!0,"string"!=typeof t&&t.stopPropagation());try{var i=e.func.call(n,t,n,r);return null!=i&&"object"==typeof i&&"function"==typeof i.then?i:Promise.resolve()}catch(e){return Promise.reject(e.message)}}));Promise.all(i).then((function(){return Promise.resolve()})).catch((function(e){console.error("dispatch event error, name = "+("string"==typeof t?t:t.type)),console.error(e)}))}}