From 42580c99004b8c64dca76a69ce07bd93a3762ea5 Mon Sep 17 00:00:00 2001 From: pimlie Date: Thu, 28 Feb 2019 19:21:03 +0100 Subject: [PATCH] fix: better group optional functionality --- lib/module.js | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/module.js b/lib/module.js index 582340c..6856fd0 100644 --- a/lib/module.js +++ b/lib/module.js @@ -26,9 +26,6 @@ export default function nuxtMemwatch(options = {}) { return } - let requestCounter = 0 - let gcRequestCounter = 0 - options = setOptions(this.options.memwatch || options) if (options.autoHeapDiff && !this.options.dev) { @@ -39,21 +36,28 @@ export default function nuxtMemwatch(options = {}) { options.groupName = 'nuxt-memwatch' options.gcAfterEvery = options.gcAfterEvery || 0 - options.graphSetup.push((graphSetup) => { - graphSetup.metrics.requests = { - min: 0, - aggregator: 'avg', - color: 'magenta,bold' - } - }) + if (options.graph) { + let requestCounter = 0 - options.graphAddMetric.push((turtle, stats) => { - turtle.metric(options.groupName, 'requests').push(requestCounter) - requestCounter = 0 - }) + options.graphSetup.push((graphSetup) => { + graphSetup.metrics.requests = { + min: 0, + aggregator: 'avg', + color: 'magenta,bold' + } + }) + + options.graphAddMetric.push((turtle, stats) => { + turtle.metric(options.groupName, 'requests').push(requestCounter) + requestCounter = 0 + }) + + this.nuxt.hook('render:routeDone', () => (requestCounter++)) + } if (options.gcAfterEvery) { const memwatch = await getMemwatch() + let gcRequestCounter = 0 this.nuxt.hook('render:routeDone', () => { gcRequestCounter++ @@ -65,10 +69,6 @@ export default function nuxtMemwatch(options = {}) { }) } - if (options.graph) { - this.nuxt.hook('render:routeDone', () => (requestCounter++)) - } - start(options) }) }