-
Notifications
You must be signed in to change notification settings - Fork 93
/
types.js
90 lines (72 loc) · 2.43 KB
/
types.js
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
/* @flow */
import type { ZalgoPromise } from '@krakenjs/zalgo-promise/src';
import type { CrossDomainWindowType, DomainMatcher } from '@krakenjs/cross-domain-utils/src';
import type { ProxyWindow } from './serialize/window';
// export something to force webpack to see this as an ES module
export const TYPES = true;
// eslint-disable-next-line flowtype/require-exact-type
export type CancelableType = {
cancel : () => void
};
export type ErrorHandlerType = (err : mixed) => void;
export type HandlerType = ({|
source : CrossDomainWindowType,
origin : string,
data : any // eslint-disable-line flowtype/no-weak-types
|}) => (void | any | ZalgoPromise<any>); // eslint-disable-line flowtype/no-weak-types
export type ServerOptionsType = {|
handler? : ?HandlerType,
errorHandler? : ?ErrorHandlerType,
window? : CrossDomainWindowType | ProxyWindow,
name? : ?string,
domain? : ?DomainMatcher,
once? : ?boolean,
errorOnClose? : ?boolean
|};
export type OnType = (
name : string,
options : ServerOptionsType | HandlerType,
handler : ?HandlerType
) => CancelableType;
type RegularRequestOptionsType = {|
domain? : ?DomainMatcher,
fireAndForget? : false,
timeout? : ?number
|};
type FireAndForgetRequestOptionsType = {|
domain? : ?DomainMatcher,
fireAndForget : true,
timeout? : ?number
|};
export type RequestOptionsType = RegularRequestOptionsType | FireAndForgetRequestOptionsType;
export type ResponseMessageEvent = {|
source : CrossDomainWindowType,
origin : string,
data : Object
|};
type RegularSendType = (
win : CrossDomainWindowType | ProxyWindow,
name : string,
data : ?Object,
options? : RegularRequestOptionsType
) => ZalgoPromise<ResponseMessageEvent>;
type FireAndForgetSendType = (
win : CrossDomainWindowType | ProxyWindow,
name : string,
data : ?Object,
options? : FireAndForgetRequestOptionsType
) => ZalgoPromise<void>;
export type SendType = RegularSendType & FireAndForgetSendType;
export type MessageEvent = {|
source : CrossDomainWindowType,
origin : string,
data : string
|};
// eslint-disable-next-line flowtype/require-exact-type
export type CrossDomainFunctionType<A, R> = {
(...args : A) : ZalgoPromise<R>,
fireAndForget : (...args : A) => ZalgoPromise<void>,
__id__? : string,
__name__? : string
};
export type ReceiveMessageType = (MessageEvent, {| on : OnType, send : SendType |}) => void;