Closed telamon closed 4 years ago
Amazing work! Totally readable and understandable with nice tests. Awesome.
So while writing the tests yesterday I couldn't quite let go of the feel of stiffness when I wanted to expose some info on the meta-exchange that required looping through async callbacks.
So I prototyped some syntatic sugar for the policies. It's entirely possible to provide both styles at the same time, but I'm unsure if it's worth implementing unless it provides better readability and ease of use:
Given an multifeed instance:
var multi = multifeed(hypercore, ram, { valueEncoding: 'json' })
Attach an announcement meta-info extender (ugh.. terminology..):
multi.useShareProvider(function(feed, share, ignore) {
feed.get(0, function(err, entry) {
if (err) ignore()
else share({timestamp: entry.createdAt})
})
})
Attach an inline feed accept filter:
multi.useAcceptFilter(function(feedMeta, accept) {
accept(new Date().getTime() - feedMeta.timestamp < 86400000)
})
The benefit of this pattern/style is that the application does not have to handle lists of feeds, which might also be considered a limitation by some. Thoughts?
This is ace and exciting @telamon :raised_hands:
hey @telamon is this still a WIP? We're really interested in using this kind of feature in peerfs, particularly with regards to permissions-based replication, I can forsee it being really useful. Is there anything that I can do to help get it over the line or finish what you started?
@KGibb8 Yes, this feature is being worked on as we speak. I've reached the point myself where i need fine grained replication control :)
Currently writing a proposal on an "replication-middleware" API that would enable a powerful and elegant way gain control replication for both core-storages and applications. Will leave a comment with a link to the draft as soon as it's published.
Great @telamon, I look forward to reading it. When are you aiming to publish it by? Exciting!
@KGibb8 just did!! :tada: https://github.com/telamon/replic8
This PR is super seeded by #32
Hey! This is the second feature I have in stock for multifeed (mentioned it earlier in Issue #2 )
It formalizes and exposes the feed-exchange to applications in order to let an application attach it's own metadata and control which feeds it want's to share and receive.
Example policies:
I'm a little short on words today, hope the above examples explains the intention of the feature. Will gladly receive feedback on the policy/adapter design as this was thrown together as a proof of concept.
Maybe it's more useful to split it up as 2 separate types of plugins?
multifeed.useShareProvider(...)
andmultifeed.useReceiveFilter(...)