Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the process.env check #206

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.9kb`</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
125 changes: 34 additions & 91 deletions build/postmate.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@
emit: 1,
reply: 1,
request: 1
/**
* Ensures that a message is safe to interpret
* @param {Object} message The postmate message being sent
* @param {String|Boolean} allowedOrigin The whitelisted origin or false to skip origin check
* @return {Boolean}
*/

};
/**
* Ensures that a message is safe to interpret
* @param {Object} message The postmate message being sent
* @param {String|Boolean} allowedOrigin The whitelisted origin or false to skip origin check
* @return {Boolean}
*/

var sanitize = function sanitize(message, allowedOrigin) {
if (typeof allowedOrigin === 'string' && message.origin !== allowedOrigin) return false;
if (!message.data) return false;
Expand All @@ -101,9 +101,7 @@
* @param {Object} info Information on the consumer
*/

var ParentAPI =
/*#__PURE__*/
function () {
var ParentAPI = /*#__PURE__*/function () {
function ParentAPI(info) {
var _this = this;

Expand All @@ -112,11 +110,8 @@
this.child = info.child;
this.childOrigin = info.childOrigin;
this.events = {};

{
log('Parent: Registering API');
log('Parent: Awaiting messages...');
}
log('Parent: Registering API');
log('Parent: Awaiting messages...');

this.listener = function (e) {
if (!sanitize(e, _this.childOrigin)) return false;
Expand All @@ -129,9 +124,7 @@
name = _ref.name;

if (e.data.postmate === 'emit') {
{
log("Parent: Received event emission: " + name);
}
log("Parent: Received event emission: " + name);

if (name in _this.events) {
_this.events[name].forEach(function (callback) {
Expand All @@ -142,10 +135,7 @@
};

this.parent.addEventListener('message', this.listener, false);

{
log('Parent: Awaiting event emissions from Child');
}
log('Parent: Awaiting event emissions from Child');
}

var _proto = ParentAPI.prototype;
Expand Down Expand Up @@ -197,10 +187,7 @@
};

_proto.destroy = function destroy() {
{
log('Parent: Destroying Postmate instance');
}

log('Parent: Destroying Postmate instance');
window.removeEventListener('message', this.listener, false);
this.frame.parentNode.removeChild(this.frame);
};
Expand All @@ -212,29 +199,19 @@
* @param {Object} info Information on the consumer
*/

var ChildAPI =
/*#__PURE__*/
function () {
var ChildAPI = /*#__PURE__*/function () {
function ChildAPI(info) {
var _this3 = this;

this.model = info.model;
this.parent = info.parent;
this.parentOrigin = info.parentOrigin;
this.child = info.child;

{
log('Child: Registering API');
log('Child: Awaiting messages...');
}

log('Child: Registering API');
log('Child: Awaiting messages...');
this.child.addEventListener('message', function (e) {
if (!sanitize(e, _this3.parentOrigin)) return;

{
log('Child: Received request', e.data);
}

log('Child: Received request', e.data);
var _e$data = e.data,
property = _e$data.property,
uid = _e$data.uid,
Expand Down Expand Up @@ -264,10 +241,7 @@
var _proto2 = ChildAPI.prototype;

_proto2.emit = function emit(name, data) {
{
log("Child: Emitting Event \"" + name + "\"", data);
}

log("Child: Emitting Event \"" + name + "\"", data);
this.parent.postMessage({
postmate: 'emit',
type: messageType,
Expand All @@ -281,13 +255,11 @@
return ChildAPI;
}();
/**
* The entry point of the Parent.
* The entry point of the Parent.
* @type {Class}
*/

var Postmate =
/*#__PURE__*/
function () {
var Postmate = /*#__PURE__*/function () {
// eslint-disable-line no-undef
// Internet Explorer craps itself

Expand Down Expand Up @@ -335,41 +307,28 @@

if (e.data.postmate === 'handshake-reply') {
clearInterval(responseInterval);

{
log('Parent: Received handshake reply from Child');
}
log('Parent: Received handshake reply from Child');

_this4.parent.removeEventListener('message', reply, false);

_this4.childOrigin = e.origin;

{
log('Parent: Saving Child origin', _this4.childOrigin);
}

log('Parent: Saving Child origin', _this4.childOrigin);
return resolve(new ParentAPI(_this4));
} // Might need to remove since parent might be receiving different messages
// from different hosts


{
log('Parent: Invalid handshake reply');
}

log('Parent: Invalid handshake reply');
return reject('Failed handshake');
};

_this4.parent.addEventListener('message', reply, false);

var doSend = function doSend() {
attempt++;

{
log("Parent: Sending handshake attempt " + attempt, {
childOrigin: childOrigin
});
}
log("Parent: Sending handshake attempt " + attempt, {
childOrigin: childOrigin
});

_this4.child.postMessage({
postmate: 'handshake',
Expand All @@ -393,12 +352,9 @@
_this4.frame.addEventListener('load', loaded);
}

{
log('Parent: Loading frame', {
url: url
});
}

log('Parent: Loading frame', {
url: url
});
_this4.frame.src = url;
});
};
Expand All @@ -421,9 +377,7 @@
}
}();

Postmate.Model =
/*#__PURE__*/
function () {
Postmate.Model = /*#__PURE__*/function () {
/**
* Initializes the child, model, parent, and responds to the Parents handshake
* @param {Object} model Hash of values, functions, or promises
Expand Down Expand Up @@ -453,16 +407,11 @@
}

if (e.data.postmate === 'handshake') {
{
log('Child: Received handshake from Parent');
}
log('Child: Received handshake from Parent');

_this5.child.removeEventListener('message', shake, false);

{
log('Child: Sending handshake reply to Parent');
}

log('Child: Sending handshake reply to Parent');
e.source.postMessage({
postmate: 'handshake-reply',
type: messageType
Expand All @@ -475,16 +424,10 @@
Object.keys(defaults).forEach(function (key) {
_this5.model[key] = defaults[key];
});

{
log('Child: Inherited and extended model from Parent');
}
}

{
log('Child: Saving Parent origin', _this5.parentOrigin);
log('Child: Inherited and extended model from Parent');
}

log('Child: Saving Parent origin', _this5.parentOrigin);
return resolve(new ChildAPI(_this5));
}

Expand Down
Loading