diff --git a/src/Database.js b/src/Database.js index ce28f673..c1441769 100644 --- a/src/Database.js +++ b/src/Database.js @@ -186,10 +186,13 @@ module.exports = function (Y /* :any */) { } } getNextOpId () { - if (this.userId == null) { + if (this._temporaryUserIdGenerator != null) { + return this._temporaryUserIdGenerator() + } else if (this.userId == null) { throw new Error('OperationStore not yet initialized!') + } else { + return [this.userId, this.opClock++] } - return [this.userId, this.opClock++] } /* Apply a list of operations. diff --git a/src/y.js b/src/y.js index 191f1b0f..1d3db613 100644 --- a/src/y.js +++ b/src/y.js @@ -111,18 +111,14 @@ class YConfig { this.connector = new Y[opts.connector.name](this, opts.connector) this.db.requestTransaction(function * requestTransaction () { // create initial Map type - var model = { - id: ['_', 0], - struct: 'Map', - type: 'Map', - map: {} + this.store._temporaryUserIdGenerator = function () { + return ['_', 0] } - yield* this.store.tryExecute.call(this, model) - var root = yield* this.getType(model.id) - this.store.y.root = root - setTimeout(function () { - callback() - }, 0) + var typeid = yield* Y.Map.createType.call(this) + var type = yield* this.getType(typeid) + this.store.y.root = type + this.store._temporaryUserIdGenerator = null + setTimeout(callback, 0) }) } isConnected () {