Skip to content

Commit

Permalink
fix: better group optional functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
pimlie committed Feb 28, 2019
1 parent 139a2d1 commit 42580c9
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions lib/module.js
Expand Up @@ -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) {
Expand All @@ -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++
Expand All @@ -65,10 +69,6 @@ export default function nuxtMemwatch(options = {}) {
})
}

if (options.graph) {
this.nuxt.hook('render:routeDone', () => (requestCounter++))
}

start(options)
})
}

0 comments on commit 42580c9

Please sign in to comment.