2016-01-15 00:01:56 +01:00

3 lines
7.6 KiB
JavaScript

!function e(t,r,n){function o(u,i){if(!r[u]){if(!t[u]){var s="function"==typeof require&&require;if(!i&&s)return s(u,!0);if(a)return a(u,!0);var c=new Error("Cannot find module '"+u+"'");throw c.code="MODULE_NOT_FOUND",c}var l=r[u]={exports:{}};t[u][0].call(l.exports,function(e){var r=t[u][1][e];return o(r?r:e)},l,l.exports,e,t,r,n)}return r[u].exports}for(var a="function"==typeof require&&require,u=0;u<n.length;u++)o(n[u]);return o}({1:[function(e,t,r){"use strict";function n(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function o(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&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function u(e){var t=function(){function e(t,r){a(this,e),this.store=t.objectStore(r)}return s(e,[{key:"find",value:regeneratorRuntime.mark(function t(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.store.get(e);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)})},{key:"put",value:regeneratorRuntime.mark(function r(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.store.put(e);case 2:case"end":return t.stop()}},r,this)})},{key:"delete",value:regeneratorRuntime.mark(function n(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.store["delete"](e);case 2:case"end":return t.stop()}},n,this)})},{key:"findWithLowerBound",value:regeneratorRuntime.mark(function o(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.store.openCursor(window.IDBKeyRange.lowerBound(e));case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},o,this)})},{key:"findWithUpperBound",value:regeneratorRuntime.mark(function u(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.store.openCursor(window.IDBKeyRange.upperBound(e),"prev");case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},u,this)})},{key:"findNext",value:regeneratorRuntime.mark(function i(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(this.findWithLowerBound([e[0],e[1]+1]),"t0",1);case 1:return t.abrupt("return",t.t0);case 2:case"end":return t.stop()}},i,this)})},{key:"findPrev",value:regeneratorRuntime.mark(function c(e){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(this.findWithUpperBound([e[0],e[1]-1]),"t0",1);case 1:return t.abrupt("return",t.t0);case 2:case"end":return t.stop()}},c,this)})},{key:"iterate",value:regeneratorRuntime.mark(function l(e,t,r,n){var o,a;return regeneratorRuntime.wrap(function(u){for(;;)switch(u.prev=u.next){case 0:o=null,null!=t&&null!=r?o=window.IDBKeyRange.bound(t,r):null!=t?o=window.IDBKeyRange.lowerBound(t):null!=r&&(o=window.IDBKeyRange.upperBound(r)),a=this.store.openCursor(o);case 3:return u.next=5,a;case 5:if(u.t0=u.sent,null==u.t0){u.next=11;break}return u.delegateYield(n.call(e,a.result.value),"t1",8);case 8:a.result["continue"](),u.next=3;break;case 11:case"end":return u.stop()}},l,this)})}]),e}(),r=function(e){function r(e){a(this,r);var o=n(this,Object.getPrototypeOf(r).call(this,e)),u=e.db.transaction(["OperationStore","StateStore","DeleteStore"],"readwrite");return o.store=e,o.ss=new t(u,"StateStore"),o.os=new t(u,"OperationStore"),o.ds=new t(u,"DeleteStore"),o}return o(r,e),r}(e.Transaction),u=function(e){function t(e,r){a(this,t);var o=n(this,Object.getPrototypeOf(t).call(this,e,r));if(null==r&&(r={}),null==r.namespace||"string"!=typeof r.namespace)throw new Error("IndexedDB: expect a string (opts.namespace)!");o.namespace=r.namespace,null!=r.idbVersion?o.idbVersion=r.idbVersion:o.idbVersion=5;var u=o;o.requestTransaction(regeneratorRuntime.mark(function s(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,window.indexedDB.open(r.namespace,u.idbVersion);case 2:u.db=e.sent;case 3:case"end":return e.stop()}},s,this)})),r.cleanStart&&o.requestTransaction(regeneratorRuntime.mark(function c(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.os.store.clear();case 2:return e.next=4,this.ds.store.clear();case 4:return e.next=6,this.ss.store.clear();case 6:case"end":return e.stop()}},c,this)}));var i=[];return window.addEventListener("storage",function(e){e.key==="__YJS__"+u.namespace&&(i.push(e.newValue),1===i.length&&u.requestTransaction(regeneratorRuntime.mark(function t(){var e,r,n;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:e=i,i=[],t.t0=regeneratorRuntime.keys(e);case 3:if((t.t1=t.t0()).done){t.next=12;break}if(r=t.t1.value,n=JSON.parse(e[r]),"Delete"===n.struct){t.next=9;break}return t.delegateYield(this.getOperation(n.id),"t2",8);case 8:n=t.t2;case 9:return t.delegateYield(this.store.operationAdded(this,n,!0),"t3",10);case 10:t.next=3;break;case 12:case"end":return t.stop()}},t,this)})))},!1),o}return o(t,e),s(t,[{key:"operationAdded",value:regeneratorRuntime.mark(function u(e,r,n){return regeneratorRuntime.wrap(function(o){for(;;)switch(o.prev=o.next){case 0:return o.delegateYield(i(Object.getPrototypeOf(t.prototype),"operationAdded",this).call(this,e,r),"t0",1);case 1:n||(window.localStorage["__YJS__"+this.namespace]=JSON.stringify(r));case 2:case"end":return o.stop()}},u,this)})},{key:"transact",value:function(e){function t(u){var i=u.value;return u.done?(e=o.getNextRequest(),void(null!=e&&(null==n&&null!=o.db&&(n=new r(o)),a=e.call(n),t(a.next())))):void(i.constructor===window.IDBRequest?(i.onsuccess=function(){var e=i.result;null!=e&&e.constructor===window.IDBCursorWithValue&&(e=e.value),t(a.next(e))},i.onerror=function(e){a["throw"](e)}):i.constructor===window.IDBCursor?(i.onsuccess=function(){t(a.next(null!=i.result?i.result.value:null))},i.onerror=function(e){a["throw"](e)}):i.constructor===window.IDBOpenDBRequest?(i.onsuccess=function(e){var r=e.target.result;t(a.next(r))},i.onerror=function(){a["throw"]("Couldn't open IndexedDB database!")},i.onupgradeneeded=function(e){var t=e.target.result;try{t.createObjectStore("OperationStore",{keyPath:"id"}),t.createObjectStore("DeleteStore",{keyPath:"id"}),t.createObjectStore("StateStore",{keyPath:"id"})}catch(r){console.log("Store already exists!")}}):a["throw"]("You must not yield this type!"))}var n=null!=this.db?new r(this):null,o=this,a=e.call(n);t(a.next())}},{key:"destroy",value:regeneratorRuntime.mark(function c(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return this.db.close(),e.next=3,window.indexedDB.deleteDatabase(this.namespace);case 3:case"end":return e.stop()}},c,this)})}]),t}(e.AbstractDatabase);e.extend("indexeddb",u)}var i=function c(e,t,r){null===e&&(e=Function.prototype);var n=Object.getOwnPropertyDescriptor(e,t);if(void 0===n){var o=Object.getPrototypeOf(e);return null===o?void 0:c(o,t,r)}if("value"in n)return n.value;var a=n.get;if(void 0!==a)return a.call(r)},s=function(){function e(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();t.exports=u,"undefined"!=typeof Y&&u(Y)},{}]},{},[1]);
//# sourceMappingURL=y-indexeddb.js.map