@shopify/app-bridge
Version:
**Shopify is doubling our engineering staff in 2021! [Join our team and work on libraries like this one.](https://smrtr.io/5GGrc)**
86 lines (85 loc) • 2.32 kB
TypeScript
import type { AnyAction, ActionCallback, Unsubscribe } from './actions/types';
import type { TransportDispatch, Dispatcher } from './client/types';
declare global {
interface Window {
MobileWebView: {
postMessage(message?: any): void;
context?(): string;
};
__context__?: string;
}
}
export declare enum Context {
Modal = "Modal",
Main = "Main"
}
/**
* @deprecated Not to be used, use regular `MessageEvent` instead.
* @internal
*/
export interface HandlerData {
data: AnyAction;
}
/**
* @internal
*/
export declare type Handler = (event: MessageEvent) => void;
/**
* @internal
*/
export interface MessageTransport {
dispatch(message: TransportDispatch): void;
hostFrame: Window;
localOrigin: string;
subscribe(handler: Handler): () => void;
}
export interface ContextualMessageTransport extends MessageTransport {
context: Context;
frameWindow: Window | null;
dispatch(message: any): void;
}
/**
* Create a MessageTransport from an IFrame.
* @remarks
* Used on the host-side to create a postMessage MessageTransport.
* @beta
*/
export declare function fromFrame(frame: HTMLIFrameElement, localOrigin: string, context: Context): ContextualMessageTransport;
/**
* Create a MessageTransport from a parent window.
* @remarks
* Used on the client-side to create a postMessage MessageTransport.
* @internalremarks
* In unframed mode, message should be dispatched via MobileWebView.postMessage instead of postMessage.
* @beta
*/
export declare function fromWindow(contentWindow: Window, localOrigin: string): MessageTransport;
/**
* @internal
*/
export interface ActionListener {
id?: string;
callback(data: any): void;
}
/**
* @internal
*/
export interface ActionListenersMap {
[index: string]: ActionListener[];
}
/**
* @internal
*/
export interface Subscribe {
(callback: ActionCallback, id?: string): Unsubscribe;
(eventNameSpace: string, callback: ActionCallback, id?: string): Unsubscribe;
}
/**
* @internal
*/
export interface TransportListener {
createSubscribeHandler(dispatcher?: Dispatcher): Subscribe;
handleMessage(message: any): void;
handleActionDispatch(action: AnyAction): boolean;
}
export declare function createTransportListener(): TransportListener;