File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed
Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " vue-apollo" ,
3- "version" : " 1.2.5 " ,
3+ "version" : " 1.3.0 " ,
44 "description" : " Vue apollo integration" ,
55 "main" : " index.js" ,
66 "scripts" : {
3131 },
3232 "dependencies" : {
3333 "graphql-tag" : " ^0.1.15" ,
34- "lodash.omit" : " ^4.5.0"
34+ "lodash.debounce" : " ^4.0.8" ,
35+ "lodash.omit" : " ^4.5.0" ,
36+ "lodash.throttle" : " ^4.1.1"
3537 },
3638 "devDependencies" : {
3739 "babel-cli" : " ^6.14.0" ,
Original file line number Diff line number Diff line change 11import omit from 'lodash.omit'
2+ import { throttle , debounce } from './utils'
23
34class SmartApollo {
45 type = null
@@ -62,7 +63,10 @@ class SmartApollo {
6263 start ( ) {
6364 this . starting = true
6465 if ( typeof this . options . variables === 'function' ) {
65- this . unwatchVariables = this . vm . $watch ( this . options . variables . bind ( this . vm ) , this . executeApollo . bind ( this ) , {
66+ let cb = this . executeApollo . bind ( this )
67+ cb = this . options . throttle ? throttle ( cb , this . options . throttle ) : cb
68+ cb = this . options . debounce ? debounce ( cb , this . options . debounce ) : cb
69+ this . unwatchVariables = this . vm . $watch ( this . options . variables . bind ( this . vm ) , cb , {
6670 immediate : true ,
6771 } )
6872 } else {
@@ -125,6 +129,8 @@ export class SmartQuery extends SmartApollo {
125129 'loadingKey' ,
126130 'watchLoading' ,
127131 'skip' ,
132+ 'throttle' ,
133+ 'debounce' ,
128134 ]
129135
130136 constructor ( vm , key , options ) {
@@ -245,6 +251,8 @@ export class SmartSubscription extends SmartApollo {
245251 'variables' ,
246252 'result' ,
247253 'error' ,
254+ 'throttle' ,
255+ 'debounce' ,
248256 ]
249257
250258 constructor ( vm , key , options ) {
Original file line number Diff line number Diff line change 1+ import loThrottle from 'lodash.throttle'
2+ import loDebounce from 'lodash.debounce'
3+
4+ function factory ( action ) {
5+ return ( cb , options ) => {
6+ if ( typeof options === 'number' ) {
7+ return action ( cb , options )
8+ } else {
9+ return action ( cb , options . wait , options )
10+ }
11+ }
12+ }
13+
14+ export const throttle = factory ( loThrottle )
15+
16+ export const debounce = factory ( loDebounce )
You can’t perform that action at this time.
0 commit comments