From b8529337e83565833ac09e0d11c4f2e7f2c8d7d2 Mon Sep 17 00:00:00 2001 From: shfshanyue Date: Fri, 20 Aug 2021 13:33:14 +0800 Subject: [PATCH] chore(refactor): simplify init() code using "for of" --- src/init.ts | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/init.ts b/src/init.ts index 8483072..4500eba 100644 --- a/src/init.ts +++ b/src/init.ts @@ -61,8 +61,6 @@ const hooks: Array = [ ]; export function init(modules: Array>, domApi?: DOMAPI) { - let i: number; - let j: number; const cbs: ModuleHooks = { create: [], update: [], @@ -74,12 +72,11 @@ export function init(modules: Array>, domApi?: DOMAPI) { const api: DOMAPI = domApi !== undefined ? domApi : htmlDomApi; - for (i = 0; i < hooks.length; ++i) { - cbs[hooks[i]] = []; - for (j = 0; j < modules.length; ++j) { - const hook = modules[j][hooks[i]]; - if (hook !== undefined) { - (cbs[hooks[i]] as any[]).push(hook); + for (const hook of hooks) { + for (const module of modules) { + const currentHook = module[hook]; + if (currentHook !== undefined) { + (cbs[hook] as any[]).push(currentHook); } } }