File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,12 @@ angular.module(name, [
45
45
fn = this . $bindToContext ( $Mixer . caller , fn || angular . noop ) ;
46
46
cb = cb ? this . $bindToContext ( $Mixer . caller , cb ) : angular . noop ;
47
47
48
+ // Additional callbacks specific for this library
49
+ // onStart - right after Meteor.subscribe()
50
+ const hooks = {
51
+ onStart : angular . noop
52
+ } ;
53
+
48
54
if ( ! _ . isString ( subName ) ) {
49
55
throw Error ( 'argument 1 must be a string' ) ;
50
56
}
@@ -55,6 +61,16 @@ angular.module(name, [
55
61
throw Error ( 'argument 3 must be a function or an object' ) ;
56
62
}
57
63
64
+ if ( _ . isObject ( cb ) ) {
65
+ for ( const hook in hooks ) {
66
+ if ( hooks . hasOwnProperty ( hook ) && cb [ hook ] ) {
67
+ // Don't use any of additional callbacks in Meteor.subscribe
68
+ hooks [ hook ] = cb [ hook ] ;
69
+ delete cb [ hook ] ;
70
+ }
71
+ }
72
+ }
73
+
58
74
const result = { } ;
59
75
60
76
const computation = this . autorun ( ( ) => {
@@ -66,6 +82,9 @@ angular.module(name, [
66
82
}
67
83
68
84
const subscription = Meteor . subscribe ( subName , ...args , cb ) ;
85
+
86
+ hooks . onStart ( ) ;
87
+
69
88
result . ready = subscription . ready . bind ( subscription ) ;
70
89
result . subscriptionId = subscription . subscriptionId ;
71
90
} ) ;
Original file line number Diff line number Diff line change @@ -180,7 +180,7 @@ describe('angular-meteor.core', function() {
180
180
it ( 'should call subscription callbacks object using view model as context' , function ( done ) {
181
181
var vm = scope . viewModel ( { } ) ;
182
182
183
- var next = _ . after ( 2 , done ) ;
183
+ var next = _ . after ( 3 , done ) ;
184
184
185
185
spyOn ( Meteor , 'subscribe' ) . and . callFake ( function ( name , cbs ) {
186
186
cbs . onReady ( ) ;
@@ -197,6 +197,26 @@ describe('angular-meteor.core', function() {
197
197
onReady : function ( ) {
198
198
expect ( this ) . toEqual ( vm ) ;
199
199
next ( ) ;
200
+ } ,
201
+
202
+ onStart : function ( ) {
203
+ expect ( this ) . toEqual ( vm ) ;
204
+ next ( ) ;
205
+ }
206
+ } ) ;
207
+ } ) ;
208
+
209
+ it ( 'should call onStart callback after Meteor.subscribe has been called' , function ( done ) {
210
+ var vm = scope . viewModel ( { } ) ;
211
+
212
+ spyOn ( Meteor , 'subscribe' ) . and . callFake ( function ( ) {
213
+ return { ready : angular . noop } ;
214
+ } ) ;
215
+
216
+ vm . subscribe ( 'test' , angular . noop , {
217
+ onStart : function ( ) {
218
+ expect ( Meteor . subscribe ) . toHaveBeenCalled ( ) ;
219
+ done ( ) ;
200
220
}
201
221
} ) ;
202
222
} ) ;
You can’t perform that action at this time.
0 commit comments