diff --git a/.babelrc b/.babelrc index 3bff21e7..b550b51e 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,4 @@ { - "presets": [ "es2015-rollup" ] + "presets": [ "es2015-rollup" ], + "plugins": ["transform-class-properties"] } diff --git a/README.md b/README.md index a72e0f48..9d911eef 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ You can download the compiled javascript directly [here](/build/postmate.min.js) * Child exposes a `model`, an object literal whose values consist of serializable values, functions and promises, that the parent can retrieve. * Child can emit events that the parent can listen to. * *Zero* dependencies. Provide your own polyfill or abstraction for the `Promise` API if needed -* Lightweight, weighing in at ~ `4.6kb` +* Lightweight, weighing in at ~ `4.7kb` ## Installing Postmate can be installed via NPM or Bower. @@ -49,10 +49,10 @@ $ bower i postmate # Install via Bower * **`Parent`**: The **top level** page that will embed an `iFrame`, creating a `Child` * **`Child`**: The **bottom level** page loaded within the `iFrame` * **`Model`**: The object that the `Child` exposes to the `Parent` +* **Handshake**: The process in which the parent frame identifies itself to the child, and vice versa. When a handshake is complete, the two contexts have bound their event listeners and identified one another. ## Usage -1. The `Parent` begins communication with the `Child`. A handshake is sent, the `Child` responds with -a handshake reply, finishing `Parent`/`Child` initialization. The two are bound and ready to communicate securely. +1. The `Parent` begins communication with the `Child`. A handshake is sent, the `Child` responds with a handshake reply, finishing `Parent`/`Child` initialization. The two are bound and ready to communicate securely. 2. The `Parent` fetches values from the `Child` by property name. The `Child` can emit messages to the parent. @@ -104,7 +104,19 @@ new Postmate(options); Name | Type | Description | Default :--- | :--- | :--- | :--- -`debug` | `Boolean` | _Set to `true` to enable logging of additional information_ | `undefined` +`debug` | `Boolean` | _Set to `true` to enable logging of additional information_ | `false` + +*** +> ## `Postmate.Promise` +```javascript +// parent.com or child.com +Postmate.Promise = RSVP.Promise; +new Postmate(options); +``` + +Name | Type | Description | Default +:--- | :--- | :--- | :--- +`Promise` | `Object` | _Replace the Promise API that Postmate uses_ | `window.Promise` *** diff --git a/build/postmate.min.js b/build/postmate.min.js index 26c76439..26a78cc6 100644 --- a/build/postmate.min.js +++ b/build/postmate.min.js @@ -1,7 +1,7 @@ /** * postmate - A powerful, simple, promise-based postMessage library - * @version v1.0.1 + * @version v1.0.2 * @link https://github.com/dollarshaveclub/postmate * @author Jacob Kelley * @license MIT */ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.Postmate=t()}(this,function(){"use strict";function e(){var e;l.debug&&(e=console).log.apply(e,arguments)}function t(e){var t=document.createElement("a");return t.href=e,t.origin}function n(e,t){return e.origin===t&&("object"===a(e.data)&&("postmate"in e.data&&e.data.type===o))}function i(e,t){var n="function"==typeof e[t]?e[t]():e[t];return Promise.resolve(n)}var a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol?"symbol":typeof e},r=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},s=function(){function e(e,t){for(var n=0;n { + return new Postmate.Promise(resolve => { // Extract data from response and kill listeners const uid = new Date().getTime(); const transact = e => { @@ -171,6 +171,9 @@ class ChildAPI { */ class Postmate { + static debug = false; + static Promise = window.Promise; + /** * Sets options related to the Parent * @param {Object} userOptions The element to inject the frame into, and the url @@ -195,7 +198,7 @@ class Postmate { */ sendHandshake(url) { const childOrigin = resolveOrigin(url); - return new Promise((resolve, reject) => { + return new Postmate.Promise((resolve, reject) => { const reply = e => { if (!sanitize(e, childOrigin)) return false; if (e.data.postmate === 'handshake-reply') { @@ -251,7 +254,7 @@ Postmate.Model = class Model { * @return {Promise} Resolves an object that exposes an API for the Child */ sendHandshakeReply() { - return new Promise((resolve, reject) => { + return new Postmate.Promise((resolve, reject) => { const shake = e => { if (e.data.postmate === 'handshake') { log('Child: Received handshake from Parent'); diff --git a/test/fixtures/child.html b/test/fixtures/child.html index 2c338930..98643882 100644 --- a/test/fixtures/child.html +++ b/test/fixtures/child.html @@ -15,8 +15,8 @@ window.onerror = function () { console.log.apply(console, arguments); }; - + - - + +