Comparing version 1.2.0 to 2.0.0
@@ -20,6 +20,5 @@ /** | ||
export declare const Comlink: { | ||
proxy: (endpoint: Endpoint) => Function; | ||
proxy: (endpoint: Window | Endpoint) => Function; | ||
proxyValue: (obj: {}) => {}; | ||
expose: (rootObj: Object | Function, endpoint: Endpoint) => void; | ||
windowEndpoint: (w: Window) => Endpoint; | ||
expose: (rootObj: Object | Function, endpoint: Window | Endpoint) => void; | ||
}; |
@@ -0,1 +1,13 @@ | ||
/** | ||
* Copyright 2017 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
export const Comlink = (function () { | ||
@@ -7,2 +19,4 @@ const uid = Math.floor(Math.random() * Number.MAX_SAFE_INTEGER); | ||
/* export */ function proxy(endpoint) { | ||
if (isWindow(endpoint)) | ||
endpoint = windowEndpoint(endpoint); | ||
if (!isEndpoint(endpoint)) | ||
@@ -28,2 +42,4 @@ throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined'); | ||
/* export */ function expose(rootObj, endpoint) { | ||
if (isWindow(endpoint)) | ||
endpoint = windowEndpoint(endpoint); | ||
if (!isEndpoint(endpoint)) | ||
@@ -66,3 +82,3 @@ throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined'); | ||
} | ||
/* export */ function windowEndpoint(w) { | ||
function windowEndpoint(w) { | ||
if (self.constructor.name !== 'Window') | ||
@@ -102,2 +118,5 @@ throw Error('self is not a window'); | ||
} | ||
function isWindow(endpoint) { | ||
return endpoint.constructor.name === 'Window'; | ||
} | ||
/** | ||
@@ -219,3 +238,3 @@ * `pingPongMessage` sends a `postMessage` and waits for a reply. Replies are | ||
} | ||
return { proxy, proxyValue, expose, windowEndpoint }; | ||
return { proxy, proxyValue, expose }; | ||
})(); |
@@ -1,1 +0,1 @@ | ||
export const Comlink=function(){function a(b){if(!d(b))throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined');return e(b),k(async(c,d,e)=>{const f=await i(b,{type:c,callPath:d,argumentsList:e},n(e)),g=f.data;return'PROXY'===g.type?a(g.endpoint):g.obj})}function b(a){return a[t]=!0,a}function c(a,g){if(!d(g))throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined');e(g),f(g,async function(d){if(!d.data.id)return;const e=d.data;let f=await e.callPath.reduce((a,b)=>a[b],a);switch(e.type){case'APPLY':{e.callPath.pop();const c=await e.callPath.reduce((a,b)=>a[b],a),d='AsyncGeneratorFunction'===f.constructor.name;f=await f.apply(c,e.argumentsList),d&&(f=b(f))}case'GET':{const a=p(f);return a.id=e.id,g.postMessage(a,n([a]))}case'CONSTRUCT':{const a=new f(...(e.argumentsList||[])),{port1:b,port2:d}=new MessageChannel;return c(a,b),g.postMessage({id:e.id,type:'PROXY',endpoint:d},[d])}}})}function d(a){return'addEventListener'in a&&'removeEventListener'in a&&'postMessage'in a}function e(a){h(a)&&a.start()}function f(a,b){a.addEventListener('message',b)}function g(a,b){a.removeEventListener('message',b)}function h(a){return'MessagePort'===a.constructor.name}function i(a,b,c){const d=`${q}-${r++}`;return new Promise((e)=>{f(a,function b(c){c.data.id!==d||(g(a,b),e(c))}),b=Object.assign({},b,{id:d}),a.postMessage(b,c)})}function j(){return'asyncIterator'in Symbol}function k(a){let b=[];return new Proxy(function(){},{construct(c,d){const e=a('CONSTRUCT',b,d);return b=[],e},apply(c,d,e){if('bind'===b[b.length-1]){const c=b.slice();return b=[],(...b)=>a('APPLY',c.slice(0,-1),b)}const f=a('APPLY',b,e);return b=[],f},get(c,d,e){if('then'===d&&0===b.length)return{then:()=>e};if(j()&&d===Symbol.asyncIterator)return()=>e;if('then'===d){const c=a('GET',b);return b=[],Promise.resolve(c).then.bind(c)}return b.push(d),e}})}function l(a){return s.some((b)=>a instanceof b)}function*m(a){if(!a)return;if('string'==typeof a)return;yield a;let b=Object.values(a);Array.isArray(a)&&(b=a);for(const c of b)yield*m(c)}function n(a){const b=[];for(const c of m(a))l(c)&&b.push(c);return b}function o(a){return a&&a[t]}function p(a){if(o(a)){const{port1:b,port2:d}=new MessageChannel;return c(a,b),{type:'PROXY',endpoint:d}}return{type:'OBJECT',obj:a}}const q=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER);let r=0;const s=[ArrayBuffer,MessagePort],t=Symbol('proxyValue');return{proxy:a,proxyValue:b,expose:c,windowEndpoint:function(a){if('Window'!==self.constructor.name)throw Error('self is not a window');return{addEventListener:self.addEventListener.bind(self),removeEventListener:self.removeEventListener.bind(self),postMessage:(b,c)=>a.postMessage(b,'*',c)}}}}(); | ||
export const Comlink=function(){function a(b){if(j(b)&&(b=d(b)),!e(b))throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined');return f(b),m(async(c,d,e)=>{const f=await k(b,{type:c,callPath:d,argumentsList:e},p(e)),g=f.data;return'PROXY'===g.type?a(g.endpoint):g.obj})}function b(a){return a[v]=!0,a}function c(a,h){if(j(h)&&(h=d(h)),!e(h))throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined');f(h),g(h,async function(d){if(!d.data.id)return;const e=d.data;let f=await e.callPath.reduce((a,b)=>a[b],a);switch(e.type){case'APPLY':{e.callPath.pop();const c=await e.callPath.reduce((a,b)=>a[b],a),d='AsyncGeneratorFunction'===f.constructor.name;f=await f.apply(c,e.argumentsList),d&&(f=b(f))}case'GET':{const a=r(f);return a.id=e.id,h.postMessage(a,p([a]))}case'CONSTRUCT':{const a=new f(...(e.argumentsList||[])),{port1:b,port2:d}=new MessageChannel;return c(a,b),h.postMessage({id:e.id,type:'PROXY',endpoint:d},[d])}}})}function d(a){if('Window'!==self.constructor.name)throw Error('self is not a window');return{addEventListener:self.addEventListener.bind(self),removeEventListener:self.removeEventListener.bind(self),postMessage:(b,c)=>a.postMessage(b,'*',c)}}function e(a){return'addEventListener'in a&&'removeEventListener'in a&&'postMessage'in a}function f(a){i(a)&&a.start()}function g(a,b){a.addEventListener('message',b)}function h(a,b){a.removeEventListener('message',b)}function i(a){return'MessagePort'===a.constructor.name}function j(a){return'Window'===a.constructor.name}function k(a,b,c){const d=`${s}-${t++}`;return new Promise((e)=>{g(a,function b(c){c.data.id!==d||(h(a,b),e(c))}),b=Object.assign({},b,{id:d}),a.postMessage(b,c)})}function l(){return'asyncIterator'in Symbol}function m(a){let b=[];return new Proxy(function(){},{construct(c,d){const e=a('CONSTRUCT',b,d);return b=[],e},apply(c,d,e){if('bind'===b[b.length-1]){const c=b.slice();return b=[],(...b)=>a('APPLY',c.slice(0,-1),b)}const f=a('APPLY',b,e);return b=[],f},get(c,d,e){if('then'===d&&0===b.length)return{then:()=>e};if(l()&&d===Symbol.asyncIterator)return()=>e;if('then'===d){const c=a('GET',b);return b=[],Promise.resolve(c).then.bind(c)}return b.push(d),e}})}function n(a){return u.some((b)=>a instanceof b)}function*o(a){if(!a)return;if('string'==typeof a)return;yield a;let b=Object.values(a);Array.isArray(a)&&(b=a);for(const c of b)yield*o(c)}function p(a){const b=[];for(const c of o(a))n(c)&&b.push(c);return b}function q(a){return a&&a[v]}function r(a){if(q(a)){const{port1:b,port2:d}=new MessageChannel;return c(a,b),{type:'PROXY',endpoint:d}}return{type:'OBJECT',obj:a}}const s=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER);let t=0;const u=[ArrayBuffer,MessagePort],v=Symbol('proxyValue');return{proxy:a,proxyValue:b,expose:c}}(); |
"use strict"; | ||
/** | ||
* Copyright 2017 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
@@ -9,2 +21,4 @@ self.Comlink = (function () { | ||
/* export */ function proxy(endpoint) { | ||
if (isWindow(endpoint)) | ||
endpoint = windowEndpoint(endpoint); | ||
if (!isEndpoint(endpoint)) | ||
@@ -30,2 +44,4 @@ throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined'); | ||
/* export */ function expose(rootObj, endpoint) { | ||
if (isWindow(endpoint)) | ||
endpoint = windowEndpoint(endpoint); | ||
if (!isEndpoint(endpoint)) | ||
@@ -68,3 +84,3 @@ throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined'); | ||
} | ||
/* export */ function windowEndpoint(w) { | ||
function windowEndpoint(w) { | ||
if (self.constructor.name !== 'Window') | ||
@@ -104,2 +120,5 @@ throw Error('self is not a window'); | ||
} | ||
function isWindow(endpoint) { | ||
return endpoint.constructor.name === 'Window'; | ||
} | ||
/** | ||
@@ -221,3 +240,3 @@ * `pingPongMessage` sends a `postMessage` and waits for a reply. Replies are | ||
} | ||
return { proxy, proxyValue, expose, windowEndpoint }; | ||
return { proxy, proxyValue, expose }; | ||
})(); |
@@ -1,1 +0,1 @@ | ||
'use strict';self.Comlink=function(){function a(b){if(!d(b))throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined');return e(b),k(async(c,d,e)=>{const f=await i(b,{type:c,callPath:d,argumentsList:e},n(e)),g=f.data;return'PROXY'===g.type?a(g.endpoint):g.obj})}function b(a){return a[t]=!0,a}function c(a,g){if(!d(g))throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined');e(g),f(g,async function(d){if(!d.data.id)return;const e=d.data;let f=await e.callPath.reduce((a,b)=>a[b],a);switch(e.type){case'APPLY':{e.callPath.pop();const c=await e.callPath.reduce((a,b)=>a[b],a),d='AsyncGeneratorFunction'===f.constructor.name;f=await f.apply(c,e.argumentsList),d&&(f=b(f))}case'GET':{const a=p(f);return a.id=e.id,g.postMessage(a,n([a]))}case'CONSTRUCT':{const a=new f(...(e.argumentsList||[])),{port1:b,port2:d}=new MessageChannel;return c(a,b),g.postMessage({id:e.id,type:'PROXY',endpoint:d},[d])}}})}function d(a){return'addEventListener'in a&&'removeEventListener'in a&&'postMessage'in a}function e(a){h(a)&&a.start()}function f(a,b){a.addEventListener('message',b)}function g(a,b){a.removeEventListener('message',b)}function h(a){return'MessagePort'===a.constructor.name}function i(a,b,c){const d=`${q}-${r++}`;return new Promise((e)=>{f(a,function b(c){c.data.id!==d||(g(a,b),e(c))}),b=Object.assign({},b,{id:d}),a.postMessage(b,c)})}function j(){return'asyncIterator'in Symbol}function k(a){let b=[];return new Proxy(function(){},{construct(c,d){const e=a('CONSTRUCT',b,d);return b=[],e},apply(c,d,e){if('bind'===b[b.length-1]){const c=b.slice();return b=[],(...b)=>a('APPLY',c.slice(0,-1),b)}const f=a('APPLY',b,e);return b=[],f},get(c,d,e){if('then'===d&&0===b.length)return{then:()=>e};if(j()&&d===Symbol.asyncIterator)return()=>e;if('then'===d){const c=a('GET',b);return b=[],Promise.resolve(c).then.bind(c)}return b.push(d),e}})}function l(a){return s.some((b)=>a instanceof b)}function*m(a){if(!a)return;if('string'==typeof a)return;yield a;let b=Object.values(a);Array.isArray(a)&&(b=a);for(const c of b)yield*m(c)}function n(a){const b=[];for(const c of m(a))l(c)&&b.push(c);return b}function o(a){return a&&a[t]}function p(a){if(o(a)){const{port1:b,port2:d}=new MessageChannel;return c(a,b),{type:'PROXY',endpoint:d}}return{type:'OBJECT',obj:a}}const q=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER);let r=0;const s=[ArrayBuffer,MessagePort],t=Symbol('proxyValue');return{proxy:a,proxyValue:b,expose:c,windowEndpoint:function(a){if('Window'!==self.constructor.name)throw Error('self is not a window');return{addEventListener:self.addEventListener.bind(self),removeEventListener:self.removeEventListener.bind(self),postMessage:(b,c)=>a.postMessage(b,'*',c)}}}}(); | ||
'use strict';self.Comlink=function(){function a(b){if(j(b)&&(b=d(b)),!e(b))throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined');return f(b),m(async(c,d,e)=>{const f=await k(b,{type:c,callPath:d,argumentsList:e},p(e)),g=f.data;return'PROXY'===g.type?a(g.endpoint):g.obj})}function b(a){return a[v]=!0,a}function c(a,h){if(j(h)&&(h=d(h)),!e(h))throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined');f(h),g(h,async function(d){if(!d.data.id)return;const e=d.data;let f=await e.callPath.reduce((a,b)=>a[b],a);switch(e.type){case'APPLY':{e.callPath.pop();const c=await e.callPath.reduce((a,b)=>a[b],a),d='AsyncGeneratorFunction'===f.constructor.name;f=await f.apply(c,e.argumentsList),d&&(f=b(f))}case'GET':{const a=r(f);return a.id=e.id,h.postMessage(a,p([a]))}case'CONSTRUCT':{const a=new f(...(e.argumentsList||[])),{port1:b,port2:d}=new MessageChannel;return c(a,b),h.postMessage({id:e.id,type:'PROXY',endpoint:d},[d])}}})}function d(a){if('Window'!==self.constructor.name)throw Error('self is not a window');return{addEventListener:self.addEventListener.bind(self),removeEventListener:self.removeEventListener.bind(self),postMessage:(b,c)=>a.postMessage(b,'*',c)}}function e(a){return'addEventListener'in a&&'removeEventListener'in a&&'postMessage'in a}function f(a){i(a)&&a.start()}function g(a,b){a.addEventListener('message',b)}function h(a,b){a.removeEventListener('message',b)}function i(a){return'MessagePort'===a.constructor.name}function j(a){return'Window'===a.constructor.name}function k(a,b,c){const d=`${s}-${t++}`;return new Promise((e)=>{g(a,function b(c){c.data.id!==d||(h(a,b),e(c))}),b=Object.assign({},b,{id:d}),a.postMessage(b,c)})}function l(){return'asyncIterator'in Symbol}function m(a){let b=[];return new Proxy(function(){},{construct(c,d){const e=a('CONSTRUCT',b,d);return b=[],e},apply(c,d,e){if('bind'===b[b.length-1]){const c=b.slice();return b=[],(...b)=>a('APPLY',c.slice(0,-1),b)}const f=a('APPLY',b,e);return b=[],f},get(c,d,e){if('then'===d&&0===b.length)return{then:()=>e};if(l()&&d===Symbol.asyncIterator)return()=>e;if('then'===d){const c=a('GET',b);return b=[],Promise.resolve(c).then.bind(c)}return b.push(d),e}})}function n(a){return u.some((b)=>a instanceof b)}function*o(a){if(!a)return;if('string'==typeof a)return;yield a;let b=Object.values(a);Array.isArray(a)&&(b=a);for(const c of b)yield*o(c)}function p(a){const b=[];for(const c of o(a))n(c)&&b.push(c);return b}function q(a){return a&&a[v]}function r(a){if(q(a)){const{port1:b,port2:d}=new MessageChannel;return c(a,b),{type:'PROXY',endpoint:d}}return{type:'OBJECT',obj:a}}const s=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER);let t=0;const u=[ArrayBuffer,MessagePort],v=Symbol('proxyValue');return{proxy:a,proxyValue:b,expose:c}}(); |
@@ -0,1 +1,13 @@ | ||
/** | ||
* Copyright 2017 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
(function (factory) { | ||
@@ -18,2 +30,4 @@ if (typeof module === "object" && typeof module.exports === "object") { | ||
/* export */ function proxy(endpoint) { | ||
if (isWindow(endpoint)) | ||
endpoint = windowEndpoint(endpoint); | ||
if (!isEndpoint(endpoint)) | ||
@@ -39,2 +53,4 @@ throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined'); | ||
/* export */ function expose(rootObj, endpoint) { | ||
if (isWindow(endpoint)) | ||
endpoint = windowEndpoint(endpoint); | ||
if (!isEndpoint(endpoint)) | ||
@@ -77,3 +93,3 @@ throw Error('endpoint does not have all of addEventListener, removeEventListener and postMessage defined'); | ||
} | ||
/* export */ function windowEndpoint(w) { | ||
function windowEndpoint(w) { | ||
if (self.constructor.name !== 'Window') | ||
@@ -113,2 +129,5 @@ throw Error('self is not a window'); | ||
} | ||
function isWindow(endpoint) { | ||
return endpoint.constructor.name === 'Window'; | ||
} | ||
/** | ||
@@ -230,4 +249,4 @@ * `pingPongMessage` sends a `postMessage` and waits for a reply. Replies are | ||
} | ||
return { proxy, proxyValue, expose, windowEndpoint }; | ||
return { proxy, proxyValue, expose }; | ||
})(); | ||
}); |
@@ -1,1 +0,1 @@ | ||
(function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);b!==void 0&&(module.exports=b)}else"function"==typeof define&&define.amd&&define(["require","exports"],a)})(function(a,b){"use strict";Object.defineProperty(b,"__esModule",{value:!0}),b.Comlink=function(){function a(b){if(!d(b))throw Error("endpoint does not have all of addEventListener, removeEventListener and postMessage defined");return e(b),k(async(c,d,e)=>{const f=await i(b,{type:c,callPath:d,argumentsList:e},n(e)),g=f.data;return"PROXY"===g.type?a(g.endpoint):g.obj})}function b(a){return a[t]=!0,a}function c(a,g){if(!d(g))throw Error("endpoint does not have all of addEventListener, removeEventListener and postMessage defined");e(g),f(g,async function(d){if(!d.data.id)return;const e=d.data;let f=await e.callPath.reduce((a,b)=>a[b],a);switch(e.type){case"APPLY":{e.callPath.pop();const c=await e.callPath.reduce((a,b)=>a[b],a),d="AsyncGeneratorFunction"===f.constructor.name;f=await f.apply(c,e.argumentsList),d&&(f=b(f))}case"GET":{const a=p(f);return a.id=e.id,g.postMessage(a,n([a]))}case"CONSTRUCT":{const a=new f(...(e.argumentsList||[])),{port1:b,port2:d}=new MessageChannel;return c(a,b),g.postMessage({id:e.id,type:"PROXY",endpoint:d},[d])}}})}function d(a){return"addEventListener"in a&&"removeEventListener"in a&&"postMessage"in a}function e(a){h(a)&&a.start()}function f(a,b){a.addEventListener("message",b)}function g(a,b){a.removeEventListener("message",b)}function h(a){return"MessagePort"===a.constructor.name}function i(a,b,c){const d=`${q}-${r++}`;return new Promise((e)=>{f(a,function b(c){c.data.id!==d||(g(a,b),e(c))}),b=Object.assign({},b,{id:d}),a.postMessage(b,c)})}function j(){return"asyncIterator"in Symbol}function k(a){let b=[];return new Proxy(function(){},{construct(c,d){const e=a("CONSTRUCT",b,d);return b=[],e},apply(c,d,e){if("bind"===b[b.length-1]){const c=b.slice();return b=[],(...b)=>a("APPLY",c.slice(0,-1),b)}const f=a("APPLY",b,e);return b=[],f},get(c,d,e){if("then"===d&&0===b.length)return{then:()=>e};if(j()&&d===Symbol.asyncIterator)return()=>e;if("then"===d){const c=a("GET",b);return b=[],Promise.resolve(c).then.bind(c)}return b.push(d),e}})}function l(a){return s.some((b)=>a instanceof b)}function*m(a){if(!a)return;if("string"==typeof a)return;yield a;let b=Object.values(a);Array.isArray(a)&&(b=a);for(const c of b)yield*m(c)}function n(a){const b=[];for(const c of m(a))l(c)&&b.push(c);return b}function o(a){return a&&a[t]}function p(a){if(o(a)){const{port1:b,port2:d}=new MessageChannel;return c(a,b),{type:"PROXY",endpoint:d}}return{type:"OBJECT",obj:a}}const q=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER);let r=0;const s=[ArrayBuffer,MessagePort],t=Symbol("proxyValue");return{proxy:a,proxyValue:b,expose:c,windowEndpoint:function(a){if("Window"!==self.constructor.name)throw Error("self is not a window");return{addEventListener:self.addEventListener.bind(self),removeEventListener:self.removeEventListener.bind(self),postMessage:(b,c)=>a.postMessage(b,"*",c)}}}}()}); | ||
(function(a){if("object"==typeof module&&"object"==typeof module.exports){var b=a(require,exports);b!==void 0&&(module.exports=b)}else"function"==typeof define&&define.amd&&define(["require","exports"],a)})(function(a,b){"use strict";Object.defineProperty(b,"__esModule",{value:!0}),b.Comlink=function(){function a(b){if(j(b)&&(b=d(b)),!e(b))throw Error("endpoint does not have all of addEventListener, removeEventListener and postMessage defined");return f(b),m(async(c,d,e)=>{const f=await k(b,{type:c,callPath:d,argumentsList:e},p(e)),g=f.data;return"PROXY"===g.type?a(g.endpoint):g.obj})}function b(a){return a[v]=!0,a}function c(a,h){if(j(h)&&(h=d(h)),!e(h))throw Error("endpoint does not have all of addEventListener, removeEventListener and postMessage defined");f(h),g(h,async function(d){if(!d.data.id)return;const e=d.data;let f=await e.callPath.reduce((a,b)=>a[b],a);switch(e.type){case"APPLY":{e.callPath.pop();const c=await e.callPath.reduce((a,b)=>a[b],a),d="AsyncGeneratorFunction"===f.constructor.name;f=await f.apply(c,e.argumentsList),d&&(f=b(f))}case"GET":{const a=r(f);return a.id=e.id,h.postMessage(a,p([a]))}case"CONSTRUCT":{const a=new f(...(e.argumentsList||[])),{port1:b,port2:d}=new MessageChannel;return c(a,b),h.postMessage({id:e.id,type:"PROXY",endpoint:d},[d])}}})}function d(a){if("Window"!==self.constructor.name)throw Error("self is not a window");return{addEventListener:self.addEventListener.bind(self),removeEventListener:self.removeEventListener.bind(self),postMessage:(b,c)=>a.postMessage(b,"*",c)}}function e(a){return"addEventListener"in a&&"removeEventListener"in a&&"postMessage"in a}function f(a){i(a)&&a.start()}function g(a,b){a.addEventListener("message",b)}function h(a,b){a.removeEventListener("message",b)}function i(a){return"MessagePort"===a.constructor.name}function j(a){return"Window"===a.constructor.name}function k(a,b,c){const d=`${s}-${t++}`;return new Promise((e)=>{g(a,function b(c){c.data.id!==d||(h(a,b),e(c))}),b=Object.assign({},b,{id:d}),a.postMessage(b,c)})}function l(){return"asyncIterator"in Symbol}function m(a){let b=[];return new Proxy(function(){},{construct(c,d){const e=a("CONSTRUCT",b,d);return b=[],e},apply(c,d,e){if("bind"===b[b.length-1]){const c=b.slice();return b=[],(...b)=>a("APPLY",c.slice(0,-1),b)}const f=a("APPLY",b,e);return b=[],f},get(c,d,e){if("then"===d&&0===b.length)return{then:()=>e};if(l()&&d===Symbol.asyncIterator)return()=>e;if("then"===d){const c=a("GET",b);return b=[],Promise.resolve(c).then.bind(c)}return b.push(d),e}})}function n(a){return u.some((b)=>a instanceof b)}function*o(a){if(!a)return;if("string"==typeof a)return;yield a;let b=Object.values(a);Array.isArray(a)&&(b=a);for(const c of b)yield*o(c)}function p(a){const b=[];for(const c of o(a))n(c)&&b.push(c);return b}function q(a){return a&&a[v]}function r(a){if(q(a)){const{port1:b,port2:d}=new MessageChannel;return c(a,b),{type:"PROXY",endpoint:d}}return{type:"OBJECT",obj:a}}const s=Math.floor(Math.random()*Number.MAX_SAFE_INTEGER);let t=0;const u=[ArrayBuffer,MessagePort],v=Symbol("proxyValue");return{proxy:a,proxyValue:b,expose:c}}()}); |
{ | ||
"name": "comlinkjs", | ||
"version": "1.2.0", | ||
"version": "2.0.0", | ||
"description": "", | ||
@@ -18,3 +18,3 @@ "main": "comlink.umd.js", | ||
"mangle_global": "sed -i .bak 's!exports.Comlink!self.Comlink!' dist/comlink.global.js && sed -i .bak 's!^.*\"__esModule\".*$!!' dist/comlink.global.js", | ||
"minify": "babili --minified -o dist/comlink.global.{min.,}js && babili --minified -o dist/comlink.es6.{min.,}js && babili --minified -o dist/comlink.umd.{min.,}js" | ||
"minify": "babili -o dist/comlink.global.{min.,}js && babili -o dist/comlink.es6.{min.,}js && babili -o dist/comlink.umd.{min.,}js" | ||
}, | ||
@@ -38,14 +38,18 @@ "keywords": [], | ||
"devDependencies": { | ||
"babili": "^0.1.4", | ||
"chai": "^4.1.1", | ||
"eslint": "^4.5.0", | ||
"eslint-config-google": "^0.9.1", | ||
"gsap": "^1.20.2", | ||
"karma": "^1.7.0", | ||
"karma-mocha": "^1.3.0", | ||
"mocha": "^3.5.0", | ||
"karma-chai": "^0.1.0", | ||
"karma-chrome-launcher": "^2.2.0", | ||
"karma-firefox-launcher": "^1.0.1", | ||
"karma-mocha": "^1.3.0", | ||
"karma-safari-launcher": "^1.0.0", | ||
"babili": "^0.1.4", | ||
"eslint": "^4.5.0", | ||
"eslint-config-google": "^0.9.1", | ||
"karma-typescript": "^3.0.5", | ||
"mocha": "^3.5.0", | ||
"postcss": "^6.0.11", | ||
"postcss-cssnext": "^3.0.2", | ||
"prismjs": "^1.7.0", | ||
"typescript": "^2.5.2", | ||
@@ -52,0 +56,0 @@ "typescript-eslint-parser": "^8.0.0" |
@@ -93,3 +93,3 @@ # Comlink | ||
The Comlink module exports 3 functions: | ||
The Comlink module exports 4 functions: | ||
@@ -114,13 +114,2 @@ ### `proxy(endpoint)` | ||
### `windowEndpoint(window)` | ||
If a window is to be used as an endpoint, the value must be wrapped by | ||
`windowEndpoint` so that messages will be dispatched correctly. | ||
```js | ||
const ifr = document.querySelector('iframe'); | ||
Comlink.proxy(Comlink.windowEndpoint(ifr.contentWindow)); | ||
``` | ||
[UMD]: https://github.com/umdjs/umd | ||
@@ -127,0 +116,0 @@ [transferable]: https://developer.mozilla.org/en-US/docs/Web/API/Transferable |
Sorry, the diff of this file is not supported yet
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
55388
775
18
119