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 1
1
{
2
2
"name" : " vue-apollo" ,
3
- "version" : " 1.2.5 " ,
3
+ "version" : " 1.3.0 " ,
4
4
"description" : " Vue apollo integration" ,
5
5
"main" : " index.js" ,
6
6
"scripts" : {
31
31
},
32
32
"dependencies" : {
33
33
"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"
35
37
},
36
38
"devDependencies" : {
37
39
"babel-cli" : " ^6.14.0" ,
Original file line number Diff line number Diff line change 1
1
import omit from 'lodash.omit'
2
+ import { throttle , debounce } from './utils'
2
3
3
4
class SmartApollo {
4
5
type = null
@@ -62,7 +63,10 @@ class SmartApollo {
62
63
start ( ) {
63
64
this . starting = true
64
65
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 , {
66
70
immediate : true ,
67
71
} )
68
72
} else {
@@ -125,6 +129,8 @@ export class SmartQuery extends SmartApollo {
125
129
'loadingKey' ,
126
130
'watchLoading' ,
127
131
'skip' ,
132
+ 'throttle' ,
133
+ 'debounce' ,
128
134
]
129
135
130
136
constructor ( vm , key , options ) {
@@ -245,6 +251,8 @@ export class SmartSubscription extends SmartApollo {
245
251
'variables' ,
246
252
'result' ,
247
253
'error' ,
254
+ 'throttle' ,
255
+ 'debounce' ,
248
256
]
249
257
250
258
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