https://github.com/regular/tre-watch-heads
https://github.com/regular/tre-watch-heads
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/regular/tre-watch-heads
- Owner: regular
- Created: 2018-11-22T11:25:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-10-02T07:12:10.000Z (over 5 years ago)
- Last Synced: 2024-04-24T18:55:27.181Z (about 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
tre-watch-heads
---
Observe mutable ssb messages
``` js
const WatchHeads = require('tre-watch-heads')
const h = require('mutant/html-element')
const computed = require('mutant/computed')
// pass your ssb client instance
const head = WatchHeads(ssb)
// head() takes a revisionRoot and returns a mutant-compatible observable
// This is how you get the revisionRoot from any ssb message, mutated or not
const revRoot = kv.value.content.revisionRoot || kv.key
// html will update in realtime whenever we receive a new revision of this particular message
document.body.appendChild(
h('div', [
h('div', 'latest version:'),
computed(head(revRoot), kvm => {
// 'kvm' stands for key/value/meta
const text = kvm && kvm.value.content.text
const isForked = kvm && kvm.meta.forked
return [
h('span', isForked ? 'forked' : 'not forked'),
h('div', text)
]
})
])
)
// When the element is removed from the dom, the underlying pull-stream
// will be aborted automatically
```
See Also:
- [ssb-revisions](https://www.npmjs.com/package/ssb-revisions)
- [mutant](https://www.npmjs.com/package/mutant)
- [collect-mutations](https://www.npmjs.com/package/collect-mutations)
License: ISC