git ssb

7+

dinoworm 🐛 / patchcore



Commit e6ada2f6daafcd03bde943759ecec74629525fb6

Changed the 'gives' name to fit the depject patchcore conventions matt mentioned. Also changed the second argument to accept 'opts' to make the space to also add an optional 'object' to filter on directly within the sbot query. Remove the 'sync' observable as mutant-pull-reduce is meant to deal with that.

Gordon Martin committed on 11/26/2017, 10:29:46 PM
Parent: 613698a4f9211cb8b1e75978401b1edf3831c673

Files changed

backlinks/obs_filter.jschanged
backlinks/obs_filter.jsView
@@ -6,75 +6,63 @@
66 exports.needs = nest({
77 'sbot.pull.backlinks': 'first'
88 })
99
10-exports.gives = nest("backlinks.filter.obs", true)
10 +exports.gives = nest("backlinks.obs.filter", true)
1111
1212 /**
1313 * sbot.filter.obs returns an observable list of messages that link
1414 * back to the message with the given message ID (@id). Only messages that
15- * pass the filter function are added to the list.
15 + * pass the filter are added to the list.
1616 *
17- * When a message arrives, if passing it to the filter function (@filterFn)
18- * does not result in it returning 'true' the message is not added to the
19- * observable list.
17 + * When a message arrives, if a filter function is given in the options (opts.filter)
18 + * and passing it to the filter function (opts.filter) not result in it returning
19 + * 'true' the message is not added to the observable list.
2020 *
2121 * A 'sync' observable property is also added to the returned observable
2222 * which is 'true' when all previously seen messages are caught up with.
2323 *
2424 * Note: Unlike backlinks.obs.for this does not cache the observable for
2525 * callers that supply the same arguments.
2626 */
2727 exports.create = function(api) {
28- function pullFilterReduceObs(id, filterFn) {
28 + function pullFilterReduceObs(id, opts) {
2929 if (!id || typeof(id) !== "string") {
3030 throw new Error("id must be a string.")
3131 }
3232
33- if (!filterFn || typeof(filterFn) !== "function") {
34- throw new Error("filterFn must be a function.")
33 + var sbotFilter = {
34 + $filter: {
35 + dest: id
36 + }
3537 }
3638
37- var sync = Value(false)
38-
3939 var msgBacklinks = api.sbot.pull.backlinks({
40- query: [{
41- $filter: {
42- dest: id
43- }
44- }],
40 + query: [sbotFilter],
4541 live: true
4642 })
4743
48- var msgFilter = pull.filter((msg) => {
49- // We do not include the 'sync' message which indicates that any
50- // further messages are newly gossiped messages in the list of messages.
51- if (msg.sync) {
52- sync.set(true)
53- return false
54- } else {
55- return filterFn(msg)
56- }
57- })
44 + // If a filter function is supplied in the options, we use it to filter
45 + // the links stream, otherwise we use all the messages from the stream
46 + var filterFunction = opts && opts.filter ? opts.filter : () => true
5847
5948 var filteredBacklinks = pull(
6049 msgBacklinks,
61- msgFilter
50 + pull.filter(filterFunction)
6251 )
6352
6453 var backlinksObs = MutantPullReduce(filteredBacklinks, (state, msg) => {
6554 state.push(msg)
6655 return state;
6756 }, {
6857 startValue: [],
69- nextTick: true
58 + nextTick: true,
59 + sync: true
7060 })
7161
72- backlinksObs.sync = sync
73-
7462 return backlinksObs;
7563 }
7664
7765 return nest({
78- "backlinks.filter.obs": (id, filterFn) => pullFilterReduceObs(id, filterFn)
66 + "backlinks.obs.filter": (id, opts) => pullFilterReduceObs(id, opts)
7967 })
8068 }

Built with git-ssb-web