"use strict";function _inherits(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(t.__proto__=e)}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}!function(t){function e(t,e,r,o){var a=Object.create((e||n).prototype);return a._invoke=s(t,r||null,new p(o||[])),a}function r(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(n){return{type:"throw",arg:n}}}function n(){}function o(){}function a(){}function i(t){["next","throw","return"].forEach(function(e){t[e]=function(t){return this._invoke(e,t)}})}function u(t){this.arg=t}function c(t){function e(e,r){var n=t[e](r),i=n.value;return i instanceof u?Promise.resolve(i.arg).then(o,a):Promise.resolve(i).then(function(t){return n.value=t,n},a)}function r(t,r){var o=n?n.then(function(){return e(t,r)}):new Promise(function(n){n(e(t,r))});return n=o["catch"](i),o}"object"==typeof process&&process.domain&&(e=process.domain.bind(e));var n,o=e.bind(t,"next"),a=e.bind(t,"throw"),i=e.bind(t,"return");this._invoke=r}function s(t,e,n){var o=w;return function(a,i){if(o===k)throw new Error("Generator is already running");if(o===L)return y();for(;;){var u=n.delegate;if(u){if("return"===a||"throw"===a&&u.iterator[a]===d){n.delegate=null;var c=u.iterator["return"];if(c){var s=r(c,u.iterator,i);if("throw"===s.type){a="throw",i=s.arg;continue}}if("return"===a)continue}var s=r(u.iterator[a],u.iterator,i);if("throw"===s.type){n.delegate=null,a="throw",i=s.arg;continue}a="next",i=d;var f=s.arg;if(!f.done)return o=x,f;n[u.resultName]=f.value,n.next=u.nextLoc,n.delegate=null}if("next"===a)o===x?n.sent=i:delete n.sent;else if("throw"===a){if(o===w)throw o=L,i;n.dispatchException(i)&&(a="next",i=d)}else"return"===a&&n.abrupt("return",i);o=k;var s=r(t,e,n);if("normal"===s.type){o=n.done?L:x;var f={value:s.arg,done:n.done};if(s.arg!==R)return f;n.delegate&&"next"===a&&(i=d)}else"throw"===s.type&&(o=L,a="throw",i=s.arg)}}}function f(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function l(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function p(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(f,this),this.reset()}function h(t){if(t){var e=t[g];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,n=function o(){for(;++re;++e)this[t]=null},stop:function(){this.done=!0;var t=this.tryEntries[0],e=t.completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(t){function e(e,n){return a.type="throw",a.arg=t,r.next=e,!!n}if(this.done)throw t;for(var r=this,n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n],a=o.completion;if("root"===o.tryLoc)return e("end");if(o.tryLoc<=this.prev){var i=v.call(o,"catchLoc"),u=v.call(o,"finallyLoc");if(i&&u){if(this.prev=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&v.call(n,"finallyLoc")&&this.prev=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),l(r),R}},"catch":function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;l(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:h(t),resultName:e,nextLoc:r},R}}}("object"==typeof global?global:"object"==typeof window?window:"object"==typeof self?self:void 0);var AbstractTransaction=function(){function t(){_classCallCheck(this,t)}return t.prototype.addOperation=regeneratorRuntime.mark(function e(t){var r;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.delegateYield(this.getState(t.uid[0]),"t0",1);case 1:if(r=e.t0,null==r&&(r={user:t.uid[0],clock:0}),t.uid[1]!==r.clock){e.next=9;break}return r.clock++,e.delegateYield(this.setState(r),"t1",6);case 6:return e.abrupt("return",!0);case 9:return e.abrupt("return",!1);case 10:case"end":return e.stop()}},e,this)}),t}(),IndexedDB=function(){var t=function(t){function e(r){_classCallCheck(this,e),t.call(this),this.transaction=r,this.sv=r.objectStore("StateVector"),this.ob=r.objectStore("OperationBuffer")}return _inherits(e,t),e.prototype.setOperation=regeneratorRuntime.mark(function r(t){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.delegateYield(regeneratorRuntime.mark(function r(){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:case"end":return t.stop()}},r,this)})(),"t0",1);case 1:return e.next=3,this.ob.put(t);case 3:return e.abrupt("return",t);case 4:case"end":return e.stop()}},r,this)}),e.prototype.getOperation=regeneratorRuntime.mark(function n(t){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.ob.get(t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},n,this)}),e.prototype.setState=regeneratorRuntime.mark(function o(t){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sv.put(t);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},o,this)}),e.prototype.getState=regeneratorRuntime.mark(function a(t){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sv.get(t);case 2:if(e.t0=e.sent,e.t0){e.next=5;break}e.t0={user:t,clock:0};case 5:return e.abrupt("return",e.t0);case 6:case"end":return e.stop()}},a,this)}),e.prototype.getStateVector=regeneratorRuntime.mark(function i(){var t,e,r;return regeneratorRuntime.wrap(function(n){for(;;)switch(n.prev=n.next){case 0:t=[],e=this.sv.openCursor();case 2:return n.next=4,e;case 4:if(n.t0=r=n.sent,null==n.t0){n.next=10;break}t.push(r.value),r["continue"](),n.next=2;break;case 10:return n.abrupt("return",t);case 11:case"end":return n.stop()}},i,this)}),e.prototype.getStateSet=regeneratorRuntime.mark(function u(){var t,e,r,n,o,a,i;return regeneratorRuntime.wrap(function(u){for(;;)switch(u.prev=u.next){case 0:return u.delegateYield(this.getStateVector(),"t0",1);case 1:t=u.t0,e={},r=t,n=Array.isArray(r),o=0,r=n?r:r[Symbol.iterator]();case 4:if(!n){u.next=10;break}if(!(o>=r.length)){u.next=7;break}return u.abrupt("break",18);case 7:a=r[o++],u.next=14;break;case 10:if(o=r.next(),!o.done){u.next=13;break}return u.abrupt("break",18);case 13:a=o.value;case 14:i=a,e[i.user]=i.clock;case 16:u.next=4;break;case 18:return u.abrupt("return",e);case 19:case"end":return u.stop()}},u,this)}),e.prototype.getOperations=regeneratorRuntime.mark(function c(t){var e,r,n,o,a,i,u,s,f,l,p,h,y;return regeneratorRuntime.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:return null==t&&(t={}),e=[],c.delegateYield(this.getStateVector(),"t0",3);case 3:r=c.t0,n=r,o=Array.isArray(n),a=0,n=o?n:n[Symbol.iterator]();case 5:if(!o){c.next=11;break}if(!(a>=n.length)){c.next=8;break}return c.abrupt("break",31);case 8:i=n[a++],c.next=15;break;case 11:if(a=n.next(),!a.done){c.next=14;break}return c.abrupt("break",31);case 14:i=a.value;case 15:u=i,s=u.user,f=t[s]||0,l=u.clock,p=IDBKeyRange.bound([s,f],[s,l]),h=this.ob.openCursor(p);case 21:return c.next=23,h;case 23:if(c.t1=y=c.sent,null==c.t1){c.next=29;break}e.push(y.value),y["continue"](),c.next=21;break;case 29:c.next=5;break;case 31:return c.abrupt("return",e);case 32:case"end":return c.stop()}},c,this)}),e}(AbstractTransaction),e=function(){function e(t){var r=this;_classCallCheck(this,e),this.whenReadyListeners=[],this.namespace=t,this.ready=!1;var n=indexedDB.open(t);n.onerror=function(){throw new Error("Couldn't open the IndexedDB database!")},n.onsuccess=function(t){r.db=t.target.result,r.whenReadyListeners.forEach(function(t){setTimeout(t,0)}),r.whenReadyListeners=null,r.ready=!0},n.onupgradeneeded=function(t){var e=t.target.result;e.createObjectStore("OperationBuffer",{keyPath:"uid"}),e.createObjectStore("StateVector",{keyPath:"user"})}}return e.prototype.whenReady=function(t){this.ready?setTimeout(t,0):this.whenReadyListeners.push(t)},e.prototype.requestTransaction=function(e){var r=this;this.whenReady(function(){function n(t){var e=t.value;t.done||(e.constructor===IDBRequest||e.constructor===IDBCursor||e.constructor===IDBOpenDBRequest?(e.onsuccess=function(){n(a.next(e.result))},e.onerror=function(t){a["throw"](t)}):a["throw"]("You can not yield this type!"))}var o=new t(r.db.transaction(["OperationBuffer","StateVector"],"readwrite")),a=e.apply(o);n(a.next())})},e.prototype.removeDatabase=regeneratorRuntime.mark(function r(){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,indexedDB.deleteDatabase(this.namespace);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},r,this)}),e}();return e}(),OperationBuffer=function t(){_classCallCheck(this,t)},Operation=function(){function t(e){_classCallCheck(this,t),this.i=e.i}return t.prototype.yay=function(){return this.i},t}(); //# sourceMappingURL=y.js.map