if (typeof new_value === 'object' && new_value !== null)
new_value =
new_value instanceof Array ?
- new LazyArray(this, new_value) :
- new LazyObject(this, new_value)
+ new LazyArray(this, [ptr, len], new_value) :
+ new LazyObject(this, [ptr, len], new_value)
value[2] = new_value
}
value = new_value
}
set(value) {
- //assert(
- // typeof value !== 'object' ||
- // value === null ||
- // (value instanceof Lazy && value.transaction === this)
- //)
this.dirty = true
if (typeof value === 'object' && value !== null) {
assert(value instanceof Lazy && value.transaction === this)
}
LazyArray(...args) {
- return new LazyArray(this, ...args)
+ return new LazyArray(this, null, ...args)
}
LazyObject(...args) {
- return new LazyObject(this, ...args)
+ return new LazyObject(this, null, ...args)
}
json_to_logjson(value) {
// logjson array or object
class Lazy {
- constructor(transaction) {
+ constructor(transaction, ptr_len) {
assert(transaction instanceof Transaction)
this.transaction = transaction
- this.dirty = false
+ this.ptr_len = ptr_len || null
}
has(key) {
}
class LazyArray extends Lazy {
- constructor(transaction, array) {
- super(transaction)
+ constructor(transaction, ptr_len, array) {
+ super(transaction, ptr_len)
this.array = array || []
this.length = this.array.length
}
if (typeof new_value === 'object' && new_value !== null)
new_value =
new_value instanceof Array ?
- new LazyArray(this.transaction, new_value) :
- new LazyObject(this.transaction, new_value)
+ new LazyArray(this.transaction, [ptr, len], new_value) :
+ new LazyObject(this.transaction, [ptr, len], new_value)
value[2] = new_value
}
value = new_value
set(key, value) {
assert(typeof key === 'number')
- //assert(
- // typeof value !== 'object' ||
- // value === null ||
- // (value instanceof Lazy && value.transaction === this.transaction)
- //)
- this.dirty = true
+ this.ptr_len = null // mark dirty
if (typeof value === 'object' && value !== null) {
assert(value instanceof Lazy && value.transaction === this.transaction)
value = [-1, 0, value]
item[0] = ptr
item[1] = len
- this.dirty = true
+ this.ptr_len = null // mark dirty
}
}
}
- return this.dirty
+ return this.ptr_len === null
}
pack() {
- this.dirty = false
-
let new_array = []
for (let i = 0; i < this.length; ++i) {
let item = this.array[i]
}
class LazyObject extends Lazy {
- constructor(transaction, object) {
- super(transaction)
+ constructor(transaction, ptr_len, object) {
+ super(transaction, ptr_len)
this.object = object || {}
}
if (typeof new_value === 'object' && new_value !== null)
new_value =
new_value instanceof Array ?
- new LazyArray(this.transaction, new_value) :
- new LazyObject(this.transaction, new_value)
+ new LazyArray(this.transaction, [ptr, len], new_value) :
+ new LazyObject(this.transaction, [ptr, len], new_value)
value[2] = new_value
}
value = new_value
set(key, value) {
assert(typeof key === 'string')
- //assert(
- // typeof value !== 'object' ||
- // value === null ||
- // (value instanceof Lazy && value.transaction === this.transaction)
- //)
- this.dirty = true
+ this.ptr_len = null // mark dirty
if (typeof value === 'object' && value !== null) {
assert(value instanceof Lazy && value.transaction === this.transaction)
value = [-1, 0, value]
item[0] = ptr
item[1] = len
- this.dirty = true
+ this.ptr_len = null // mark dirty
}
}
}
- return this.dirty
+ return this.ptr_len === null
}
pack() {
- this.dirty = false
-
let new_object = {}
for (let i in this.object) {
let item = this.object[i]