Created
July 13, 2017 00:45
-
-
Save ar5had/5a90e3aa77b1dee7684ed5a044ce3bd1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { Provider } = ReactRedux; | |
window.addEventListener("message", e => { | |
// extentions and other 3rd party scripts talk via postMeessage api(same orgin) | |
// so it is very important to filter those events | |
if (e.origin !== window.location.origin || !e.data || e.data.source !== "dialog-message") { | |
return; | |
} | |
// parent and window are same thing if the current page is not in any frame | |
if (window !== parent) { | |
parent.postMessage( | |
{ messageRecieved: true, source: "dialog-message" }, | |
`${window.location.origin}/iframe-testing-ground` | |
); | |
} | |
const state = Object.assign({}, e.data); | |
window.redux_store.dispatch(window.redux_actions.loadInitialState(state)); | |
}); | |
window.sendState = () => { | |
window.postMessage(window.redux_store.getState(), `${window.location.origin}`); | |
}; | |
ReactDOM.render( | |
<Provider store={window.redux_store}> | |
<PrintDialog /> | |
</Provider>, | |
document.getElementById("root") | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment