@@ -1757,15 +1757,7 @@ var index = {
1757
1757
if ( data ) {
1758
1758
for ( var _key in data ) {
1759
1759
if ( _key . charAt ( 0 ) !== '$' ) {
1760
- var _options = data [ _key ] ;
1761
- var func = void 0 ;
1762
- if ( typeof _options === 'function' ) {
1763
- func = _options . bind ( this ) ;
1764
- } else {
1765
- throw Error ( 'Meteor data \'' + _key + '\': You must provide a function which returns the result.' ) ;
1766
- }
1767
-
1768
- this . $addMeteorData ( _key , func ) ;
1760
+ this . $addMeteorData ( _key , data [ _key ] ) ;
1769
1761
}
1770
1762
}
1771
1763
}
@@ -1896,52 +1888,55 @@ var index = {
1896
1888
$addMeteorData : function $addMeteorData ( key , func ) {
1897
1889
var _this4 = this ;
1898
1890
1899
- var hasDataField = hasProperty ( this . $data , key ) ;
1900
- if ( ! hasDataField && ! hasProperty ( this , key ) && ! hasProperty ( this . $props , key ) ) {
1901
- Object . defineProperty ( this , key , {
1902
- get : function get$$1 ( ) {
1903
- return _this4 . $data . $meteor . data [ key ] ;
1904
- } ,
1905
- enumerable : true ,
1906
- configurable : true
1907
- } ) ;
1891
+ if ( typeof func === 'function' ) {
1892
+ func = func . bind ( this ) ;
1893
+ } else {
1894
+ throw Error ( 'Meteor data \'' + key + '\': You must provide a function which returns the result.' ) ;
1908
1895
}
1909
1896
1910
- var setData = function setData ( value ) {
1911
- set$1 ( hasDataField ? _this4 . $ data : _this4 . $ data. $meteor . data , key , value ) ;
1912
- } ;
1897
+ if ( hasProperty ( this . $data , key ) || hasProperty ( this . $props , key ) || hasProperty ( this , key ) ) {
1898
+ throw Error ( 'Meteor data \'' + key + '\': Property already used in the component data, props or other.' ) ;
1899
+ }
1913
1900
1914
- setData ( null ) ;
1901
+ Object . defineProperty ( this , key , {
1902
+ get : function get$$1 ( ) {
1903
+ return _this4 . $data . $meteor . data [ key ] ;
1904
+ } ,
1905
+ enumerable : true ,
1906
+ configurable : true
1907
+ } ) ;
1915
1908
1916
1909
// Function run
1917
- var run = function run ( params ) {
1918
- var result = func ( params ) ;
1910
+ var setResult = function setResult ( result ) {
1919
1911
if ( result && typeof result . fetch === 'function' ) {
1920
1912
result = result . fetch ( ) ;
1921
1913
}
1922
1914
if ( Vue . config . meteor . freeze ) {
1923
1915
result = Object . freeze ( result ) ;
1924
1916
}
1925
- setData ( result ) ;
1917
+ set$1 ( _this4 . $data . $meteor . data , key , result ) ;
1926
1918
} ;
1927
1919
1920
+ // Vue autorun
1921
+ var unwatch = this . $watch ( func , noop ) ;
1922
+ var watcher = this . _watchers . find ( function ( w ) {
1923
+ return w . getter === func ;
1924
+ } ) ;
1925
+
1928
1926
// Meteor autorun
1929
- var computation = void 0 ;
1927
+ var computation = this . $autorun ( function ( ) {
1928
+ // Vue watcher deps are also-rebuilt
1929
+ var result = watcher . get ( ) ;
1930
+ setResult ( result ) ;
1931
+ } ) ;
1930
1932
var unautorun = function unautorun ( ) {
1931
1933
if ( computation ) _this4 . $stopHandle ( computation ) ;
1932
1934
} ;
1933
- var autorun = function autorun ( ) {
1934
- unautorun ( ) ;
1935
- computation = _this4 . $autorun ( function ( ) {
1936
- run ( ) ;
1937
- } ) ;
1935
+ // Update from Vue (override)
1936
+ watcher . update = function ( ) {
1937
+ computation . invalidate ( ) ;
1938
1938
} ;
1939
1939
1940
- // Vue autorun
1941
- var unwatch = this . $watch ( autorun , noop , {
1942
- immediate : true
1943
- } ) ;
1944
-
1945
1940
return function ( ) {
1946
1941
unwatch ( ) ;
1947
1942
unautorun ( ) ;
0 commit comments