git ssb

7+

dinoworm 🐛 / patchcore



Commit 6e3b109334efa6ea87f3cd60592e293c9a42532b

Merge pull request #57 from ssbc/fix-partial-rerender

ammending #56 - fix preserving partial re-rendering from messages
mix irving authored on 3/6/2018, 5:20:35 AM
GitHub committed on 3/6/2018, 5:20:35 AM
Parent: bbf9cdfc7f84c6262811e691c5feb5c33dc69c0a
Parent: 26e9c98d156ad3d0051b094655e6273733915e8c

Files changed

feed/obs/thread.jschanged
feed/obs/thread.jsView
@@ -1,8 +1,8 @@
11 var nest = require('depnest')
22 var sort = require('ssb-sort')
33 var ref = require('ssb-ref')
4-var { Array: MutantArray, Value, map, computed } = require('mutant')
4 +var { Array: MutantArray, Value, map, computed, concat } = require('mutant')
55
66 exports.needs = nest({
77 'backlinks.obs.for': 'first',
88 'sbot.async.get': 'first',
@@ -31,21 +31,26 @@
3131 }
3232 })
3333
3434 var backlinks = api.backlinks.obs.for(rootId)
35 +
36 + // wrap computed in a map to turn into individual observables
3537 var replies = map(computed(backlinks, (msgs) => {
36- return msgs.filter(msg => {
38 + return sort(msgs.filter(msg => {
3739 const { type, branch } = msg.value.content
3840 return type !== 'vote' && !isBlocked(msg) && (root(msg) === rootId || matchAny(branch, rootId))
39- })
41 + }))
4042 }), x => Value(x), {
4143 // avoid refresh of entire list when items added
4244 comparer: (a, b) => a === b
4345 })
4446
45- var messages = computed([prepend, replies], (prepend, replies) => {
46- return sort([...prepend, ...replies])
47- })
47 + // append the root message to the sorted replies list
48 + // -------------------------
49 + // concat preserves the individual observable messages so that clients don't need to
50 + // rerender the entire list when an item is added (map will only be called for new items)
51 + // (we can't use a computed here as it would squash the individual observables into a single one)
52 + var messages = concat([prepend, replies])
4853
4954 var result = {
5055 messages,
5156 lastId: computed(messages, (messages) => {

Built with git-ssb-web