Skip to content

Commit

Permalink
reject promise on handshake fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitor Cunha committed Nov 27, 2020
1 parent fadcb22 commit 56c6fe8
Show file tree
Hide file tree
Showing 6 changed files with 2,697 additions and 1,149 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ You can download the compiled javascript directly [here](/build/postmate.min.js)
* Child emits events that the parent can listen to.
* Parent can `call` functions within a `child`
* *Zero* dependencies. Provide your own polyfill or abstraction for the `Promise` API if needed.
* Lightweight, weighing in at ~ <span class="size">`1.6kb`</span> (minified & gzipped).
* Lightweight, weighing in at ~ <span class="size">`1.7kb`</span> (minified & gzipped).

NOTE: While the underlying mechanism is [window.postMessage()](https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage), only iFrame is supported.

Expand Down
58 changes: 29 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "popostmate",
"version": "1.6.2",
"version": "1.6.4",
"description": "A powerful, simple, promise-based postMessage library",
"main": "build/postmate.js",
"module": "build/postmate.es.js",
Expand All @@ -10,36 +10,36 @@
"src"
],
"devDependencies": {
"@babel/core": "^7.0.0-beta.51",
"@babel/plugin-proposal-class-properties": "^7.0.0-beta.51",
"@babel/preset-env": "^7.0.0-beta.51",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^23.0.0",
"chai": "^4.1.2",
"codecov": "^3.0.2",
"connect": "^3.4.1",
"conventional-changelog-cli": "^2.0.5",
"es-check": "^5.0.0",
"eslint": "^6.0.0",
"@babel/core": "^7.12.3",
"@babel/plugin-proposal-class-properties": "^7.12.1",
"@babel/preset-env": "^7.12.1",
"babel-core": "^7.0.0-bridge",
"babel-jest": "^26.6.1",
"chai": "^4.2.0",
"codecov": "^3.8.0",
"connect": "^3.7.0",
"conventional-changelog-cli": "^2.1.0",
"es-check": "^5.1.2",
"eslint": "^7.12.1",
"eslint-config-dollarshaveclub": "^3.0.4",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-standard": "^4.0.1",
"gulp": "4.0.2",
"gulp-mocha-phantomjs": "0.12.2",
"gzip-size": "^5.0.0",
"jest": "^22.0.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-standard": "^4.0.2",
"gulp": "^4.0.2",
"gulp-mocha-phantomjs": "^0.12.2",
"gzip-size": "^5.1.1",
"jest": "^26.6.1",
"mocha": "^7.0.1",
"mocha-phantomjs": "^4.1.0",
"nyc": "^15.0.0",
"regenerator-runtime": "^0.13.0",
"rollup": "^1.21.4",
"rollup-plugin-babel": "^4.0.0-beta.0",
"rollup-plugin-replace": "^2.0.0",
"rollup-plugin-uglify": "^6.0.0",
"rsvp": "^4.8.1",
"serve-static": "^1.11.1",
"uglify-js": "^3.6.3",
"nyc": "^15.1.0",
"regenerator-runtime": "^0.13.7",
"rollup": "^2.32.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-uglify": "^6.0.4",
"rsvp": "^4.8.5",
"serve-static": "^1.14.1",
"uglify-js": "^3.11.4",
"vinyl-source-stream": "^2.0.0"
},
"scripts": {
Expand All @@ -48,7 +48,7 @@
"test": "npm run test:unit && npm run test:acceptance && npm run test:es-check",
"test:es-check": "es-check es5 build/postmate.min.js",
"test:unit": "jest --coverage",
"test:acceptance": "gulp test ",
"test:acceptance": "gulp test",
"build": "npm run build:dist && npm run build:readme",
"build:readme": "node ./scripts/update-readme.js",
"build:dist": "rollup --config configs/rollup.config.js",
Expand Down
14 changes: 8 additions & 6 deletions src/postmate.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ class Postmate {
this.parent = window
this.frame = document.createElement('iframe')
this.frame.name = name || ''
this.frame.classList.add.apply(this.frame.classList, classListArray)
if (classListArray.length > 0) { // check for IE 11. See issue#207
this.frame.classList.add.apply(this.frame.classList, classListArray)
}
container.appendChild(this.frame)
this.child = this.frame.contentWindow || this.frame.contentDocument.parentWindow
this.model = model || {}
Expand Down Expand Up @@ -334,7 +336,11 @@ class Postmate {
this.parent.addEventListener('message', reply, false)

const doSend = () => {
attempt++
if (++attempt > maxHandshakeRequests) {
clearInterval(responseInterval)
return reject('Handshake Timeout Reached')
}

if (process.env.NODE_ENV !== 'production') {
log(`Parent: Sending handshake attempt ${attempt}`, { childOrigin })
}
Expand All @@ -344,10 +350,6 @@ class Postmate {
model: this.model,
childId: this.childId,
}, childOrigin)

if (attempt === maxHandshakeRequests) {
clearInterval(responseInterval)
}
}

const loaded = () => {
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/fixtures/child.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<script>
window.onerror = function () { console.log.apply(console, arguments); };
</script>
<script src="../../node_modules/rsvp/dist/rsvp.min.js"></script>
<script src="../../node_modules/rsvp/dist/rsvp.js"></script>
<script type="text/javascript" src="../../build/postmate.min.js"></script>
<script>Postmate.Promise = RSVP.Promise;</script>
<script type="text/javascript">
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<script src="../../node_modules/mocha/mocha.js"></script>
<script src="../../node_modules/chai/chai.js"></script>
<script>mocha.setup('bdd')</script>
<script src="../../node_modules/rsvp/dist/rsvp.min.js"></script>
<script src="../../node_modules/rsvp/dist/rsvp.js"></script>
<script src="../../build/postmate.dev.js"></script>
<script>Postmate.Promise = RSVP.Promise;</script>
<script src="./test.js"></script>
Expand Down
Loading

0 comments on commit 56c6fe8

Please sign in to comment.