prevent calling init multi times

This commit is contained in:
Pooya Parsa 2017-06-14 21:03:04 +04:30
parent 36c1deda17
commit 17d0082861
2 changed files with 9 additions and 5 deletions

View File

@ -49,7 +49,10 @@ export default class Builder extends Tapable {
this._init = this.init().catch(this.nuxt.errorHandler)
} else {
// Wait for hook
this.nuxt.plugin('init', this.init.bind(this))
this.nuxt.plugin('init', () => {
this._init = this.init()
return this._init
})
}
}

View File

@ -28,17 +28,18 @@ export default class Renderer extends Tapable {
this.nuxt = nuxt
this.options = nuxt.options
// Will be loaded by createRenderer
// Will be set by createRenderer
this.bundleRenderer = null
this.renderToStream = null
this.renderToString = null
if (nuxt.initialized) {
// If nuxt already initialized
this._init = this.init().catch(this.nuxt.errorHandler)
} else {
// Wait for hook
this.nuxt.plugin('init', this.init.bind(this))
this.nuxt.plugin('init', () => {
this._init = this.init()
return this._init
})
}
}