/
githubmirror
/
angular
Обзор
Документация
Войти
/
githubmirror
/
angular
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
devtools/src/zone-unaware-iframe-message-bus.ts
55 строк
1 KB
Milo
refactor(devtools): cleanup iframe-message-bus (#62785)
25 июл 2025, 11:03
25 июл 2025, 11:03
e4ed6d6
Код
Авторство
О чём код?
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.dev/license */ import {Events, MessageBus, Parameters} from '../projects/protocol'; import {IFrameMessageBus} from './iframe-message-bus'; const runOutsideAngular = (f: () => any) => { const w = window as any; if (!w.Zone || w.Zone.current._name !== 'angular') { f(); return; } w.Zone.current._parent.run(f); }; export class ZoneUnawareIFrameMessageBus extends MessageBus<Events> { private delegate: IFrameMessageBus; constructor(source: string, destination: string, docWindow: () => Window) { super(); this.delegate = new IFrameMessageBus(source, destination, docWindow); } override on<E extends keyof Events>(topic: E, cb: Events[E]): any { let result: any; runOutsideAngular(() => { result = this.delegate.on(topic, cb); }); return result; } override once<E extends keyof Events>(topic: E, cb: Events[E]): any { let result: any; runOutsideAngular(() => { result = this.delegate.once(topic, cb); }); return result; } // Need to be run in the zone because otherwise it won't be caught by the // listener in the extension. override emit<E extends keyof Events>(topic: E, args?: Parameters<Events[E]>): boolean { return this.delegate.emit(topic, args); } override destroy(): void { this.delegate.destroy(); } }