(
private readonly w: () => (Window | null),
private readonly targetOrigin: string
)
| 10 | private readonly listeners: Map<string, Function[]> = new Map() |
| 11 | |
| 12 | constructor( |
| 13 | private readonly w: () => (Window | null), |
| 14 | private readonly targetOrigin: string |
| 15 | ) { |
| 16 | window.addEventListener('message', e => { |
| 17 | if (e.origin !== targetOrigin) { |
| 18 | return |
| 19 | } |
| 20 | const listeners = this.listeners.get(e.data.type) |
| 21 | if (listeners) { |
| 22 | listeners.forEach(func => func(e.data.data)) |
| 23 | } |
| 24 | }) |
| 25 | } |
| 26 | |
| 27 | send< |
| 28 | T extends Events0['type'] |