mafintosh / append-tree

Model a tree structure on top off an append-only log.
MIT License
54 stars 13 forks source link

README tweak #9

Open creationix opened 7 years ago

creationix commented 7 years ago

In the readme, you mention that the hypercore feed can be faked with:

any append-only log that supports .append() and .length

But in testing, I found more was needed. So I made a simple minimal interface.

// Fake hypercore feed for testing and learning
var values = []
var feed = {
  append (value, cb) {
    console.log('APPEND', {value, cb})
    values.push(value)
    nextTick(cb)
  },
  get (index, options, cb) {
    console.log('GET', {index, options, cb})
    nextTick(cb, null, values[index])
  },
  get length () {
    console.log('LENGTH')
    return values.length
  },
  ready (cb) {
    console.log('READY', {cb})
    nextTick(cb)
  }
}
creationix commented 7 years ago

Maybe mention it needs all 4 and .length is a getter.