From 73b78d3fe847014bcb8a9caad59544778fc6d0c1 Mon Sep 17 00:00:00 2001 From: unadlib Date: Sat, 19 Jun 2021 17:35:01 +0800 Subject: [PATCH] refactor(globaltransport): refactor GlobalTransport in fronts-transport --- packages/fronts-react/src/index.ts | 2 +- .../src/{messageTransport.ts => globalTransport.ts} | 8 ++++---- packages/fronts-transport/src/index.ts | 2 +- packages/fronts/src/index.ts | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) rename packages/fronts-transport/src/{messageTransport.ts => globalTransport.ts} (82%) diff --git a/packages/fronts-react/src/index.ts b/packages/fronts-react/src/index.ts index d8bb576..ec6f162 100644 --- a/packages/fronts-react/src/index.ts +++ b/packages/fronts-react/src/index.ts @@ -1,4 +1,4 @@ -export { boot, loadScript, transport } from 'fronts'; +export { boot, loadScript, globalTransport, GlobalTransport } from 'fronts'; export * from './useApp'; export * from './interface'; diff --git a/packages/fronts-transport/src/messageTransport.ts b/packages/fronts-transport/src/globalTransport.ts similarity index 82% rename from packages/fronts-transport/src/messageTransport.ts rename to packages/fronts-transport/src/globalTransport.ts index caa8e20..dab5116 100644 --- a/packages/fronts-transport/src/messageTransport.ts +++ b/packages/fronts-transport/src/globalTransport.ts @@ -2,7 +2,7 @@ import { ListenerOptions, Transport, TransportOptions } from 'data-transport'; import { postMessageToFrames } from './postMessage'; -interface MessageTransportOptions extends Partial { +interface EventTransportOptions extends Partial { /** * Specify what the origin of targetWindow must be for the event to be dispatched, * by default, it's the literal string "*" (indicating no preference). @@ -10,7 +10,7 @@ interface MessageTransportOptions extends Partial { targetOrigin?: string; } -class MessageTransport extends Transport { +export class GlobalTransport extends Transport { constructor({ targetOrigin = '*', listener = (callback) => { @@ -29,7 +29,7 @@ class MessageTransport extends Transport { }, checkListen = false, ...options - }: MessageTransportOptions) { + }: EventTransportOptions) { super({ ...options, checkListen, @@ -39,4 +39,4 @@ class MessageTransport extends Transport { } } -export const transport = new MessageTransport({}); +export const globalTransport = new GlobalTransport({}); diff --git a/packages/fronts-transport/src/index.ts b/packages/fronts-transport/src/index.ts index 4efb92d..a8562b5 100644 --- a/packages/fronts-transport/src/index.ts +++ b/packages/fronts-transport/src/index.ts @@ -1,3 +1,3 @@ export * from 'data-transport'; -export * from './messageTransport'; +export * from './globalTransport'; diff --git a/packages/fronts/src/index.ts b/packages/fronts/src/index.ts index 5be5760..8bfb1f5 100644 --- a/packages/fronts/src/index.ts +++ b/packages/fronts/src/index.ts @@ -1,6 +1,6 @@ import './injectDependencies'; -export { transport } from 'fronts-transport'; +export { globalTransport, GlobalTransport } from 'fronts-transport'; export * from './loadApp'; export * from './interface';