yjs/y.js
2015-06-18 02:35:52 +02:00

2 lines
7.6 KiB
JavaScript

"use strict";function _classCallCheck(t,r){if(!(t instanceof r))throw new TypeError("Cannot call a class as a function")}!function(t){function r(t,r,e,o){var i=Object.create((r||n).prototype);return i._invoke=s(t,e||null,new h(o||[])),i}function e(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(n){return{type:"throw",arg:n}}}function n(){}function o(){}function i(){}function a(t){["next","throw","return"].forEach(function(r){t[r]=function(t){return this._invoke(r,t)}})}function c(t){this.arg=t}function u(t){function r(r,e){var n=t[r](e),a=n.value;return a instanceof c?Promise.resolve(a.arg).then(o,i):Promise.resolve(a).then(function(t){return n.value=t,n},i)}function e(t,e){var o=n?n.then(function(){return r(t,e)}):new Promise(function(n){n(r(t,e))});return n=o["catch"](a),o}"object"==typeof process&&process.domain&&(r=process.domain.bind(r));var n,o=r.bind(t,"next"),i=r.bind(t,"throw"),a=r.bind(t,"return");this._invoke=e}function s(t,r,n){var o=x;return function(i,a){if(o===L)throw new Error("Generator is already running");if(o===E)return y();for(;;){var c=n.delegate;if(c){if("return"===i||"throw"===i&&c.iterator[i]===v){n.delegate=null;var u=c.iterator["return"];if(u){var s=e(u,c.iterator,a);if("throw"===s.type){i="throw",a=s.arg;continue}}if("return"===i)continue}var s=e(c.iterator[i],c.iterator,a);if("throw"===s.type){n.delegate=null,i="throw",a=s.arg;continue}i="next",a=v;var f=s.arg;if(!f.done)return o=b,f;n[c.resultName]=f.value,n.next=c.nextLoc,n.delegate=null}if("next"===i)o===b?n.sent=a:delete n.sent;else if("throw"===i){if(o===x)throw o=E,a;n.dispatchException(a)&&(i="next",a=v)}else"return"===i&&n.abrupt("return",a);o=L;var s=e(t,r,n);if("normal"===s.type){o=n.done?E:b;var f={value:s.arg,done:n.done};if(s.arg!==O)return f;n.delegate&&"next"===i&&(a=v)}else"throw"===s.type&&(o=E,i="throw",a=s.arg)}}}function f(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function l(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function h(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(f,this),this.reset()}function p(t){if(t){var r=t[g];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var e=-1,n=function o(){for(;++e<t.length;)if(d.call(t,e))return o.value=t[e],o.done=!1,o;return o.value=v,o.done=!0,o};return n.next=n}}return{next:y}}function y(){return{value:v,done:!0}}var v,d=Object.prototype.hasOwnProperty,g="function"==typeof Symbol&&Symbol.iterator||"@@iterator",w="object"==typeof module,m=t.regeneratorRuntime;if(m)return void(w&&(module.exports=m));m=t.regeneratorRuntime=w?module.exports:{},m.wrap=r;var x="suspendedStart",b="suspendedYield",L="executing",E="completed",O={},k=i.prototype=n.prototype;o.prototype=k.constructor=i,i.constructor=o,o.displayName="GeneratorFunction",m.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return r?r===o||"GeneratorFunction"===(r.displayName||r.name):!1},m.mark=function(t){return t.__proto__=i,t.prototype=Object.create(k),t},m.awrap=function(t){return new c(t)},a(u.prototype),m.async=function(t,e,n,o){var i=new u(r(t,e,n,o));return m.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},a(k),k[g]=function(){return this},k.toString=function(){return"[object Generator]"},m.keys=function(t){var r=[];for(var e in t)r.push(e);return r.reverse(),function n(){for(;r.length;){var e=r.pop();if(e in t)return n.value=e,n.done=!1,n}return n.done=!0,n}},m.values=p,h.prototype={constructor:h,reset:function(){this.prev=0,this.next=0,this.sent=v,this.done=!1,this.delegate=null,this.tryEntries.forEach(l);for(var t,r=0;d.call(this,t="t"+r)||20>r;++r)this[t]=null},stop:function(){this.done=!0;var t=this.tryEntries[0],r=t.completion;if("throw"===r.type)throw r.arg;return this.rval},dispatchException:function(t){function r(r,n){return i.type="throw",i.arg=t,e.next=r,!!n}if(this.done)throw t;for(var e=this,n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n],i=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var a=d.call(o,"catchLoc"),c=d.call(o,"finallyLoc");if(a&&c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&d.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=r&&r<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=r,o?this.next=o.finallyLoc:this.complete(i),O},complete:function(t,r){if("throw"===t.type)throw t.arg;"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=t.arg,this.next="end"):"normal"===t.type&&r&&(this.next=r)},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),l(e),O}},"catch":function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;l(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,e){return this.delegate={iterator:p(t),resultName:r,nextLoc:e},O}}}("object"==typeof global?global:"object"==typeof window?window:"object"==typeof self?self:void 0);var IndexedDB=function(){var t=regeneratorRuntime.mark(function n(){return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:case"end":return t.stop()}},n,this)}).constructor,r=function(){function t(r){_classCallCheck(this,t),this.transaction=r}return t.prototype.setOperation=function(t){var r=this;return new Promise(function(e,n){var o=r.transaction.objectStore("OperationBuffer").put(t);o.onsuccess=function(){e(t)},o.onerror=function(){n("Could not set Operation!")}})},t.prototype.getOperation=function(t){var r=this;return new Promise(function(e,n){var o=r.transaction.objectStore("OperationBuffer").get(t);o.onsuccess=function(){e(o.result)},o.onerror=function(){n("Could not get Operation")}})},t.prototype.getOperations=function(){this.transaction.objectStore("OperationBuffer");return regeneratorRuntime.mark(function t(){var r;return regeneratorRuntime.wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getOperation(["u1",0]);case 2:return r=t.sent,t.abrupt("return",r.uid);case 4:case"end":return t.stop()}},t,this)})},t}(),e=function(){function e(t){_classCallCheck(this,e),this.namespace=t,this.ready=new Promise(function(r,e){var n=indexedDB.open(t);n.onerror=function(){e("Couldn't open the IndexedDB database!")},n.onsuccess=function(t){r(t.target.result)},n.onupgradeneeded=function(t){var r=t.target.result;r.createObjectStore("OperationBuffer",{keyPath:"uid"}),r.createObjectStore("StateVector",{keyPath:"user"})}})["catch"](function(t){throw new Error(t)})}return e.prototype.requestTransaction=function(e){this.ready.then(function(n){function o(r){for(var e=!0;e;){var n=r;c=void 0,e=!1;var c=n.value;if(n.done)return c;if(c.constructor===Promise)return n.value.then(function(t){return o(a.next(t))},function(t){return o(a["throw"](t))});if(c.constructor!==t)throw new Error("I do only accept Promises and Generators!");r=c.apply(i).next(),e=!0}}var i=new r(n.transaction(["OperationBuffer","StateVector"],"readwrite")),a=e.apply(i);return o(a.next())})},e}();return e}(),OperationBuffer=function t(){_classCallCheck(this,t),this.i=4},Operation=function(){function t(r){_classCallCheck(this,t),this.i=r.i}return t.prototype.yay=function(){return this.i},t}();
//# sourceMappingURL=y.js.map