Skip to content
This repository has been archived by the owner on Sep 30, 2023. It is now read-only.

Added applyEntry function to Index. #46

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/KeyValueIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ class KeyValueIndex {
get(key) {
return this._index[key]
}

put(entry) {
this._index[entry.payload.key] = item.payload.value
}

del(entry) {
delete this._index[item.payload.key]
}

applyEntry(entry) {
switch(entry.payload.op) {
case "PUT":
this.put(entry)
break
case "DEL":
this.del(entry)
break
}
}

updateIndex(oplog) {
oplog.values
Expand All @@ -16,11 +35,7 @@ class KeyValueIndex {
.reduce((handled, item) => {
if(!handled.includes(item.payload.key)) {
handled.push(item.payload.key)
if(item.payload.op === 'PUT') {
this._index[item.payload.key] = item.payload.value
} else if(item.payload.op === 'DEL') {
delete this._index[item.payload.key]
}
this.applyEntry(item)
}
return handled
}, [])
Expand Down