Lazy $apollo

This commit is contained in:
Guillaume Chau
2016-09-27 11:44:45 +02:00
parent ffcd308993
commit bc6c73b146
2 changed files with 12 additions and 4 deletions
+1 -1
View File
@@ -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": {
+11 -3
View File
@@ -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;
}
}