From 7574f20cf6eb0e4eb10c994be4ffdb4c45a5145e Mon Sep 17 00:00:00 2001 From: Muhammed Thanish Date: Fri, 28 Oct 2016 16:28:36 +0530 Subject: [PATCH] Use a constant key to identify messages --- src/index.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/index.js b/src/index.js index fb99c7e4d4b7..294e3bc4aa29 100644 --- a/src/index.js +++ b/src/index.js @@ -1,14 +1,15 @@ import Channel from '@kadira/storybook-channel'; import stringify from 'json-stringify-safe'; -export default function createChannel({ key }) { - const transport = new PostmsgTransport({ key }); +export const KEY = 'storybook-channel'; + +export default function createChannel() { + const transport = new PostmsgTransport(); return new Channel({ transport }); } export class PostmsgTransport { - constructor({ key }) { - this._key = key; + constructor() { this._buffer = []; this._handler = null; window.addEventListener('message', this._handleEvent.bind(this), false); @@ -26,7 +27,7 @@ export class PostmsgTransport { this._buffer.push({ event, resolve, reject }); }); } - const data = stringify({ key: this._key, event }); + const data = stringify({ key: KEY, event }); iframeWindow.postMessage(data, '*'); return Promise.resolve(null); } @@ -68,7 +69,7 @@ export class PostmsgTransport { return null; } const { key, event } = data; - if (key === this._key) { + if (key === KEY) { this._handler(event); } }