@@ -1518,7 +1518,7 @@ var CMeteorData = {
15181518
15191519 render : function render ( h ) {
15201520 var result = this . $scopedSlots . default ( {
1521- data : this . meteorData
1521+ data : this . $data . $meteor . data . meteorData
15221522 } ) ;
15231523 if ( Array . isArray ( result ) ) {
15241524 result = result . concat ( this . $slots . default ) ;
@@ -1707,11 +1707,11 @@ var index = {
17071707 if ( ! toVal ) return fromVal ;
17081708 if ( ! fromVal ) return toVal ;
17091709
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 ) ;
17121712
17131713 return Object . assign ( {
1714- subscribe : merge ( toVal . subscribe , fromVal . subscribe )
1714+ $ subscribe : merge ( toVal . $ subscribe, fromVal . $ subscribe)
17151715 } , merge ( toData , fromData ) ) ;
17161716 } ;
17171717
@@ -1725,16 +1725,56 @@ var index = {
17251725 return result ;
17261726 }
17271727
1728- function prepare ( ) {
1728+ function firstPrepare ( ) {
17291729 var _this = this ;
17301730
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 ( ) {
17311743 this . _trackerHandles = [ ] ;
17321744 this . _subsAutorun = { } ;
17331745 this . _subs = { } ;
1746+ }
17341747
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 , {
17361776 get : function get$$1 ( ) {
1737- return _this . $data . $meteor . subs ;
1777+ return _this2 . $data . $meteor . data [ key ] ;
17381778 } ,
17391779 enumerable : true ,
17401780 configurable : true
@@ -1774,15 +1814,15 @@ var index = {
17741814 data : function data ( ) {
17751815 return {
17761816 $meteor : {
1777- data : { } ,
1817+ data : this . $_meteorInitData ,
17781818 subs : { }
17791819 }
17801820 } ;
17811821 }
17821822 } , vueVersion === '1' ? {
1783- init : prepare
1823+ init : firstPrepare
17841824 } : { } , vueVersion === '2' ? {
1785- beforeCreate : prepare
1825+ beforeCreate : firstPrepare
17861826 } : { } , {
17871827 created : function created ( ) {
17881828 if ( this . $options . meteor && ! this . $options . meteor . $lazy ) {
@@ -1805,7 +1845,7 @@ var index = {
18051845
18061846 methods : {
18071847 $_subscribe : function $_subscribe ( ) {
1808- var _this2 = this ;
1848+ var _this3 = this ;
18091849
18101850 for ( var _len = arguments . length , args = Array ( _len ) , _key2 = 0 ; _key2 < _len ; _key2 ++ ) {
18111851 args [ _key2 ] = arguments [ _key2 ] ;
@@ -1826,10 +1866,10 @@ var index = {
18261866 }
18271867 var autorun = this . $autorun ( function ( ) {
18281868 var ready = handle . ready ( ) ;
1829- set$1 ( _this2 . $data . $meteor . subs , key , ready ) ;
1869+ set$1 ( _this3 . $data . $meteor . subs , key , ready ) ;
18301870 // Wait for the new subscription to be ready before stoping the old one
18311871 if ( ready && oldSub ) {
1832- _this2 . $stopHandle ( oldSub ) ;
1872+ _this3 . $stopHandle ( oldSub ) ;
18331873 }
18341874 } ) ;
18351875 this . _subsAutorun [ key ] = autorun ;
@@ -1842,12 +1882,12 @@ var index = {
18421882 }
18431883 } ,
18441884 $subscribe : function $subscribe ( key , options ) {
1845- var _this3 = this ;
1885+ var _this4 = this ;
18461886
18471887 var handle = void 0 ,
18481888 unwatch = void 0 ;
18491889 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 ) ) ) ;
18511891 } ;
18521892
18531893 if ( typeof options === 'function' ) {
@@ -1866,7 +1906,7 @@ var index = {
18661906
18671907 return function ( ) {
18681908 if ( unwatch ) unwatch ( ) ;
1869- if ( handle ) _this3 . $stopHandle ( handle ) ;
1909+ if ( handle ) _this4 . $stopHandle ( handle ) ;
18701910 } ;
18711911 } ,
18721912 $autorun : function $autorun ( reactiveFunction ) {
@@ -1883,6 +1923,7 @@ var index = {
18831923 } ,
18841924 $startMeteor : function $startMeteor ( ) {
18851925 if ( ! this . _meteorActive ) {
1926+ prepare . call ( this ) ;
18861927 launch . call ( this ) ;
18871928 }
18881929 } ,
@@ -1892,37 +1933,35 @@ var index = {
18921933 try {
18931934 tracker . stop ( ) ;
18941935 } catch ( e ) {
1895- console . error ( e , tracker ) ;
1936+ if ( Meteor . isDevelopment ) console . error ( e , tracker ) ;
18961937 }
18971938 } ) ;
18981939 this . _trackerHandles = null ;
18991940 this . _meteorActive = false ;
19001941 } ,
19011942 $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 ;
19031946
19041947 if ( typeof func === 'function' ) {
19051948 func = func . bind ( this ) ;
19061949 } else {
19071950 throw Error ( 'Meteor data \'' + key + '\': You must provide a function which returns the result.' ) ;
19081951 }
19091952
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+ }
19131957
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+ }
19211960
19221961 // Function run
19231962 var setResult = function setResult ( result ) {
19241963 result = getResult ( result ) ;
1925- set$1 ( _this4 . $data . $meteor . data , key , result ) ;
1964+ set$1 ( _this5 . $data . $meteor . data , key , result ) ;
19261965 } ;
19271966
19281967 // Vue autorun
@@ -1938,7 +1977,7 @@ var index = {
19381977 setResult ( result ) ;
19391978 } ) ;
19401979 var unautorun = function unautorun ( ) {
1941- if ( computation ) _this4 . $stopHandle ( computation ) ;
1980+ if ( computation ) _this5 . $stopHandle ( computation ) ;
19421981 } ;
19431982 // Update from Vue (override)
19441983 watcher . update = function ( ) {
@@ -1951,8 +1990,9 @@ var index = {
19511990 } ;
19521991 } ,
19531992 $addComputed : function $addComputed ( key , watcher ) {
1954- var _this5 = this ;
1993+ var _this6 = this ;
19551994
1995+ if ( watcher . getter . vuex ) return ;
19561996 var computation = void 0 ,
19571997 autorunMethod = void 0 ;
19581998 var autorun = function autorun ( cb ) {
@@ -1961,10 +2001,66 @@ var index = {
19612001 var dirty = false ;
19622002 computation = autorunMethod ( function ( computation ) {
19632003 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+
19682064 dirty = false ;
19692065 } ) ;
19702066 // Update from Vue (override)
@@ -1977,14 +2073,20 @@ var index = {
19772073 return watcher . value ;
19782074 } ;
19792075 // Override getter to expose $autorun
1980- var func = watcher . getter ;
2076+ var getter = watcher . getter ;
19812077 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 ;
19862082 return result ;
19872083 } ;
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+ }
19882090 }
19892091 }
19902092 } ) ) ;
0 commit comments