2 lines
15 KiB
JavaScript
2 lines
15 KiB
JavaScript
"use strict";function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(e.__proto__=t)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}!function(e){function t(e,t,r,a){var i=Object.create((t||n).prototype);return i._invoke=c(e,r||null,new p(a||[])),i}function r(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(n){return{type:"throw",arg:n}}}function n(){}function a(){}function i(){}function o(e){["next","throw","return"].forEach(function(t){e[t]=function(e){return this._invoke(t,e)}})}function s(e){this.arg=e}function u(e){function t(t,r){var n=e[t](r),o=n.value;return o instanceof s?Promise.resolve(o.arg).then(a,i):Promise.resolve(o).then(function(e){return n.value=e,n},i)}function r(e,r){var a=n?n.then(function(){return t(e,r)}):new Promise(function(n){n(t(e,r))});return n=a["catch"](o),a}"object"==typeof process&&process.domain&&(t=process.domain.bind(t));var n,a=t.bind(e,"next"),i=t.bind(e,"throw"),o=t.bind(e,"return");this._invoke=r}function c(e,t,n){var a=m;return function(i,o){if(a===w)throw new Error("Generator is already running");if(a===R)return d();for(;;){var s=n.delegate;if(s){if("return"===i||"throw"===i&&s.iterator[i]===y){n.delegate=null;var u=s.iterator["return"];if(u){var c=r(u,s.iterator,o);if("throw"===c.type){i="throw",o=c.arg;continue}}if("return"===i)continue}var c=r(s.iterator[i],s.iterator,o);if("throw"===c.type){n.delegate=null,i="throw",o=c.arg;continue}i="next",o=y;var l=c.arg;if(!l.done)return a=k,l;n[s.resultName]=l.value,n.next=s.nextLoc,n.delegate=null}if("next"===i)a===k?n.sent=o:delete n.sent;else if("throw"===i){if(a===m)throw a=R,o;n.dispatchException(o)&&(i="next",o=y)}else"return"===i&&n.abrupt("return",o);a=w;var c=r(e,t,n);if("normal"===c.type){a=n.done?R:k;var l={value:c.arg,done:n.done};if(c.arg!==S)return l;n.delegate&&"next"===i&&(o=y)}else"throw"===c.type&&(a=R,i="throw",o=c.arg)}}}function l(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function f(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function p(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(l,this),this.reset()}function h(e){if(e){var t=e[b];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,n=function a(){for(;++r<e.length;)if(g.call(e,r))return a.value=e[r],a.done=!1,a;return a.value=y,a.done=!0,a};return n.next=n}}return{next:d}}function d(){return{value:y,done:!0}}var y,g=Object.prototype.hasOwnProperty,b="function"==typeof Symbol&&Symbol.iterator||"@@iterator",v="object"==typeof module,x=e.regeneratorRuntime;if(x)return void(v&&(module.exports=x));x=e.regeneratorRuntime=v?module.exports:{},x.wrap=t;var m="suspendedStart",k="suspendedYield",w="executing",R="completed",S={},O=i.prototype=n.prototype;a.prototype=O.constructor=i,i.constructor=a,a.displayName="GeneratorFunction",x.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return t?t===a||"GeneratorFunction"===(t.displayName||t.name):!1},x.mark=function(e){return e.__proto__=i,e.prototype=Object.create(O),e},x.awrap=function(e){return new s(e)},o(u.prototype),x.async=function(e,r,n,a){var i=new u(t(e,r,n,a));return x.isGeneratorFunction(r)?i:i.next().then(function(e){return e.done?e.value:i.next()})},o(O),O[b]=function(){return this},O.toString=function(){return"[object Generator]"},x.keys=function(e){var t=[];for(var r in e)t.push(r);return t.reverse(),function n(){for(;t.length;){var r=t.pop();if(r in e)return n.value=r,n.done=!1,n}return n.done=!0,n}},x.values=h,p.prototype={constructor:p,reset:function(){this.prev=0,this.next=0,this.sent=y,this.done=!1,this.delegate=null,this.tryEntries.forEach(f);for(var e,t=0;g.call(this,e="t"+t)||20>t;++t)this[e]=null},stop:function(){this.done=!0;var e=this.tryEntries[0],t=e.completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){function t(t,n){return i.type="throw",i.arg=e,r.next=t,!!n}if(this.done)throw e;for(var r=this,n=this.tryEntries.length-1;n>=0;--n){var a=this.tryEntries[n],i=a.completion;if("root"===a.tryLoc)return t("end");if(a.tryLoc<=this.prev){var o=g.call(a,"catchLoc"),s=g.call(a,"finallyLoc");if(o&&s){if(this.prev<a.catchLoc)return t(a.catchLoc,!0);if(this.prev<a.finallyLoc)return t(a.finallyLoc)}else if(o){if(this.prev<a.catchLoc)return t(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return t(a.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&g.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var a=n;break}}a&&("break"===e||"continue"===e)&&a.tryLoc<=t&&t<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=e,i.arg=t,a?this.next=a.finallyLoc:this.complete(i),S},complete:function(e,t){if("throw"===e.type)throw e.arg;"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=e.arg,this.next="end"):"normal"===e.type&&t&&(this.next=t)},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),f(r),S}},"catch":function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;f(r)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:h(e),resultName:t,nextLoc:r},S}}}("object"==typeof global?global:"object"==typeof window?window:"object"==typeof self?self:void 0);var AbstractTransaction=function(){function e(t){_classCallCheck(this,e),this.store=t}return e.prototype.addOperation=regeneratorRuntime.mark(function t(e){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(r=this.getState(e.id[0]),e.id[1]!==r.clock){t.next=8;break}return r.clock++,t.delegateYield(this.setState(r),"t0",4);case 4:return this.store.operationAdded(e),t.abrupt("return",!0);case 8:return t.abrupt("return",!1);case 9:case"end":return t.stop()}},t,this)}),e}(),AbstractOperationStore=function(){function e(){_classCallCheck(this,e),this.listenersById={},this.listenersByIdExecuteNow=[],this.listenersByIdRequestPending=!1}return e.prototype.whenOperationsExist=function(e,t,r){if(e.length>0)for(var n={f:t,args:r||[],missing:e.length},a=e,i=Array.isArray(a),o=0,a=i?a:a[Symbol.iterator]();;){var s;if(i){if(o>=a.length)break;s=a[o++]}else{if(o=a.next(),o.done)break;s=o.value}var u=s,c=JSON.stringify(u),l=this.listenersById[c];null==l&&(l=[],this.listenersById[c]=l),l.push(n)}else this.listenersByIdExecuteNow.push({f:t,args:r||[]});if(!this.listenersByIdRequestPending){this.listenersByIdRequestPending=!0;var f=this;this.requestTransaction(regeneratorRuntime.mark(function p(){var e,t,r,n,a,i,o,s,u,c,l,h,d,y;return regeneratorRuntime.wrap(function(p){for(;;)switch(p.prev=p.next){case 0:e=f.listenersByIdExecuteNow,f.listenersByIdExecuteNow=[],t=f.listenersById,f.listenersById={},f.listenersByIdRequestPending=!1,r=e,n=Array.isArray(r),a=0,r=n?r:r[Symbol.iterator]();case 6:if(!n){p.next=12;break}if(!(a>=r.length)){p.next=9;break}return p.abrupt("break",20);case 9:i=r[a++],p.next=16;break;case 12:if(a=r.next(),!a.done){p.next=15;break}return p.abrupt("break",20);case 15:i=a.value;case 16:return o=i,p.delegateYield(o.f.apply(this,o.args),"t0",18);case 18:p.next=6;break;case 20:p.t1=regeneratorRuntime.keys(t);case 21:if((p.t2=p.t1()).done){p.next=48;break}return s=p.t2.value,u=t[s],c=JSON.parse(s),p.delegateYield(this.getOperation(c),"t3",26);case 26:if(null!=p.t3){p.next=30;break}f.listenersById[s]=u,p.next=46;break;case 30:l=u,h=Array.isArray(l),d=0,l=h?l:l[Symbol.iterator]();case 31:if(!h){p.next=37;break}if(!(d>=l.length)){p.next=34;break}return p.abrupt("break",46);case 34:y=l[d++],p.next=41;break;case 37:if(d=l.next(),!d.done){p.next=40;break}return p.abrupt("break",46);case 40:y=d.value;case 41:if(o=y,0!==--o.missing){p.next=44;break}return p.delegateYield(o.f.apply(this,o.args),"t4",44);case 44:p.next=31;break;case 46:p.next=21;break;case 48:case"end":return p.stop()}},p,this)}))}},e.prototype.operationAdded=function(e){var t=this.listenersById[e.id];if(null!=t)for(var r=t,n=Array.isArray(r),a=0,r=n?r:r[Symbol.iterator]();;){var i;if(n){if(a>=r.length)break;i=r[a++]}else{if(a=r.next(),a.done)break;i=a.value}var o=i;0===--o.missing&&this.whenOperationsExist([],o.f,o.args)}},e}(),Struct={Operation:{create:regeneratorRuntime.mark(function e(t,r){var n;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.delegateYield(this.getState(r),"t0",1);case 1:return n=e.t0,t.id=[r,n.clock],e.delegateYield(this.addOperation(t),"t1",4);case 4:return e.abrupt("return",e.t1);case 5:case"end":return e.stop()}},e,this)})},Insert:{create:regeneratorRuntime.mark(function t(e,r,n,a){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return e.left=n?n.id:null,e.origin=e.left,e.right=a?a.id:null,e.type="Insert",t.delegateYield(Struct.Operation.create(e,r),"t0",5);case 5:if(null==n){t.next=8;break}return n.right=e.id,t.delegateYield(this.setOperation(n),"t1",8);case 8:if(null==a){t.next=11;break}return a.left=e.id,t.delegateYield(this.setOperation(a),"t2",11);case 11:return t.abrupt("return",e);case 12:case"end":return t.stop()}},t,this)}),requiredOps:function(e,t){return t.push(e.left),t.push(e.right),t},execute:regeneratorRuntime.mark(function r(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",e);case 1:case"end":return t.stop()}},r,this)})}},GeneratorFunction=regeneratorRuntime.mark(function n(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:case"end":return e.stop()}},n,this)}).constructor,IndexedDB=function(){var e=function(e){function t(r){_classCallCheck(this,t),e.call(this,r),this.transaction=r.db.transaction(["OperationStore","StateVector"],"readwrite"),this.sv=this.transaction.objectStore("StateVector"),this.os=this.transaction.objectStore("OperationStore"),this.buffer={}}return _inherits(t,e),t.prototype.setOperation=regeneratorRuntime.mark(function r(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.os.put(e);case 2:return this.buffer[JSON.stringify(e.id)]=e,t.abrupt("return",e);case 4:case"end":return t.stop()}},r,this)}),t.prototype.getOperation=regeneratorRuntime.mark(function n(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(t=this.buffer[JSON.stringify(e)],null!=t){r.next=6;break}return r.next=4,this.os.get(e);case 4:t=r.sent,this.buffer[JSON.stringify(e)]=t;case 6:return r.abrupt("return",t);case 7:case"end":return r.stop()}},n,this)}),t.prototype.removeOperation=regeneratorRuntime.mark(function a(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return this.buffer[JSON.stringify(e)]=null,t.next=3,this.os["delete"](e);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}},a,this)}),t.prototype.setState=regeneratorRuntime.mark(function i(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.sv.put(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},i,this)}),t.prototype.getState=regeneratorRuntime.mark(function o(e){var t;return regeneratorRuntime.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:return r.next=2,this.sv.get(e);case 2:if(r.t0=t=r.sent,null==r.t0){r.next=7;break}return r.abrupt("return",t);case 7:return r.abrupt("return",{user:e,clock:0});case 8:case"end":return r.stop()}},o,this)}),t.prototype.getStateVector=regeneratorRuntime.mark(function s(){var e,t,r;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:e=[],t=this.sv.openCursor();case 2:return n.next=4,t;case 4:if(n.t0=r=n.sent,null==n.t0){n.next=10;break}e.push(r.value),r["continue"](),n.next=2;break;case 10:return n.abrupt("return",e);case 11:case"end":return n.stop()}},s,this)}),t.prototype.getStateSet=regeneratorRuntime.mark(function u(){var e,t,r,n,a,i,o;return regeneratorRuntime.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.delegateYield(this.getStateVector(),"t0",1);case 1:e=s.t0,t={},r=e,n=Array.isArray(r),a=0,r=n?r:r[Symbol.iterator]();case 4:if(!n){s.next=10;break}if(!(a>=r.length)){s.next=7;break}return s.abrupt("break",18);case 7:i=r[a++],s.next=14;break;case 10:if(a=r.next(),!a.done){s.next=13;break}return s.abrupt("break",18);case 13:i=a.value;case 14:o=i,t[o.user]=o.clock;case 16:s.next=4;break;case 18:return s.abrupt("return",t);case 19:case"end":return s.stop()}},u,this)}),t.prototype.getOperations=regeneratorRuntime.mark(function c(e){var t,r,n,a,i,o,s,u,l,f,p,h,d;return regeneratorRuntime.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:return null==e&&(e={}),t=[],c.delegateYield(this.getStateVector(),"t0",3);case 3:r=c.t0,n=r,a=Array.isArray(n),i=0,n=a?n:n[Symbol.iterator]();case 5:if(!a){c.next=11;break}if(!(i>=n.length)){c.next=8;break}return c.abrupt("break",31);case 8:o=n[i++],c.next=15;break;case 11:if(i=n.next(),!i.done){c.next=14;break}return c.abrupt("break",31);case 14:o=i.value;case 15:s=o,u=s.user,l=e[u]||0,f=s.clock,p=IDBKeyRange.bound([u,l],[u,f]),h=this.os.openCursor(p);case 21:return c.next=23,h;case 23:if(c.t1=d=c.sent,null==c.t1){c.next=29;break}t.push(d.value),d["continue"](),c.next=21;break;case 29:c.next=5;break;case 31:return c.abrupt("return",t);case 32:case"end":return c.stop()}},c,this)}),t}(AbstractTransaction),t=function(t){function r(n){function a(e){var t=e.value;e.done||(t.constructor===IDBRequest||t.constructor===IDBCursor?(t.onsuccess=function(){a(o.next(t.result))},t.onerror=function(e){o["throw"](e)}):t===i.transactionQueue?t.queue.length>0?a(o.next(t.queue.shift())):t.onRequest=function(){t.onRequest=null,a(o.next(t.queue.shift()))}:t.constructor===IDBOpenDBRequest?(t.onsuccess=function(e){var t=e.target.result;a(o.next(t))},t.onerror=function(){o["throw"]("Couldn't open IndexedDB database!")},t.onupgradeneeded=function(e){var t=e.target.result;t.createObjectStore("OperationStore",{keyPath:"id"}),t.createObjectStore("StateVector",{keyPath:"user"})}):o["throw"]("You can not yield this type!"))}_classCallCheck(this,r),t.call(this),this.namespace=n,this.transactionQueue={queue:[],onRequest:null};var i=this,o=regeneratorRuntime.mark(function s(){var t,r,a,o;return regeneratorRuntime.wrap(function(s){for(;;)switch(s.prev=s.next){case 0:return s.next=2,indexedDB.open(n,3);case 2:i.db=s.sent,t=i.transactionQueue,r=null,a=!0;case 6:if(!a){s.next=14;break}return s.next=9,t;case 9:return o=s.sent,r=new e(i),s.delegateYield(o.call(r),"t0",12);case 12:s.next=6;break;case 14:case"end":return s.stop()}},s,this)})();a(o.next())}return _inherits(r,t),r.prototype.requestTransaction=function(e){this.transactionQueue.queue.push(e),null!=this.transactionQueue.onRequest&&this.transactionQueue.onRequest()},r.prototype.removeDatabase=regeneratorRuntime.mark(function n(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.db.close(),e.next=3,indexedDB.deleteDatabase(this.namespace);case 3:case"end":return e.stop()}},n,this)}),r}(AbstractOperationStore);return t}();
|
|
//# sourceMappingURL=y.js.map
|