mirror of
https://github.com/orbitdb/orbitdb.git
synced 2025-06-21 05:26:37 +00:00
31 lines
529 B
JavaScript
31 lines
529 B
JavaScript
'use strict';
|
|
|
|
const Counter = require('../../crdts/GCounter');
|
|
|
|
class CounterIndex {
|
|
constructor() {
|
|
this._index = null;
|
|
}
|
|
|
|
createCounter(id) {
|
|
this._index = new Counter(id);
|
|
}
|
|
|
|
get() {
|
|
return this._index;
|
|
}
|
|
|
|
updateIndex(oplog, updated) {
|
|
const counter = this._index;
|
|
if(counter) {
|
|
updated.filter((f) => f && f.op === 'COUNTER')
|
|
.map((f) => Counter.from(f.value))
|
|
.forEach((f) => counter.merge(f))
|
|
|
|
this._index = counter;
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = CounterIndex;
|