@@ -219,7 +219,7 @@ class WorkflowService {
219
219
subscription . subscribers [ componentOrView . _uid ] = componentOrView
220
220
// Then we recompute the query, checking if variables match, and action name is set.
221
221
this . recompute ( subscription )
222
- // regardless of whether this results in a restart, we take this opertunity to preset the componentOrView store if needed
222
+ // regardless of whether this results in a restart, we take this opportunity to preset the componentOrView store if needed
223
223
const errors = [ ]
224
224
// if the callbacks class has an init method defined, use it
225
225
for ( const callback of subscription . callbacks ) {
@@ -273,63 +273,92 @@ class WorkflowService {
273
273
}
274
274
this . stopSubscription ( subscription , true )
275
275
}
276
-
277
- const globalCallback = this . globalCallback
278
-
279
- try {
280
- // Then start subscription.
281
- subscription . observable = this . startDeltasSubscription (
282
- subscription . query . query ,
283
- subscription . query . variables ,
284
- {
285
- next : function next ( response ) {
286
- const deltas = response . data . deltas || { }
287
- const added = deltas . added || { }
288
- const updated = deltas . updated || { }
289
- const pruned = deltas . pruned || { }
290
- const errors = [ ]
291
-
292
- // run the global callback first
293
- globalCallback . onAdded ( added , store , errors )
294
- globalCallback . onUpdated ( updated , store , errors )
295
- globalCallback . onPruned ( pruned , store , errors )
296
-
297
- // then run the local callbacks if there are any
298
- if ( subscription . callbacks . length === 0 ) {
299
- return
300
- }
301
- for ( const callback of subscription . callbacks ) {
302
- callback . before ( deltas , store , errors )
303
- callback . onAdded ( added , store , errors )
304
- callback . onUpdated ( updated , store , errors )
305
- callback . commit ( store , errors )
306
- }
307
- for ( const callback of [ ...subscription . callbacks ] . reverse ( ) ) {
308
- callback . onPruned ( pruned , store , errors )
309
- callback . after ( deltas , store , errors )
310
- callback . commit ( store , errors )
276
+ if ( subscription . query . isDelta === false & subscription . query . isGlobalCallback === false ) {
277
+ try {
278
+ // Then start subscription.
279
+ subscription . observable = this . startCylcSubscription (
280
+ subscription . query . query ,
281
+ subscription . query . variables ,
282
+ {
283
+ next : function next ( response ) {
284
+ if ( subscription . callbacks . length === 0 ) {
285
+ return
286
+ }
287
+ const errors = [ ]
288
+ for ( const callback of subscription . callbacks ) {
289
+ callback . onAdded ( response . data . logs , store , errors )
290
+ callback . commit ( store , errors )
291
+ }
292
+ } ,
293
+ error : function error ( err ) {
294
+ subscription . handleViewState ( ViewState . ERROR , err )
311
295
}
312
- for ( const error of errors ) {
313
- store . commit (
314
- 'SET_ALERT' ,
315
- new Alert ( error [ 0 ] , null , 'error' ) ,
316
- { root : true }
317
- )
318
- // eslint-disable-next-line no-console
319
- console . warn ( ...error )
296
+ }
297
+ )
298
+ this . subscriptions [ subscription . query . name ] = subscription
299
+ // All done!
300
+ subscription . handleViewState ( ViewState . COMPLETE , null )
301
+ subscription . reload = false
302
+ } catch ( e ) {
303
+ subscription . handleViewState ( ViewState . ERROR , e )
304
+ }
305
+ } else {
306
+ const globalCallback = this . globalCallback
307
+ try {
308
+ // Then start subscription.
309
+ subscription . observable = this . startCylcSubscription (
310
+ subscription . query . query ,
311
+ subscription . query . variables ,
312
+ {
313
+ next : function next ( response ) {
314
+ const deltas = response . data . deltas || { }
315
+ const added = deltas . added || { }
316
+ const updated = deltas . updated || { }
317
+ const pruned = deltas . pruned || { }
318
+ const errors = [ ]
319
+
320
+ // run the global callback first
321
+ globalCallback . onAdded ( added , store , errors )
322
+ globalCallback . onUpdated ( updated , store , errors )
323
+ globalCallback . onPruned ( pruned , store , errors )
324
+
325
+ // then run the local callbacks if there are any
326
+ if ( subscription . callbacks . length === 0 ) {
327
+ return
328
+ }
329
+ for ( const callback of subscription . callbacks ) {
330
+ callback . before ( deltas , store , errors )
331
+ callback . onAdded ( added , store , errors )
332
+ callback . onUpdated ( updated , store , errors )
333
+ callback . commit ( store , errors )
334
+ }
335
+ for ( const callback of [ ...subscription . callbacks ] . reverse ( ) ) {
336
+ callback . onPruned ( pruned , store , errors )
337
+ callback . after ( deltas , store , errors )
338
+ callback . commit ( store , errors )
339
+ }
340
+ for ( const error of errors ) {
341
+ store . commit (
342
+ 'SET_ALERT' ,
343
+ new Alert ( error [ 0 ] , null , 'error' ) ,
344
+ { root : true }
345
+ )
346
+ // eslint-disable-next-line no-console
347
+ console . warn ( ...error )
348
+ }
349
+ } ,
350
+ error : function error ( err ) {
351
+ subscription . handleViewState ( ViewState . ERROR , err )
320
352
}
321
- } ,
322
- error : function error ( err ) {
323
- subscription . handleViewState ( ViewState . ERROR , err )
324
353
}
325
- }
326
- )
327
- this . subscriptions [ subscription . query . name ] = subscription
328
- // All done!
329
- subscription . handleViewState ( ViewState . COMPLETE , null )
330
- subscription . reload = false
331
- } catch ( e ) {
332
- subscription . handleViewState ( ViewState . ERROR , e )
354
+ )
355
+ this . subscriptions [ subscription . query . name ] = subscription
356
+ // All done!
357
+ subscription . handleViewState ( ViewState . COMPLETE , null )
358
+ subscription . reload = false
359
+ } catch ( e ) {
360
+ subscription . handleViewState ( ViewState . ERROR , e )
361
+ }
333
362
}
334
363
}
335
364
@@ -343,7 +372,7 @@ class WorkflowService {
343
372
* @param {SubscriptionOptions } subscriptionOptions - { next(), error() }
344
373
* @returns {Subscription }
345
374
*/
346
- startDeltasSubscription ( query , variables , subscriptionOptions ) {
375
+ startCylcSubscription ( query , variables , subscriptionOptions ) {
347
376
if ( ! query ) {
348
377
throw new Error ( 'You must provide a query for the subscription' )
349
378
}
0 commit comments