chore(refactor): simplify init() code using "for of"

pull/980/head
shfshanyue 4 years ago
parent 27e9c4d5dc
commit b8529337e8

@ -61,8 +61,6 @@ const hooks: Array<keyof Module> = [
]; ];
export function init(modules: Array<Partial<Module>>, domApi?: DOMAPI) { export function init(modules: Array<Partial<Module>>, domApi?: DOMAPI) {
let i: number;
let j: number;
const cbs: ModuleHooks = { const cbs: ModuleHooks = {
create: [], create: [],
update: [], update: [],
@ -74,12 +72,11 @@ export function init(modules: Array<Partial<Module>>, domApi?: DOMAPI) {
const api: DOMAPI = domApi !== undefined ? domApi : htmlDomApi; const api: DOMAPI = domApi !== undefined ? domApi : htmlDomApi;
for (i = 0; i < hooks.length; ++i) { for (const hook of hooks) {
cbs[hooks[i]] = []; for (const module of modules) {
for (j = 0; j < modules.length; ++j) { const currentHook = module[hook];
const hook = modules[j][hooks[i]]; if (currentHook !== undefined) {
if (hook !== undefined) { (cbs[hook] as any[]).push(currentHook);
(cbs[hooks[i]] as any[]).push(hook);
} }
} }
} }

Loading…
Cancel
Save