@@ -1757,15 +1757,7 @@ var index = {
17571757 if ( data ) {
17581758 for ( var _key in data ) {
17591759 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 ] ) ;
17691761 }
17701762 }
17711763 }
@@ -1896,52 +1888,55 @@ var index = {
18961888 $addMeteorData : function $addMeteorData ( key , func ) {
18971889 var _this4 = this ;
18981890
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.' ) ;
19081895 }
19091896
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+ }
19131900
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+ } ) ;
19151908
19161909 // Function run
1917- var run = function run ( params ) {
1918- var result = func ( params ) ;
1910+ var setResult = function setResult ( result ) {
19191911 if ( result && typeof result . fetch === 'function' ) {
19201912 result = result . fetch ( ) ;
19211913 }
19221914 if ( Vue . config . meteor . freeze ) {
19231915 result = Object . freeze ( result ) ;
19241916 }
1925- setData ( result ) ;
1917+ set$1 ( _this4 . $data . $meteor . data , key , result ) ;
19261918 } ;
19271919
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+
19281926 // 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+ } ) ;
19301932 var unautorun = function unautorun ( ) {
19311933 if ( computation ) _this4 . $stopHandle ( computation ) ;
19321934 } ;
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 ( ) ;
19381938 } ;
19391939
1940- // Vue autorun
1941- var unwatch = this . $watch ( autorun , noop , {
1942- immediate : true
1943- } ) ;
1944-
19451940 return function ( ) {
19461941 unwatch ( ) ;
19471942 unautorun ( ) ;
0 commit comments