From 8b4498c911e24ef7a46daf66380f1c122f988af3 Mon Sep 17 00:00:00 2001 From: Mariusz Nowak Date: Fri, 17 Sep 2021 12:21:13 +0200 Subject: [PATCH] refactor: Simplify lifecycle event hooks resolution --- lib/classes/PluginManager.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/classes/PluginManager.js b/lib/classes/PluginManager.js index e9d09ae96a9..ceb7ed91c1f 100644 --- a/lib/classes/PluginManager.js +++ b/lib/classes/PluginManager.js @@ -554,9 +554,11 @@ class PluginManager { return this.plugins; } - getHooks(events) { - const eventsArray = [].concat(events); - return eventsArray.reduce((acc, event) => acc.concat(this.hooks[event] || []), []); + getHooks(lifecycleEventNames) { + if (!Array.isArray(lifecycleEventNames)) lifecycleEventNames = [lifecycleEventNames]; + return _.flatten( + lifecycleEventNames.map((lifecycleEventName) => this.hooks[lifecycleEventName] || []) + ); } async invoke(commandsArray, allowEntryPoints) {