-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostmate.d.ts
More file actions
126 lines (111 loc) · 3.67 KB
/
Copy pathpostmate.d.ts
File metadata and controls
126 lines (111 loc) · 3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/**
* This is written in the parent page. Creates an iFrame at the specified url. Initiates a connection with the
* child. Returns a Promise that signals when the handshake is complete and communication is ready to begin.
*/
declare class Postmate extends Promise<Postmate.ParentAPI> {
/**
* Set to true to enable logging of additional information. Default: false
*/
static debug: boolean;
/**
* Replace the Promise API that Postmate uses. Default: window.Promise
*/
static Promise: Promise<any>;
/**
* Initializes a new instance of Postmate
*
* @param options configuration options
*/
constructor(options: Postmate.PostmateOptions);
}
declare namespace Postmate {
/**
* Options passed to the Postmate constructor
*/
interface PostmateOptions {
/**
* An element to append the iFrame to. Default: document.body
*/
container?: HTMLElement | null | undefined;
/**
* An object literal to represent the default values of the child's model
*/
model?: any;
/**
* A URL to load in the iFrame. The origin of this URL will also be used for securing message transport
*/
url: string;
/**
* An Array to add classes to the iFrame. Useful for styling
*/
classListArray?: string[] | undefined;
/**
* A name which is used for the name attribute of the created iFrame
*/
name?: string | undefined;
}
/**
* Composes an API to be used by the parent
*/
interface ParentAPI {
/**
* The iFrame Element that the parent is communicating with
*/
frame: HTMLIFrameElement;
/**
* Retrieves a value by property name from the child's model object.
*
* @param key The string property to lookup in the child's model
* @returns child model property value
*/
get(key: string): Promise<any>;
/**
* Calls a function on the child's model
*
* @param key The string property to lookup in the child's model
* @param data The optional data to send to the child function
*/
call(key: string, data?: any): void;
/**
* Listen to a particular event from the child
*
* @param eventName the name of the event
* @param callback the event handler function
*/
on(eventName: string, callback: (data?: any) => void): void;
/**
* Removes the iFrame element and destroys any message event listeners
*/
destroy(): void;
}
/**
* Composes an API to be used by the child
*/
interface ChildAPI {
/**
* Emits an event to the parent
*
* @param name the name of the event
* @param data event data
*/
emit(name: string, data?: any): void;
}
/**
* This is written in the child page. Calling Postmate.Model initiates a handshake request listener from the
* Child. Once the handshake is complete, an event listener is bound to receive requests from the Parent. The
* Child model is extended from the model provided by the Parent.
*/
class Model extends Promise<ChildAPI> {
/**
* Initializes a new instance of Model
*
* @param model An object of gettable properties to expose to the parent. Value types may be anything
* accepted in postMessage. Promises may also be set as values or returned from functions. Default: {}
*/
constructor(model: any);
}
}
/**
* Module export
*/
export default Postmate;