From 8941cb61177a6c73006c7f7f9727dde758e01ac0 Mon Sep 17 00:00:00 2001 From: Bruce Johnson Date: Wed, 1 Sep 2021 09:46:54 -0700 Subject: [PATCH] use callback-hook package --- packages/webapp/package.js | 1 + packages/webapp/webapp_server.js | 16 +++++++--------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/webapp/package.js b/packages/webapp/package.js index 07d8deb0c4..6178ea386c 100644 --- a/packages/webapp/package.js +++ b/packages/webapp/package.js @@ -35,6 +35,7 @@ Package.onUse(function (api) { 'boilerplate-generator', 'webapp-hashing', 'inter-process-messaging', + 'callback-hook' ], 'server'); // At response serving time, webapp uses browser-policy if it is loaded. If diff --git a/packages/webapp/webapp_server.js b/packages/webapp/webapp_server.js index df91dbaa6a..69c3a34e6d 100644 --- a/packages/webapp/webapp_server.js +++ b/packages/webapp/webapp_server.js @@ -356,10 +356,10 @@ WebApp.decodeRuntimeConfig = function (rtimeConfig) { const runtimeConfig = { // hooks will contain the callback functions // set by the caller to addRuntimeConfigHook - hooks: [], + hooks: new Hook(), // updateHooks will contain the callback functions - // set by the caller to addUpdatedConfigHook - updateHooks: [], + // set by the caller to addUpdatedNotifyHook + updateHooks: new Hook(), // isUpdatedByArch is an object containing fields for each arch // that this server supports. // - Each field will be true when the server updates the runtimeConfig for that arch. @@ -372,13 +372,12 @@ WebApp.decodeRuntimeConfig = function (rtimeConfig) { }; WebApp.addRuntimeConfigHook = function (hook) { - if(typeof hook !== 'function') throw new Error('WebApp.addRuntimeConfigHook must be a function'); - runtimeConfig.hooks.push(hook); + return runtimeConfig.hooks.register(hook); } function getBoilerplateAsync(request, arch) { let boilerplate = boilerplateByArch[arch]; - runtimeConfig.hooks.forEach((hook) => { + runtimeConfig.hooks.each((hook) => { const meteorRuntimeConfig = hook({ arch, request, @@ -421,8 +420,7 @@ function getBoilerplateAsync(request, arch) { // - manifest // - runtimeConfig WebApp.addUpdatedNotifyHook = function(hook) { - if(typeof hook !== 'function') throw new Error('WebApp.addUpdatedNotifyHook must be a function'); - runtimeConfig.updateHooks.push(hook); + return runtimeConfig.updateHooks.register(hook); } WebAppInternals.generateBoilerplateInstance = function (arch, @@ -435,7 +433,7 @@ WebAppInternals.generateBoilerplateInstance = function (arch, ...__meteor_runtime_config__, ...(additionalOptions.runtimeConfigOverrides || {}) }; - runtimeConfig.updateHooks.forEach((cb) => { + runtimeConfig.updateHooks.each((cb) => { cb({arch, manifest, runtimeConfig: rtimeConfig}); });