@@ -1654,7 +1654,7 @@ var CMeteorSub = {
1654
1654
var parameters = typeof this . parameters === 'function' ? this . parameters : function ( ) {
1655
1655
return _this . parameters || [ ] ;
1656
1656
} ;
1657
- this . $_unsub = this . $addReactiveSub ( this . name , parameters ) ;
1657
+ this . $_unsub = this . $subscribe ( this . name , parameters ) ;
1658
1658
}
1659
1659
} ,
1660
1660
@@ -1715,6 +1715,16 @@ var index = {
1715
1715
} , merge ( toData , fromData ) ) ;
1716
1716
} ;
1717
1717
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
+
1718
1728
function prepare ( ) {
1719
1729
var _this = this ;
1720
1730
@@ -1744,21 +1754,16 @@ var index = {
1744
1754
1745
1755
if ( ! isServer || ssr ) {
1746
1756
// 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 ] ) ;
1751
1760
}
1752
1761
}
1753
1762
1754
- var data = Object . assign ( { } , lodash_omit ( meteor , [ 'subscribe' , 'data' ] ) , meteor . data ) ;
1755
-
1756
1763
// 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 ] ) ;
1762
1767
}
1763
1768
}
1764
1769
}
@@ -1783,6 +1788,14 @@ var index = {
1783
1788
if ( this . $options . meteor && ! this . $options . meteor . $lazy ) {
1784
1789
launch . call ( this ) ;
1785
1790
}
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
+ }
1786
1799
} ,
1787
1800
1788
1801
@@ -1791,7 +1804,7 @@ var index = {
1791
1804
} ,
1792
1805
1793
1806
methods : {
1794
- $subscribe : function $subscribe ( ) {
1807
+ $_subscribe : function $_subscribe ( ) {
1795
1808
var _this2 = this ;
1796
1809
1797
1810
for ( var _len = arguments . length , args = Array ( _len ) , _key2 = 0 ; _key2 < _len ; _key2 ++ ) {
@@ -1828,6 +1841,34 @@ var index = {
1828
1841
throw new Error ( 'You must provide the publication name to $subscribe.' ) ;
1829
1842
}
1830
1843
} ,
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
+ } ,
1831
1872
$autorun : function $autorun ( reactiveFunction ) {
1832
1873
var handle = Tracker . autorun ( reactiveFunction ) ;
1833
1874
this . _trackerHandles . push ( handle ) ;
@@ -1857,34 +1898,6 @@ var index = {
1857
1898
this . _trackerHandles = null ;
1858
1899
this . _meteorActive = false ;
1859
1900
} ,
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
- } ,
1888
1901
$addMeteorData : function $addMeteorData ( key , func ) {
1889
1902
var _this4 = this ;
1890
1903
@@ -1908,12 +1921,7 @@ var index = {
1908
1921
1909
1922
// Function run
1910
1923
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 ) ;
1917
1925
set$1 ( _this4 . $data . $meteor . data , key , result ) ;
1918
1926
} ;
1919
1927
@@ -1941,6 +1949,42 @@ var index = {
1941
1949
unwatch ( ) ;
1942
1950
unautorun ( ) ;
1943
1951
} ;
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
+ } ;
1944
1988
}
1945
1989
}
1946
1990
} ) ) ;
0 commit comments