From bc6c73b146d8ca42d2a13b58643b335e37831809 Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Tue, 27 Sep 2016 11:44:45 +0200 Subject: [PATCH] Lazy $apollo --- package.json | 2 +- src/vue-plugin.js | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index d7ceaac..ae5285d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vue-apollo", - "version": "1.0.0-beta11", + "version": "1.0.0-beta.12", "description": "Vue apollo integration", "main": "index.js", "scripts": { diff --git a/src/vue-plugin.js b/src/vue-plugin.js index 842caaf..fc8b35d 100644 --- a/src/vue-plugin.js +++ b/src/vue-plugin.js @@ -159,7 +159,15 @@ class DollarApollo { function prepare() { this._apolloSubscriptions = []; - this.$apollo = new DollarApollo(this); + // Lazy creation + Object.defineProperty(this, '$apollo', { + get: () => { + if(!this._apollo) { + this._apollo = new DollarApollo(this); + } + return this._apollo; + } + }); } function launch() { @@ -201,8 +209,8 @@ module.exports = { sub.unsubscribe(); }); this._apolloSubscriptions = null; - if (this.$apollo) { - this.$apollo = null; + if (this._apollo) { + this._apollo = null; } }