(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 0) { var add = nextRound nextRound = [] for (i = 0; i < add.length; i++) { op = add[i] if (op.struct === 'Insert') { var ready = true for (let j = i + 1; j < add.length; j++) { let _op = add[j] if (Y.utils.compareIds(_op.id, op.left)) { ready = false break } } if (ready) { for (let j = 0; j < nextRound.length; j++) { let _op = add[j] if (Y.utils.compareIds(_op.id, op.left)) { ready = false break } } } if (!ready) { // it is necessary to execute left first nextRound.push(op) continue } } yield* this.store.operationAdded(this, op, true) } } }) } } }, false) } * operationAdded (transaction, op, noAdd) { yield* super.operationAdded(transaction, op) if (!noAdd) { window.localStorage[this.operationAddedNamespace] = JSON.stringify(op) } } transact (makeGen) { var transaction = this.db != null ? new Transaction(this) : null var store = this var gen = makeGen.call(transaction) handleTransactions(gen.next()) function handleTransactions (result) { var request = result.value if (result.done) { makeGen = store.getNextRequest() if (makeGen != null) { if (transaction == null && store.db != null) { transaction = new Transaction(store) } gen = makeGen.call(transaction) handleTransactions(gen.next()) } // else no transaction in progress! return } console.log('new request', request.source != null ? request.source.name : null) if (request.constructor === window.IDBRequest) { request.onsuccess = function () { var res = request.result if (res != null && res.constructor === window.IDBCursorWithValue) { res = res.value } handleTransactions(gen.next(res)) } request.onerror = function (err) { gen.throw(err) } } else if (request.constructor === window.IDBCursor) { request.onsuccess = function () { handleTransactions(gen.next(request.result != null ? request.result.value : null)) } request.onerror = function (err) { gen.throw(err) } } else if (request.constructor === window.IDBOpenDBRequest) { request.onsuccess = function (event) { var db = event.target.result handleTransactions(gen.next(db)) } request.onerror = function () { gen.throw("Couldn't open IndexedDB database!") } request.onupgradeneeded = function (event) { var db = event.target.result try { delete window.localStorage[JSON.stringify(['Yjs_indexeddb', store.options.namespace])] db.deleteObjectStore('OperationStore') db.deleteObjectStore('DeleteStore') db.deleteObjectStore('StateStore') } catch (e) {} db.createObjectStore('OperationStore', {keyPath: 'id'}) db.createObjectStore('DeleteStore', {keyPath: 'id'}) db.createObjectStore('StateStore', {keyPath: 'id'}) } } else { gen.throw('You must not yield this type!') } } } // TODO: implement "free".. * destroy () { this.db.close() yield window.indexedDB.deleteDatabase(this.options.namespace) } } Y.extend('indexeddb', OperationStore) }) } module.exports = extend if (typeof Y !== 'undefined') { extend(Y) } },{}]},{},[1])