@@ -60,39 +60,21 @@ export default class SmartApollo {
6060 start ( ) {
6161 this . starting = true
6262
63- // Query callback
64- if ( typeof this . initialOptions . query === 'function' ) {
65- const queryCb = this . initialOptions . query . bind ( this . vm )
66- this . options . query = queryCb ( )
67- this . _watchers . push ( this . vm . $watch ( queryCb , query => {
68- this . options . query = query
69- this . refresh ( )
70- } , {
71- deep : this . options . deep ,
72- } ) )
73- }
74- // Query callback
75- if ( typeof this . initialOptions . document === 'function' ) {
76- const queryCb = this . initialOptions . document . bind ( this . vm )
77- this . options . document = queryCb ( )
78- this . _watchers . push ( this . vm . $watch ( queryCb , document => {
79- this . options . document = document
80- this . refresh ( )
81- } , {
82- deep : this . options . deep ,
83- } ) )
84- }
85-
86- // Apollo context
87- if ( typeof this . initialOptions . context === 'function' ) {
88- const cb = this . initialOptions . context . bind ( this . vm )
89- this . options . context = cb ( )
90- this . _watchers . push ( this . vm . $watch ( cb , context => {
91- this . options . context = context
92- this . refresh ( )
93- } , {
94- deep : this . options . deep ,
95- } ) )
63+ // Reactive options
64+ for ( const prop of [ 'query' , 'document' , 'context' ] ) {
65+ if ( typeof this . initialOptions [ prop ] === 'function' ) {
66+ const queryCb = this . initialOptions [ prop ] . bind ( this . vm )
67+ this . options [ prop ] = queryCb ( )
68+ let cb = query => {
69+ this . options [ prop ] = query
70+ this . refresh ( )
71+ }
72+ cb = this . options . throttle ? throttle ( cb , this . options . throttle ) : cb
73+ cb = this . options . debounce ? debounce ( cb , this . options . debounce ) : cb
74+ this . _watchers . push ( this . vm . $watch ( queryCb , cb , {
75+ deep : this . options . deep ,
76+ } ) )
77+ }
9678 }
9779
9880 // GraphQL Variables
0 commit comments