82e4cbbb2897a13ee25842472d346975e2776014
[sdc/sdc-workflow-designer.git] / sdc-workflow-designer-ui / src / app / services / broadcast.service.ts
1 /**
2  * Copyright (c) 2017 ZTE Corporation.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * and the Apache License 2.0 which both accompany this distribution,
6  * and are available at http://www.eclipse.org/legal/epl-v10.html
7  * and http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Contributors:
10  *     ZTE - initial API and implementation and/or initial documentation
11  */
12 import { Injectable } from '@angular/core';
13 import { Subject } from 'rxjs/Subject';
14
15 import { WorkflowNode } from '../model/workflow-node';
16
17 /**
18  * BroadcastService
19  * All of the observable subject should be registered to this service.
20  * It provider a broadcast method to broadcast data. the broadcast method would catch error while broadcasting.
21  */
22 @Injectable()
23 export class BroadcastService {
24
25     public jsPlumbInstance = new Subject<any>();
26     public jsPlumbInstance$ = this.jsPlumbInstance.asObservable();
27
28     public showProperty = new Subject<boolean>();
29     public showProperty$ = this.showProperty.asObservable();
30
31     public saveEvent = new Subject<string>();
32     public saveEvent$ = this.saveEvent.asObservable();
33
34     public nodeProperty = new Subject<WorkflowNode>();
35     public nodeProperty$ = this.nodeProperty.asObservable();
36
37     /**
38      * broadcast datas
39      * this method will catch the exceptions for the broadcast
40      * @param subject will broadcast data
41      * @param data will be broadcated
42      */
43     public broadcast(subject: Subject<any>, data: any) {
44         try {
45             subject.next(data);
46         } catch (err) {
47             console.error(err);
48         }
49     }
50 }