Skip to content

Commit

Permalink
added check to process only widtalk messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Preet Shihn authored and Preet Shihn committed May 22, 2018
1 parent 10e5d0f commit 83d843a
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# windtalk 🗣💨

Micro lib (742 bytes gzipped) that provides a seamless way for two <b><i>WIND</i></b>ows to <b><i>TALK</i></b> to each other.
Micro lib (764 bytes gzipped) that provides a seamless way for two <b><i>WIND</i></b>ows to <b><i>TALK</i></b> to each other.

* Work with objects/functions defined in another window/iframe.
* All calls are async. Works great with async/await.
Expand Down
16 changes: 8 additions & 8 deletions dist/windtalk.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var windtalk = (function (exports) {
this.c = 0; // counter
this.cbs = {}; // callbacks
self.addEventListener('message', event => {
const id = event.data && event.data.id;
const id = event.data && event.data.windtalk && event.data.id;
const cb = id && this.cbs[id];
if (cb) {
delete this.cbs[id];
Expand All @@ -49,7 +49,7 @@ var windtalk = (function (exports) {
const id = `${this.uid}-${++this.c}`;
return new Promise((resolve, reject) => {
this.cbs[id] = [resolve, reject];
this.w.postMessage(Object.assign({}, request, { id, args, target: this.uid }), '*');
this.w.postMessage(Object.assign({}, request, { id, args, target: this.uid, windtalk: true }), '*');
});
}
}
Expand All @@ -62,12 +62,12 @@ var windtalk = (function (exports) {
const _target = target;
const w = endPoint || window.top;
self.addEventListener('message', async event => {
const data = event.data || {};
data.path = data.path || [];
const reduce = list => list.reduce((o, prop) => (o ? o[prop] : o), _target);
const id = data.id;
if (id && data.type) {
const msg = { id };
if (event.data && event.data.id && event.data.type && event.data.windtalk) {
const data = event.data;
data.path = data.path || [];
const id = data.id;
const reduce = list => list.reduce((o, prop) => (o ? o[prop] : o), _target);
const msg = { id, windtalk: true };
const ref = reduce(data.path);
const refParent = reduce(data.path.slice(0, -1));
switch (data.type) {
Expand Down
2 changes: 1 addition & 1 deletion dist/windtalk.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions dist/windtalk.umd.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
this.c = 0; // counter
this.cbs = {}; // callbacks
self.addEventListener('message', event => {
const id = event.data && event.data.id;
const id = event.data && event.data.windtalk && event.data.id;
const cb = id && this.cbs[id];
if (cb) {
delete this.cbs[id];
Expand All @@ -52,7 +52,7 @@
const id = `${this.uid}-${++this.c}`;
return new Promise((resolve, reject) => {
this.cbs[id] = [resolve, reject];
this.w.postMessage(Object.assign({}, request, { id, args, target: this.uid }), '*');
this.w.postMessage(Object.assign({}, request, { id, args, target: this.uid, windtalk: true }), '*');
});
}
}
Expand All @@ -65,12 +65,12 @@
const _target = target;
const w = endPoint || window.top;
self.addEventListener('message', async event => {
const data = event.data || {};
data.path = data.path || [];
const reduce = list => list.reduce((o, prop) => (o ? o[prop] : o), _target);
const id = data.id;
if (id && data.type) {
const msg = { id };
if (event.data && event.data.id && event.data.type && event.data.windtalk) {
const data = event.data;
data.path = data.path || [];
const id = data.id;
const reduce = list => list.reduce((o, prop) => (o ? o[prop] : o), _target);
const msg = { id, windtalk: true };
const ref = reduce(data.path);
const refParent = reduce(data.path.slice(0, -1));
switch (data.type) {
Expand Down
2 changes: 1 addition & 1 deletion dist/windtalk.umd.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Remote {
this.c = 0; // counter
this.cbs = {} // callbacks
self.addEventListener('message', event => {
const id = event.data && event.data.id;
const id = event.data && event.data.windtalk && event.data.id;
const cb = id && this.cbs[id];
if (cb) {
delete this.cbs[id];
Expand All @@ -46,7 +46,7 @@ class Remote {
const id = `${this.uid}-${++this.c}`;
return new Promise((resolve, reject) => {
this.cbs[id] = [resolve, reject];
this.w.postMessage(Object.assign({}, request, { id, args, target: this.uid }), '*');
this.w.postMessage(Object.assign({}, request, { id, args, target: this.uid, windtalk: true }), '*');
});
}
}
Expand All @@ -59,12 +59,12 @@ export function expose(target, endPoint) {
const _target = target;
const w = endPoint || window.top;
self.addEventListener('message', async event => {
const data = event.data || {};
data.path = data.path || [];
const reduce = list => list.reduce((o, prop) => (o ? o[prop] : o), _target);
const id = data.id;
if (id && data.type) {
const msg = { id };
if (event.data && event.data.id && event.data.type && event.data.windtalk) {
const data = event.data;
data.path = data.path || [];
const id = data.id;
const reduce = list => list.reduce((o, prop) => (o ? o[prop] : o), _target);
const msg = { id, windtalk: true };
const ref = reduce(data.path);
const refParent = reduce(data.path.slice(0, -1));
switch (data.type) {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "windtalk",
"version": "1.0.1",
"version": "1.0.2",
"description": "Simplest way to communicate between windows/iframes.",
"main": "dist/windtalk.umd.js",
"browser": "dist/dist/windtalk.min.js",
Expand Down

0 comments on commit 83d843a

Please sign in to comment.