Commit 6e3b109334efa6ea87f3cd60592e293c9a42532b
Merge pull request #57 from ssbc/fix-partial-rerender
ammending #56 - fix preserving partial re-rendering from messagesmix 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.js | changed |
feed/obs/thread.js | |||
---|---|---|---|
@@ -1,8 +1,8 @@ | |||
1 | 1 … | var nest = require('depnest') | |
2 | 2 … | var sort = require('ssb-sort') | |
3 | 3 … | var ref = require('ssb-ref') | |
4 | -var { Array: MutantArray, Value, map, computed } = require('mutant') | ||
4 … | +var { Array: MutantArray, Value, map, computed, concat } = require('mutant') | ||
5 | 5 … | ||
6 | 6 … | exports.needs = nest({ | |
7 | 7 … | 'backlinks.obs.for': 'first', | |
8 | 8 … | 'sbot.async.get': 'first', | |
@@ -31,21 +31,26 @@ | |||
31 | 31 … | } | |
32 | 32 … | }) | |
33 | 33 … | ||
34 | 34 … | var backlinks = api.backlinks.obs.for(rootId) | |
35 … | + | ||
36 … | + // wrap computed in a map to turn into individual observables | ||
35 | 37 … | var replies = map(computed(backlinks, (msgs) => { | |
36 | - return msgs.filter(msg => { | ||
38 … | + return sort(msgs.filter(msg => { | ||
37 | 39 … | const { type, branch } = msg.value.content | |
38 | 40 … | return type !== 'vote' && !isBlocked(msg) && (root(msg) === rootId || matchAny(branch, rootId)) | |
39 | - }) | ||
41 … | + })) | ||
40 | 42 … | }), x => Value(x), { | |
41 | 43 … | // avoid refresh of entire list when items added | |
42 | 44 … | comparer: (a, b) => a === b | |
43 | 45 … | }) | |
44 | 46 … | ||
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]) | ||
48 | 53 … | ||
49 | 54 … | var result = { | |
50 | 55 … | messages, | |
51 | 56 … | lastId: computed(messages, (messages) => { |
Built with git-ssb-web