Skip to content

Commit 64da0c1

Browse files
author
Guillaume Chau
committed
chore: v2.0.0-beta.3
1 parent 5bbc3db commit 64da0c1

File tree

4 files changed

+184
-96
lines changed

4 files changed

+184
-96
lines changed

dist/vue-meteor-tracker.esm.js

Lines changed: 91 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,7 @@ var CMeteorSub = {
16541654
var parameters = typeof this.parameters === 'function' ? this.parameters : function () {
16551655
return _this.parameters || [];
16561656
};
1657-
this.$_unsub = this.$addReactiveSub(this.name, parameters);
1657+
this.$_unsub = this.$subscribe(this.name, parameters);
16581658
}
16591659
},
16601660

@@ -1715,6 +1715,16 @@ var index = {
17151715
}, merge(toData, fromData));
17161716
};
17171717

1718+
function getResult(result) {
1719+
if (result && typeof result.fetch === 'function') {
1720+
result = result.fetch();
1721+
}
1722+
if (Vue.config.meteor.freeze) {
1723+
result = Object.freeze(result);
1724+
}
1725+
return result;
1726+
}
1727+
17181728
function prepare() {
17191729
var _this = this;
17201730

@@ -1744,21 +1754,16 @@ var index = {
17441754

17451755
if (!isServer || ssr) {
17461756
// Subscriptions
1747-
if (meteor.subscribe || meteor.$subscribe) {
1748-
var subscribeOptions = Object.assign({}, meteor.subscribe, meteor.$subscribe);
1749-
for (var key in subscribeOptions) {
1750-
this.$addReactiveSub(key, subscribeOptions[key]);
1757+
if (meteor.$subscribe) {
1758+
for (var key in meteor.$subscribe) {
1759+
this.$subscribe(key, meteor.$subscribe[key]);
17511760
}
17521761
}
17531762

1754-
var data = Object.assign({}, lodash_omit(meteor, ['subscribe', 'data']), meteor.data);
1755-
17561763
// Reactive data
1757-
if (data) {
1758-
for (var _key in data) {
1759-
if (_key.charAt(0) !== '$') {
1760-
this.$addMeteorData(_key, data[_key]);
1761-
}
1764+
for (var _key in meteor) {
1765+
if (_key.charAt(0) !== '$') {
1766+
this.$addMeteorData(_key, meteor[_key]);
17621767
}
17631768
}
17641769
}
@@ -1783,6 +1788,14 @@ var index = {
17831788
if (this.$options.meteor && !this.$options.meteor.$lazy) {
17841789
launch.call(this);
17851790
}
1791+
1792+
// Computed props
1793+
var computed = this._computedWatchers;
1794+
if (computed) {
1795+
for (var key in computed) {
1796+
this.$addComputed(key, computed[key]);
1797+
}
1798+
}
17861799
},
17871800

17881801

@@ -1791,7 +1804,7 @@ var index = {
17911804
},
17921805

17931806
methods: {
1794-
$subscribe: function $subscribe() {
1807+
$_subscribe: function $_subscribe() {
17951808
var _this2 = this;
17961809

17971810
for (var _len = arguments.length, args = Array(_len), _key2 = 0; _key2 < _len; _key2++) {
@@ -1828,6 +1841,34 @@ var index = {
18281841
throw new Error('You must provide the publication name to $subscribe.');
18291842
}
18301843
},
1844+
$subscribe: function $subscribe(key, options) {
1845+
var _this3 = this;
1846+
1847+
var handle = void 0,
1848+
unwatch = void 0;
1849+
var subscribe = function subscribe(params) {
1850+
handle = _this3.$_subscribe.apply(_this3, [key].concat(toConsumableArray(params)));
1851+
};
1852+
1853+
if (typeof options === 'function') {
1854+
if (isServer) {
1855+
subscribe(options.bind(this)());
1856+
} else {
1857+
unwatch = this.$watch(options, function (params) {
1858+
subscribe(params);
1859+
}, {
1860+
immediate: true
1861+
});
1862+
}
1863+
} else {
1864+
subscribe(options);
1865+
}
1866+
1867+
return function () {
1868+
if (unwatch) unwatch();
1869+
if (handle) _this3.$stopHandle(handle);
1870+
};
1871+
},
18311872
$autorun: function $autorun(reactiveFunction) {
18321873
var handle = Tracker.autorun(reactiveFunction);
18331874
this._trackerHandles.push(handle);
@@ -1857,34 +1898,6 @@ var index = {
18571898
this._trackerHandles = null;
18581899
this._meteorActive = false;
18591900
},
1860-
$addReactiveSub: function $addReactiveSub(key, options) {
1861-
var _this3 = this;
1862-
1863-
var handle = void 0,
1864-
unwatch = void 0;
1865-
var subscribe = function subscribe(params) {
1866-
handle = _this3.$subscribe.apply(_this3, [key].concat(toConsumableArray(params)));
1867-
};
1868-
1869-
if (typeof options === 'function') {
1870-
if (isServer) {
1871-
subscribe(options.bind(this)());
1872-
} else {
1873-
unwatch = this.$watch(options, function (params) {
1874-
subscribe(params);
1875-
}, {
1876-
immediate: true
1877-
});
1878-
}
1879-
} else {
1880-
subscribe(options);
1881-
}
1882-
1883-
return function () {
1884-
if (unwatch) unwatch();
1885-
if (handle) _this3.$stopHandle(handle);
1886-
};
1887-
},
18881901
$addMeteorData: function $addMeteorData(key, func) {
18891902
var _this4 = this;
18901903

@@ -1908,12 +1921,7 @@ var index = {
19081921

19091922
// Function run
19101923
var setResult = function setResult(result) {
1911-
if (result && typeof result.fetch === 'function') {
1912-
result = result.fetch();
1913-
}
1914-
if (Vue.config.meteor.freeze) {
1915-
result = Object.freeze(result);
1916-
}
1924+
result = getResult(result);
19171925
set$1(_this4.$data.$meteor.data, key, result);
19181926
};
19191927

@@ -1941,6 +1949,42 @@ var index = {
19411949
unwatch();
19421950
unautorun();
19431951
};
1952+
},
1953+
$addComputed: function $addComputed(key, watcher) {
1954+
var _this5 = this;
1955+
1956+
var computation = void 0,
1957+
autorunMethod = void 0;
1958+
var autorun = function autorun(cb) {
1959+
if (!computation) {
1960+
// Update from Meteor
1961+
var dirty = false;
1962+
computation = autorunMethod(function (computation) {
1963+
dirty = true;
1964+
watcher.value = getResult(cb.call(_this5));
1965+
watcher.deps.forEach(function (dep) {
1966+
return dep.notify();
1967+
});
1968+
dirty = false;
1969+
});
1970+
// Update from Vue (override)
1971+
watcher.update = function () {
1972+
if (!dirty) {
1973+
computation.invalidate();
1974+
}
1975+
};
1976+
}
1977+
return watcher.value;
1978+
};
1979+
// Override getter to expose $autorun
1980+
var func = watcher.getter;
1981+
watcher.getter = function () {
1982+
autorunMethod = _this5.$autorun;
1983+
_this5.$autorun = autorun;
1984+
var result = func.call(_this5, _this5);
1985+
_this5.$autorun = autorunMethod;
1986+
return result;
1987+
};
19441988
}
19451989
}
19461990
}));

0 commit comments

Comments
 (0)