Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
send(event: ChannelEvent): Promise {
const iframeWindow = this.getWindow();
if (!iframeWindow) {
return new Promise((resolve, reject) => {
this.buffer.push({ event, resolve, reject });
});
}
const data = stringify({ key: KEY, event }, { maxDepth: 15 });
// TODO: investigate http://blog.teamtreehouse.com/cross-domain-messaging-with-postmessage
// might replace '*' with document.location ?
iframeWindow.postMessage(data, '*');
return Promise.resolve(null);
}
private handleEvent(rawEvent: RawEvent): void {
try {
const { data } = rawEvent;
const { key, event } = typeof data === 'string' && isJSON(data) ? parse(data) : data;
if (key === KEY) {
logger.debug(`message arrived at ${this.config.page}`, event.type, ...event.args);
this.handler(event);
}
} catch (error) {
logger.error(error);
// debugger;
}
}
}
_.fn('set', function(key: string, data: object) {
return _.set(this._area, this._in(key), stringify(data, { maxDepth: 50 }));
});
_.fn('get', function(key: string, alt: string) {
_.fn('get', function(key: string, alt: string) {
const value = _.get(this._area, this._in(key));
return value !== null ? parse(value) : alt || value;
});
};