-
Notifications
You must be signed in to change notification settings - Fork 10
/
WebWorker.min.js
1 lines (1 loc) · 991 Bytes
/
WebWorker.min.js
1
Ext.define("Ext.ux.WebWorker",{alias:"widget.webworker",mixins:{observable:"Ext.util.Observable"},config:{blob:"",file:"",itemId:""},constructor:function(a){var b=this;b.initConfig(a),b.mixins.observable.constructor.call(b,a),b.addEvents("error","message");try{if(Ext.isEmpty(b.getFile())){var c=window.URL||window.webkitURL,d=new Blob([b.getBlob()],{type:"text/plain"}),e=c.createObjectURL(d);b.worker=new Worker(e)}else b.worker=new Worker(b.getFile());b.id=Ext.id(),b.worker.onmessage=function(a){b.fireEvent("message",b,a.data),Ext.isObject(a.data)&&b.fireEvent(a.data.event,b,a.data.data)},b.worker.onerror=function(a){b.fireEvent("error",b,a)}}catch(f){return Ext.Error.raise(f),null}return b},send:function(a,b){var c=this;1===arguments.length?Ext.isString(a)?c.worker.postMessage(a):Ext.Error.raise("String expected!"):arguments.length>=2&&(Ext.isString(a)&&(a=[a]),Ext.each(a,function(a){var d={event:a,data:b};c.worker.postMessage(d)}))},stop:function(){this.worker.terminate()}});