Comparing version 0.1.2 to 0.1.3
@@ -7,2 +7,4 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
@@ -17,3 +19,3 @@ | ||
var Framesg = function () { | ||
function Framesg(otherFrame, namespace) { | ||
function Framesg(otherFrame, FMNamespace) { | ||
var _this = this; | ||
@@ -26,3 +28,9 @@ | ||
this.other = otherFrame; | ||
this.namespace = namespace; | ||
if ((typeof FMNamespace === 'undefined' ? 'undefined' : _typeof(FMNamespace)) === 'object') { | ||
this.receiveNamespace = FMNamespace.receive; | ||
this.sendNamespace = FMNamespace.send; | ||
} else { | ||
this.receiveNamespace = new RegExp('^' + FMNamespace + '$'); | ||
this.sendNamespace = FMNamespace; | ||
} | ||
this.handlers = Object.assign({}, handlers); | ||
@@ -45,3 +53,3 @@ this._pending = {}; | ||
if (namespace === _this.namespace) { | ||
if (typeof namespace === 'string' && namespace.match(_this.receiveNamespace)) { | ||
@@ -112,3 +120,3 @@ if (fRequestID) { | ||
fResponseID: fRequestID, | ||
namespace: this.namespace, | ||
namespace: this.sendNamespace, | ||
success: true | ||
@@ -133,3 +141,3 @@ }, attrs), '*'); | ||
msgType: msgType, | ||
namespace: this.namespace, | ||
namespace: this.sendNamespace, | ||
args: Array.prototype.slice.call(arguments, 1) | ||
@@ -136,0 +144,0 @@ }, '*'); |
let reqCounter = 1; | ||
export default class Framesg { | ||
constructor(otherFrame, namespace, handlers={}) { | ||
constructor(otherFrame, FMNamespace, handlers={}) { | ||
this.other = otherFrame; | ||
this.namespace = namespace; | ||
if (typeof FMNamespace === 'object') { | ||
this.receiveNamespace = FMNamespace.receive; | ||
this.sendNamespace = FMNamespace.send; | ||
} else { | ||
this.receiveNamespace = new RegExp(`^${FMNamespace}$`); | ||
this.sendNamespace = FMNamespace; | ||
} | ||
this.handlers = Object.assign({}, handlers); | ||
@@ -19,3 +25,3 @@ this._pending = {}; | ||
// only handle msgs for this channel | ||
if (namespace === this.namespace) { | ||
if (typeof namespace === 'string' && namespace.match(this.receiveNamespace)) { | ||
@@ -74,3 +80,3 @@ if (fRequestID) { | ||
fResponseID: fRequestID, | ||
namespace: this.namespace, | ||
namespace: this.sendNamespace, | ||
success: true, | ||
@@ -90,3 +96,3 @@ }, attrs), '*'); | ||
msgType, | ||
namespace: this.namespace, | ||
namespace: this.sendNamespace, | ||
args: Array.prototype.slice.call(arguments, 1), | ||
@@ -93,0 +99,0 @@ }, '*'); |
{ | ||
"name": "framesg", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "request/response communication to/from iframes", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
@@ -26,3 +26,3 @@ # framesg | ||
``` | ||
The first argument is the window/iframe to communicate with (typically `window.parent` within an iframe, and `iframeEl.contentWindow` within a parent where `iframeEl` is the iframe's DOM element). The second argument (`'my-channel'` in the example above) is a user-supplied namespace. The third argument is an object mapping endpoint names to handler functions. | ||
The first argument is the window/iframe to communicate with (typically `window.parent` within an iframe, and `iframeEl.contentWindow` within a parent where `iframeEl` is the iframe's DOM element). The second argument (`'my-app'` in the example above) is a user-supplied namespace. The third argument is an object mapping endpoint names to handler functions. | ||
@@ -29,0 +29,0 @@ Send a message to another frame: |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
10931
199