worker-timers
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -19,7 +19,6 @@ (function (global, factory) { | ||
var worker = new Worker(url); | ||
worker.addEventListener('message', function (_ref) { | ||
var _ref$data = _ref.data, | ||
id = _ref$data.id, | ||
type = _ref$data.type; | ||
worker.addEventListener('message', function (_a) { | ||
var _b = _a.data, | ||
id = _b.id, | ||
type = _b.type; | ||
if (type === 'interval') { | ||
@@ -31,5 +30,5 @@ var func = scheduledIntervalFunctions.get(id); | ||
} else if (type === 'timeout') { | ||
var _func = scheduledTimeoutFunctions.get(id); | ||
if (_func) { | ||
_func(); | ||
var func = scheduledTimeoutFunctions.get(id); | ||
if (func) { | ||
func(); | ||
// A timeout can be savely deleted because it is only called once. | ||
@@ -36,0 +35,0 @@ scheduledTimeoutFunctions.delete(id); |
@@ -1,1 +0,1 @@ | ||
!function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):b(a.workerTimers=a.workerTimers||{})}(this,function(a){"use strict";var b=Number.MAX_SAFE_INTEGER||Math.pow(2,53)-1,c=function(a){for(var c=Math.round(Math.random()*b);a.has(c);)c=Math.round(Math.random()*b);return c},d=new Blob(['!function(){"use strict";var a=new Map,b=new Map,c=function a(b,c,d,e){var f="performance"in self?performance.now():Date.now();f>d?postMessage({id:c,type:e}):b.set(c,setTimeout(a,d-f,b,c,d,e))};addEventListener("message",function(d){var e=d.data,f=e.action,g=e.delay,h=e.id,i=e.now,j=e.type;if("clear"===f){var k=void 0;"interval"===j?void 0!==(k=a.get(h))&&(clearTimeout(k),a.delete(h)):"timeout"===j&&void 0!==(k=b.get(h))&&(clearTimeout(k),b.delete(h))}else if("set"===f){var l=void 0;if("performance"in self){var m=performance.now(),n=Math.max(0,m-i);g-=n,l=m}else l=Date.now();var o=l+g;"interval"===j?a.set(h,setTimeout(c,g,a,h,o,j)):"timeout"===j&&b.set(h,setTimeout(c,g,b,h,o,j))}})}();'],{type:"application/javascript"}),e=URL.createObjectURL(d),f=function(a){var b=new Map,d=new Map,e=new Worker(a);return e.addEventListener("message",function(a){var c=a.data,e=c.id,f=c.type;if("interval"===f){var g=b.get(e);g&&g()}else if("timeout"===f){var h=d.get(e);h&&(h(),d.delete(e))}}),{clearInterval:function(a){b.delete(a),e.postMessage({action:"clear",id:a,type:"interval"})},clearTimeout:function(a){d.delete(a),e.postMessage({action:"clear",id:a,type:"timeout"})},setInterval:function(a,d){var f=c(b);return b.set(f,function(){a(),e.postMessage({action:"set",delay:d,id:f,now:performance.now(),type:"interval"})}),e.postMessage({action:"set",delay:d,id:f,now:performance.now(),type:"interval"}),f},setTimeout:function(a,b){var f=c(d);return d.set(f,a),e.postMessage({action:"set",delay:b,id:f,now:performance.now(),type:"timeout"}),f}}}(e),g=f.clearInterval,h=f.clearTimeout,i=f.setInterval,j=f.setTimeout;a.clearInterval=g,a.clearTimeout=h,a.setInterval=i,a.setTimeout=j,Object.defineProperty(a,"__esModule",{value:!0})}); | ||
!function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):b(a.workerTimers=a.workerTimers||{})}(this,function(a){"use strict";var b=Number.MAX_SAFE_INTEGER||Math.pow(2,53)-1,c=function(a){for(var c=Math.round(Math.random()*b);a.has(c);)c=Math.round(Math.random()*b);return c},d=new Blob(['!function(){"use strict";var a=new Map,b=new Map,c=function a(b,c,d,e){var f="performance"in self?performance.now():Date.now();f>d?postMessage({id:c,type:e}):b.set(c,setTimeout(a,d-f,b,c,d,e))};addEventListener("message",function(d){var e=d.data,f=e.action,g=e.delay,h=e.id,i=e.now,j=e.type;if("clear"===f){var k=void 0;"interval"===j?void 0!==(k=a.get(h))&&(clearTimeout(k),a.delete(h)):"timeout"===j&&void 0!==(k=b.get(h))&&(clearTimeout(k),b.delete(h))}else if("set"===f){var l=void 0;if("performance"in self){var m=performance.now(),n=Math.max(0,m-i);g-=n,l=m}else l=Date.now();var o=l+g;"interval"===j?a.set(h,setTimeout(c,g,a,h,o,j)):"timeout"===j&&b.set(h,setTimeout(c,g,b,h,o,j))}})}();'],{type:"application/javascript"}),e=URL.createObjectURL(d),f=function(a){var b=new Map,d=new Map,e=new Worker(a);return e.addEventListener("message",function(a){var c=a.data,e=c.id,f=c.type;if("interval"===f){var g=b.get(e);g&&g()}else if("timeout"===f){var g=d.get(e);g&&(g(),d.delete(e))}}),{clearInterval:function(a){b.delete(a),e.postMessage({action:"clear",id:a,type:"interval"})},clearTimeout:function(a){d.delete(a),e.postMessage({action:"clear",id:a,type:"timeout"})},setInterval:function(a,d){var f=c(b);return b.set(f,function(){a(),e.postMessage({action:"set",delay:d,id:f,now:performance.now(),type:"interval"})}),e.postMessage({action:"set",delay:d,id:f,now:performance.now(),type:"interval"}),f},setTimeout:function(a,b){var f=c(d);return d.set(f,a),e.postMessage({action:"set",delay:b,id:f,now:performance.now(),type:"timeout"}),f}}}(e),g=f.clearInterval,h=f.clearTimeout,i=f.setInterval,j=f.setTimeout;a.clearInterval=g,a.clearTimeout=h,a.setInterval=i,a.setTimeout=j,Object.defineProperty(a,"__esModule",{value:!0})}); |
@@ -48,2 +48,3 @@ { | ||
"build/es2015/", | ||
"build/esm/", | ||
"src/" | ||
@@ -63,3 +64,3 @@ ], | ||
"main": "build/es5/bundle.js", | ||
"module": "build/es2015/module.js", | ||
"module": "build/esm/module.js", | ||
"name": "worker-timers", | ||
@@ -76,3 +77,3 @@ "repository": { | ||
"types": "build/es2015/module.d.ts", | ||
"version": "4.0.0" | ||
"version": "4.0.1" | ||
} |
18176
18
194