@@ -101,7 +101,15 @@ class ContextStore {
101
101
}
102
102
103
103
async broadcast ( context : ContextType ) {
104
- if ( context ) {
104
+ if ( ! context ) {
105
+ systemLogStore . addLog ( {
106
+ name : "broadcast" ,
107
+ type : "warning" ,
108
+ value : "You must set a context before you can broadcast it" ,
109
+ variant : "text" ,
110
+ } ) ;
111
+ return ;
112
+ } else {
105
113
//check that we're on a channel
106
114
let currentChannel = await fdc3 . getCurrentChannel ( ) ;
107
115
if ( ! currentChannel ) {
@@ -129,59 +137,52 @@ class ContextStore {
129
137
} ) ;
130
138
}
131
139
}
132
- } else {
133
- systemLogStore . addLog ( {
134
- name : "broadcast" ,
135
- type : "warning" ,
136
- value : "You must set a context before you can broadcast it" ,
137
- variant : "text" ,
138
- } ) ;
139
140
}
140
141
}
141
142
142
143
addContextListener ( contextType : string | undefined ) {
143
144
try {
144
145
if ( typeof contextType === "string" ) {
145
- const listenerId = nanoid ( ) ;
146
+ const listenerId = nanoid ( ) ;
146
147
147
- // TODO: remove window after fixing https://github.com/finos/FDC3/issues/435
148
- const contactListener = window . fdc3 . addContextListener ( contextType . toLowerCase ( ) === "all" ? null : contextType , ( context ) => {
149
- const currentListener = this . contextListeners . find ( ( { id } ) => id === listenerId ) ;
148
+ // TODO: remove window after fixing https://github.com/finos/FDC3/issues/435
149
+ const contactListener = window . fdc3 . addContextListener ( contextType . toLowerCase ( ) === "all" ? null : contextType , ( context ) => {
150
+ const currentListener = this . contextListeners . find ( ( { id } ) => id === listenerId ) ;
150
151
151
- runInAction ( ( ) => {
152
- if ( currentListener ) {
153
- currentListener . lastReceivedContext = context ;
154
- }
155
- } ) ;
152
+ runInAction ( ( ) => {
153
+ if ( currentListener ) {
154
+ currentListener . lastReceivedContext = context ;
155
+ }
156
+ } ) ;
156
157
157
- systemLogStore . addLog ( {
158
- name : "receivedContextListener" ,
159
- type : "info" ,
160
- value : contextType ,
161
- variant : "code" ,
162
- body : JSON . stringify ( context , null , 4 ) ,
158
+ systemLogStore . addLog ( {
159
+ name : "receivedContextListener" ,
160
+ type : "info" ,
161
+ value : contextType ,
162
+ variant : "code" ,
163
+ body : JSON . stringify ( context , null , 4 ) ,
164
+ } ) ;
163
165
} ) ;
164
- } ) ;
165
166
166
- runInAction ( ( ) => {
167
- systemLogStore . addLog ( {
168
- name : "addContextListener" ,
169
- type : "success" ,
170
- value : contextType ,
171
- variant : "text" ,
167
+ runInAction ( ( ) => {
168
+ systemLogStore . addLog ( {
169
+ name : "addContextListener" ,
170
+ type : "success" ,
171
+ value : contextType ,
172
+ variant : "text" ,
173
+ } ) ;
174
+ this . contextListeners . push ( { id : listenerId , type : contextType , listener : contactListener } ) ;
172
175
} ) ;
173
- this . contextListeners . push ( { id : listenerId , type : contextType , listener : contactListener } ) ;
174
- } ) ;
175
- } else {
176
- runInAction ( ( ) => {
177
- systemLogStore . addLog ( {
178
- name : "addContextListener" ,
179
- type : "error" ,
180
- value : contextType ,
181
- variant : "code" ,
176
+ } else {
177
+ runInAction ( ( ) => {
178
+ systemLogStore . addLog ( {
179
+ name : "addContextListener" ,
180
+ type : "error" ,
181
+ value : contextType ,
182
+ variant : "code" ,
183
+ } ) ;
182
184
} ) ;
183
- } ) ;
184
- }
185
+ }
185
186
} catch ( e ) {
186
187
systemLogStore . addLog ( {
187
188
name : "addContextListener" ,
0 commit comments