Rename abstract parent class of Lazy(Array|Object) from Lazy to LazyValue
authorNick Downing <nick@ndcode.org>
Fri, 7 Jan 2022 05:29:18 +0000 (16:29 +1100)
committerNick Downing <nick@ndcode.org>
Fri, 7 Jan 2022 05:29:28 +0000 (16:29 +1100)
LazyArray.mjs
LazyObject.mjs
LazyValue.mjs [moved from Lazy.mjs with 92% similarity]
Transaction.mjs
index.mjs

index e6bbf50..e15d1d6 100644 (file)
@@ -1,7 +1,7 @@
 import assert from 'assert'
-import Lazy from './Lazy.mjs'
+import LazyValue from './LazyValue.mjs'
 
-class LazyArray extends Lazy {
+class LazyArray extends LazyValue {
   constructor(transaction, ptr_len, array) {
     super(transaction, ptr_len)
     this.array = array || []
@@ -34,7 +34,7 @@ class LazyArray extends Lazy {
     assert(
       typeof value !== 'object' ||
       value === null ||
-      (value instanceof Lazy && value.transaction === this.transaction)
+      (value instanceof LazyValue && value.transaction === this.transaction)
     )
     this.ptr_len = null // mark dirty
     this.array[key] = value
@@ -60,7 +60,7 @@ class LazyArray extends Lazy {
   async commit() {
     for (let i = 0; i < this.length; ++i) {
       let value = this.array[i]
-      if (value instanceof Lazy) {
+      if (value instanceof LazyValue) {
         if (await value.commit())
           this.ptr_len = null // mark dirty
         this.array[i] = value.ptr_len
index fb48c8a..8923df9 100644 (file)
@@ -1,7 +1,7 @@
 import assert from 'assert'
-import Lazy from './Lazy.mjs'
+import LazyValue from './LazyValue.mjs'
 
-class LazyObject extends Lazy {
+class LazyObject extends LazyValue {
   constructor(transaction, ptr_len, object) {
     super(transaction, ptr_len)
     this.object = object || {}
@@ -33,7 +33,7 @@ class LazyObject extends Lazy {
     assert(
       typeof value !== 'object' ||
       value === null ||
-      (value instanceof Lazy && value.transaction === this.transaction)
+      (value instanceof LazyValue && value.transaction === this.transaction)
     )
     this.ptr_len = null // mark dirty
     this.object[key] = value
@@ -53,7 +53,7 @@ class LazyObject extends Lazy {
   async commit() {
     for (let i in this.object) {
       let value = this.object[i]
-      if (value instanceof Lazy) {
+      if (value instanceof LazyValue) {
         if (await value.commit())
           this.ptr_len = null // mark dirty
         this.object[i] = value.ptr_len
similarity index 92%
rename from Lazy.mjs
rename to LazyValue.mjs
index 4bc36b9..39d4180 100644 (file)
--- a/Lazy.mjs
@@ -1,7 +1,7 @@
 import assert from 'assert'
 import Transaction from './Transaction.mjs'
 
-class Lazy {
+class LazyValue {
   constructor(transaction, ptr_len) {
     assert(transaction instanceof Transaction)
     this.transaction = transaction
@@ -29,4 +29,4 @@ class Lazy {
   }
 }
 
-export default Lazy
+export default LazyValue
index 1e8160a..8b91f78 100644 (file)
@@ -1,7 +1,7 @@
 import assert from 'assert'
 import fsPromises from 'fs/promises'
 import Database from './Database.mjs'
-import Lazy from './Lazy.mjs'
+import LazyValue from './LazyValue.mjs'
 import LazyArray from './LazyArray.mjs'
 import LazyObject from './LazyObject.mjs'
 
@@ -40,7 +40,7 @@ class Transaction {
     assert(
       typeof value !== 'object' ||
       value === null ||
-      (value instanceof Lazy && value.transaction === this)
+      (value instanceof LazyValue && value.transaction === this)
     )
     this.value = value
   }
@@ -48,7 +48,7 @@ class Transaction {
   async commit() {
     assert(this.value !== undefined)
 
-    if (this.value instanceof Lazy) {
+    if (this.value instanceof LazyValue) {
       if (await this.value.commit())
         this.dirty = true
       this.value = this.value.ptr_len
index 93c46bc..5e292dc 100644 (file)
--- a/index.mjs
+++ b/index.mjs
@@ -1,10 +1,10 @@
 import Database from './Database.mjs'
-import Lazy from './Lazy.mjs'
+import LazyValue from './LazyValue.mjs'
 import LazyArray from './LazyArray.mjs'
 import LazyObject from './LazyObject.mjs'
  
 let logjson_to_json = async value => {
-  if (value instanceof Lazy) {
+  if (value instanceof LazyValue) {
     let new_value
     if (value instanceof LazyArray) {
       new_value = []
@@ -26,7 +26,7 @@ let logjson_to_json = async value => {
 
 export default {
   Database,
-  Lazy,
+  LazyValue,
   LazyArray,
   LazyObject,
   logjson_to_json