Skip to content

Commit 5d7d67c

Browse files
committed
Prevent executor impossible states from emitting
Fixes codesandbox#2196 Fixes codesandbox#2192
1 parent f81e980 commit 5d7d67c

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

packages/app/src/app/store/providers/Executor.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@ export default Provider({
1212
const signal = this.context.controller.getSignal(signalPath);
1313
const executor = executorsManager.getExecutor();
1414

15+
if (!executor) {
16+
throw new Error(
17+
'Executor is not defined yet, this is an impossible state'
18+
);
19+
}
20+
1521
return executor.on(event, data => {
1622
signal({ event, data: data || {} });
1723
});
1824
},
1925
emit(message, data) {
2026
const executor = executorsManager.getExecutor();
2127

22-
return executor.emit(message, data);
28+
if (executor) {
29+
executor.emit(message, data);
30+
}
2331
},
2432
closeExecutor() {
2533
return executorsManager.closeExecutor();

packages/app/src/app/utils/executor-manager.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,7 @@ export class ExecutorsManager {
106106
* to either the sandbox or the server executor. Changing the executor would probably also result in components unmounting/
107107
* remounting and registering new listeners.
108108
*/
109-
getExecutor(): IExecutor {
110-
if (!this.executor) {
111-
throw new Error(
112-
'Executor is not defined yet, this is an impossible state'
113-
);
114-
}
115-
109+
getExecutor(): IExecutor | undefined {
116110
return this.executor;
117111
}
118112

0 commit comments

Comments
 (0)