@@ -1518,7 +1518,7 @@ var CMeteorData = {
1518
1518
1519
1519
render : function render ( h ) {
1520
1520
var result = this . $scopedSlots . default ( {
1521
- data : this . meteorData
1521
+ data : this . $data . $meteor . data . meteorData
1522
1522
} ) ;
1523
1523
if ( Array . isArray ( result ) ) {
1524
1524
result = result . concat ( this . $slots . default ) ;
@@ -1707,11 +1707,11 @@ var index = {
1707
1707
if ( ! toVal ) return fromVal ;
1708
1708
if ( ! fromVal ) return toVal ;
1709
1709
1710
- var toData = Object . assign ( { } , lodash_omit ( toVal , [ 'subscribe' , 'data '] ) , toVal . data ) ;
1711
- var fromData = Object . assign ( { } , lodash_omit ( fromVal , [ 'subscribe' , 'data '] ) , fromVal . data ) ;
1710
+ var toData = Object . assign ( { } , lodash_omit ( toVal , [ '$ subscribe' ] ) , toVal . data ) ;
1711
+ var fromData = Object . assign ( { } , lodash_omit ( fromVal , [ '$ subscribe' ] ) , fromVal . data ) ;
1712
1712
1713
1713
return Object . assign ( {
1714
- subscribe : merge ( toVal . subscribe , fromVal . subscribe )
1714
+ $ subscribe : merge ( toVal . $ subscribe, fromVal . $ subscribe)
1715
1715
} , merge ( toData , fromData ) ) ;
1716
1716
} ;
1717
1717
@@ -1725,16 +1725,56 @@ var index = {
1725
1725
return result ;
1726
1726
}
1727
1727
1728
- function prepare ( ) {
1728
+ function firstPrepare ( ) {
1729
1729
var _this = this ;
1730
1730
1731
+ prepare . call ( this ) ;
1732
+ Object . defineProperty ( this , '$subReady' , {
1733
+ get : function get$$1 ( ) {
1734
+ return _this . $data . $meteor . subs ;
1735
+ } ,
1736
+ enumerable : true ,
1737
+ configurable : true
1738
+ } ) ;
1739
+ proxyData . call ( this ) ;
1740
+ }
1741
+
1742
+ function prepare ( ) {
1731
1743
this . _trackerHandles = [ ] ;
1732
1744
this . _subsAutorun = { } ;
1733
1745
this . _subs = { } ;
1746
+ }
1734
1747
1735
- Object . defineProperty ( this , '$subReady' , {
1748
+ function proxyData ( ) {
1749
+ var initData = this . $_meteorInitData = { } ;
1750
+ var meteor = this . $options . meteor ;
1751
+
1752
+ if ( meteor ) {
1753
+ // Reactive data
1754
+ for ( var key in meteor ) {
1755
+ if ( key . charAt ( 0 ) !== '$' ) {
1756
+ proxyKey . call ( this , key ) ;
1757
+
1758
+ var func = meteor [ key ] ;
1759
+
1760
+ if ( meteor . $lazy && typeof func === 'function' ) {
1761
+ initData [ key ] = getResult ( func . call ( this ) ) ;
1762
+ }
1763
+ }
1764
+ }
1765
+ }
1766
+ }
1767
+
1768
+ function proxyKey ( key ) {
1769
+ var _this2 = this ;
1770
+
1771
+ if ( hasProperty ( this , key ) ) {
1772
+ throw Error ( 'Meteor data \'' + key + '\': Property already used in the component methods or prototype.' ) ;
1773
+ }
1774
+
1775
+ Object . defineProperty ( this , key , {
1736
1776
get : function get$$1 ( ) {
1737
- return _this . $data . $meteor . subs ;
1777
+ return _this2 . $data . $meteor . data [ key ] ;
1738
1778
} ,
1739
1779
enumerable : true ,
1740
1780
configurable : true
@@ -1774,15 +1814,15 @@ var index = {
1774
1814
data : function data ( ) {
1775
1815
return {
1776
1816
$meteor : {
1777
- data : { } ,
1817
+ data : this . $_meteorInitData ,
1778
1818
subs : { }
1779
1819
}
1780
1820
} ;
1781
1821
}
1782
1822
} , vueVersion === '1' ? {
1783
- init : prepare
1823
+ init : firstPrepare
1784
1824
} : { } , vueVersion === '2' ? {
1785
- beforeCreate : prepare
1825
+ beforeCreate : firstPrepare
1786
1826
} : { } , {
1787
1827
created : function created ( ) {
1788
1828
if ( this . $options . meteor && ! this . $options . meteor . $lazy ) {
@@ -1805,7 +1845,7 @@ var index = {
1805
1845
1806
1846
methods : {
1807
1847
$_subscribe : function $_subscribe ( ) {
1808
- var _this2 = this ;
1848
+ var _this3 = this ;
1809
1849
1810
1850
for ( var _len = arguments . length , args = Array ( _len ) , _key2 = 0 ; _key2 < _len ; _key2 ++ ) {
1811
1851
args [ _key2 ] = arguments [ _key2 ] ;
@@ -1826,10 +1866,10 @@ var index = {
1826
1866
}
1827
1867
var autorun = this . $autorun ( function ( ) {
1828
1868
var ready = handle . ready ( ) ;
1829
- set$1 ( _this2 . $data . $meteor . subs , key , ready ) ;
1869
+ set$1 ( _this3 . $data . $meteor . subs , key , ready ) ;
1830
1870
// Wait for the new subscription to be ready before stoping the old one
1831
1871
if ( ready && oldSub ) {
1832
- _this2 . $stopHandle ( oldSub ) ;
1872
+ _this3 . $stopHandle ( oldSub ) ;
1833
1873
}
1834
1874
} ) ;
1835
1875
this . _subsAutorun [ key ] = autorun ;
@@ -1842,12 +1882,12 @@ var index = {
1842
1882
}
1843
1883
} ,
1844
1884
$subscribe : function $subscribe ( key , options ) {
1845
- var _this3 = this ;
1885
+ var _this4 = this ;
1846
1886
1847
1887
var handle = void 0 ,
1848
1888
unwatch = void 0 ;
1849
1889
var subscribe = function subscribe ( params ) {
1850
- handle = _this3 . $_subscribe . apply ( _this3 , [ key ] . concat ( toConsumableArray ( params ) ) ) ;
1890
+ handle = _this4 . $_subscribe . apply ( _this4 , [ key ] . concat ( toConsumableArray ( params ) ) ) ;
1851
1891
} ;
1852
1892
1853
1893
if ( typeof options === 'function' ) {
@@ -1866,7 +1906,7 @@ var index = {
1866
1906
1867
1907
return function ( ) {
1868
1908
if ( unwatch ) unwatch ( ) ;
1869
- if ( handle ) _this3 . $stopHandle ( handle ) ;
1909
+ if ( handle ) _this4 . $stopHandle ( handle ) ;
1870
1910
} ;
1871
1911
} ,
1872
1912
$autorun : function $autorun ( reactiveFunction ) {
@@ -1883,6 +1923,7 @@ var index = {
1883
1923
} ,
1884
1924
$startMeteor : function $startMeteor ( ) {
1885
1925
if ( ! this . _meteorActive ) {
1926
+ prepare . call ( this ) ;
1886
1927
launch . call ( this ) ;
1887
1928
}
1888
1929
} ,
@@ -1892,37 +1933,35 @@ var index = {
1892
1933
try {
1893
1934
tracker . stop ( ) ;
1894
1935
} catch ( e ) {
1895
- console . error ( e , tracker ) ;
1936
+ if ( Meteor . isDevelopment ) console . error ( e , tracker ) ;
1896
1937
}
1897
1938
} ) ;
1898
1939
this . _trackerHandles = null ;
1899
1940
this . _meteorActive = false ;
1900
1941
} ,
1901
1942
$addMeteorData : function $addMeteorData ( key , func ) {
1902
- var _this4 = this ;
1943
+ var _this5 = this ;
1944
+
1945
+ var proxy = arguments . length > 2 && arguments [ 2 ] !== undefined ? arguments [ 2 ] : false ;
1903
1946
1904
1947
if ( typeof func === 'function' ) {
1905
1948
func = func . bind ( this ) ;
1906
1949
} else {
1907
1950
throw Error ( 'Meteor data \'' + key + '\': You must provide a function which returns the result.' ) ;
1908
1951
}
1909
1952
1910
- if ( hasProperty ( this . $data , key ) || hasProperty ( this . $props , key ) || hasProperty ( this , key ) ) {
1911
- throw Error ( 'Meteor data \'' + key + '\': Property already used in the component data, props or other.' ) ;
1912
- }
1953
+ if ( proxy ) {
1954
+ if ( hasProperty ( this . $data , key ) || hasProperty ( this . $props , key ) ) {
1955
+ throw Error ( 'Meteor data \'' + key + '\': Property already used in the component data or props.' ) ;
1956
+ }
1913
1957
1914
- Object . defineProperty ( this , key , {
1915
- get : function get$$1 ( ) {
1916
- return _this4 . $data . $meteor . data [ key ] ;
1917
- } ,
1918
- enumerable : true ,
1919
- configurable : true
1920
- } ) ;
1958
+ proxyKey . call ( this , key ) ;
1959
+ }
1921
1960
1922
1961
// Function run
1923
1962
var setResult = function setResult ( result ) {
1924
1963
result = getResult ( result ) ;
1925
- set$1 ( _this4 . $data . $meteor . data , key , result ) ;
1964
+ set$1 ( _this5 . $data . $meteor . data , key , result ) ;
1926
1965
} ;
1927
1966
1928
1967
// Vue autorun
@@ -1938,7 +1977,7 @@ var index = {
1938
1977
setResult ( result ) ;
1939
1978
} ) ;
1940
1979
var unautorun = function unautorun ( ) {
1941
- if ( computation ) _this4 . $stopHandle ( computation ) ;
1980
+ if ( computation ) _this5 . $stopHandle ( computation ) ;
1942
1981
} ;
1943
1982
// Update from Vue (override)
1944
1983
watcher . update = function ( ) {
@@ -1951,8 +1990,9 @@ var index = {
1951
1990
} ;
1952
1991
} ,
1953
1992
$addComputed : function $addComputed ( key , watcher ) {
1954
- var _this5 = this ;
1993
+ var _this6 = this ;
1955
1994
1995
+ if ( watcher . getter . vuex ) return ;
1956
1996
var computation = void 0 ,
1957
1997
autorunMethod = void 0 ;
1958
1998
var autorun = function autorun ( cb ) {
@@ -1961,10 +2001,66 @@ var index = {
1961
2001
var dirty = false ;
1962
2002
computation = autorunMethod ( function ( computation ) {
1963
2003
dirty = true ;
1964
- watcher . value = getResult ( cb . call ( _this5 ) ) ;
1965
- watcher . deps . forEach ( function ( dep ) {
1966
- return dep . notify ( ) ;
1967
- } ) ;
2004
+ watcher . value = getResult ( cb . call ( _this6 ) ) ;
2005
+ // Call watcher callback
2006
+ var get$$1 = watcher . get ;
2007
+ watcher . get = function ( ) {
2008
+ return watcher . value ;
2009
+ } ;
2010
+ watcher . run ( ) ;
2011
+ watcher . get = get$$1 ;
2012
+ // Notify watchers subscribed in dependencies
2013
+ var _iteratorNormalCompletion = true ;
2014
+ var _didIteratorError = false ;
2015
+ var _iteratorError = undefined ;
2016
+
2017
+ try {
2018
+ for ( var _iterator = watcher . deps [ Symbol . iterator ] ( ) , _step ; ! ( _iteratorNormalCompletion = ( _step = _iterator . next ( ) ) . done ) ; _iteratorNormalCompletion = true ) {
2019
+ var dep = _step . value ;
2020
+
2021
+ var subs = dep . subs . slice ( ) ;
2022
+ var _iteratorNormalCompletion2 = true ;
2023
+ var _didIteratorError2 = false ;
2024
+ var _iteratorError2 = undefined ;
2025
+
2026
+ try {
2027
+ for ( var _iterator2 = subs [ Symbol . iterator ] ( ) , _step2 ; ! ( _iteratorNormalCompletion2 = ( _step2 = _iterator2 . next ( ) ) . done ) ; _iteratorNormalCompletion2 = true ) {
2028
+ var sub = _step2 . value ;
2029
+
2030
+ if ( sub . id !== watcher . id ) {
2031
+ sub . update ( ) ;
2032
+ }
2033
+ }
2034
+ } catch ( err ) {
2035
+ _didIteratorError2 = true ;
2036
+ _iteratorError2 = err ;
2037
+ } finally {
2038
+ try {
2039
+ if ( ! _iteratorNormalCompletion2 && _iterator2 . return ) {
2040
+ _iterator2 . return ( ) ;
2041
+ }
2042
+ } finally {
2043
+ if ( _didIteratorError2 ) {
2044
+ throw _iteratorError2 ;
2045
+ }
2046
+ }
2047
+ }
2048
+ }
2049
+ } catch ( err ) {
2050
+ _didIteratorError = true ;
2051
+ _iteratorError = err ;
2052
+ } finally {
2053
+ try {
2054
+ if ( ! _iteratorNormalCompletion && _iterator . return ) {
2055
+ _iterator . return ( ) ;
2056
+ }
2057
+ } finally {
2058
+ if ( _didIteratorError ) {
2059
+ throw _iteratorError ;
2060
+ }
2061
+ }
2062
+ }
2063
+
1968
2064
dirty = false ;
1969
2065
} ) ;
1970
2066
// Update from Vue (override)
@@ -1977,14 +2073,20 @@ var index = {
1977
2073
return watcher . value ;
1978
2074
} ;
1979
2075
// Override getter to expose $autorun
1980
- var func = watcher . getter ;
2076
+ var getter = watcher . getter ;
1981
2077
watcher . getter = function ( ) {
1982
- autorunMethod = _this5 . $autorun ;
1983
- _this5 . $autorun = autorun ;
1984
- var result = func . call ( _this5 , _this5 ) ;
1985
- _this5 . $autorun = autorunMethod ;
2078
+ autorunMethod = _this6 . $autorun ;
2079
+ _this6 . $autorun = autorun ;
2080
+ var result = getter . call ( _this6 , _this6 ) ;
2081
+ _this6 . $autorun = autorunMethod ;
1986
2082
return result ;
1987
2083
} ;
2084
+ // If watcher was created before the computed property
2085
+ // (for example because of a $watch)
2086
+ // we update the result with the getter override
2087
+ if ( watcher . value instanceof Tracker . Computation ) {
2088
+ watcher . run ( ) ;
2089
+ }
1988
2090
}
1989
2091
}
1990
2092
} ) ) ;
0 commit comments