Skip to content

Commit

Permalink
store atom on storage (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
mafintosh authored Jan 13, 2025
1 parent 1ad7115 commit f9f605d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
24 changes: 12 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ class Atom {
}

class HypercoreStorage {
constructor (store, db, core, view, atomic) {
constructor (store, db, core, view, atom) {
this.store = store
this.db = db
this.core = core
this.view = view
this.atomic = atomic
this.atom = atom

this.view.readStart()
}
Expand Down Expand Up @@ -95,15 +95,15 @@ class HypercoreStorage {
}

snapshot () {
return new HypercoreStorage(this.store, this.db.snapshot(), this.core, this.view.snapshot(), this.atomic)
return new HypercoreStorage(this.store, this.db.snapshot(), this.core, this.view.snapshot(), this.atom)
}

atomize (atom) {
return new HypercoreStorage(this.store, this.db.session(), this.core, atom.view, true)
return new HypercoreStorage(this.store, this.db.session(), this.core, atom.view, atom)
}

atom () {
return this.store.atom()
createAtom () {
return this.store.createAtom()
}

createBlockStream (opts) {
Expand Down Expand Up @@ -149,7 +149,7 @@ class HypercoreStorage {
const dependency = await dependencyPromise
if (dependency) core.dependencies = this._addDependency(dependency)

return new HypercoreStorage(this.store, this.db.session(), core, this.atomic ? this.view : new View(), this.atomic)
return new HypercoreStorage(this.store, this.db.session(), core, this.atom ? this.view : new View(), this.atom)
}

async createSession (name, head) {
Expand Down Expand Up @@ -193,7 +193,7 @@ class HypercoreStorage {

await tx.flush()

return new HypercoreStorage(this.store, this.db.session(), core, this.atomic ? this.view : new View(), this.atomic)
return new HypercoreStorage(this.store, this.db.session(), core, this.atom ? this.view : new View(), this.atom)
}

async createAtomicSession (atom, head) {
Expand Down Expand Up @@ -238,7 +238,7 @@ class HypercoreStorage {
}

write () {
return new CoreTX(this.core, this.db, this.atomic ? this.view : null, [])
return new CoreTX(this.core, this.db, this.atom ? this.view : null, [])
}

close () {
Expand Down Expand Up @@ -429,7 +429,7 @@ class CorestoreStorage {
return head === null ? initStoreHead() : head
}

atom () {
createAtom () {
return new Atom(this.db)
}

Expand Down Expand Up @@ -585,7 +585,7 @@ class CorestoreStorage {
dataPointer = dependency.dataPointer
}

const result = new HypercoreStorage(this, this.db.session(), core, EMPTY, false)
const result = new HypercoreStorage(this, this.db.session(), core, EMPTY, null)

if (result.core.version === 0) await this._migrateCore(result, discoveryKey, create)
return result
Expand Down Expand Up @@ -635,7 +635,7 @@ class CorestoreStorage {

tx.apply()

return new HypercoreStorage(this, this.db.session(), ptr, EMPTY, false)
return new HypercoreStorage(this, this.db.session(), ptr, EMPTY, null)
}

async create (data) {
Expand Down
2 changes: 1 addition & 1 deletion test/streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test('reverse block stream', async function (t) {

test('block stream (atom)', async function (t) {
const core = await createCore(t)
const atom = core.atom()
const atom = core.createAtom()

const a = core.atomize(atom)

Expand Down

0 comments on commit f9f605d

Please sign in to comment.