Closed rhlsthrm closed 3 years ago
Hi,
Thank you for reaching out.
It's a can do, I will do it ASAP, tonight if I can.
Hi @rhlsthrm, I implemented the distinct
operator based on the API of the RxJS operator.
Only difference is, to flush the values you can pass a Ctx
and call the .done()
method when you want to flush.
Both argument are optionals.
I hope it fits your need, let me know you need anything else
Regards.
import { Evt, distinct } from "evt";
const evtStr = Evt.create<string>();
const flushCtx = Evt.newCtx();
evtStr
.pipe(distinct(str => str.split(" ")[0], flushCtx))
.attach(str => console.log(str));
evtStr.post("foo 1");
flushCtx.done();
evtStr.post("foo 2");
evtStr.post("bar 3");
evtStr.post("bar 4");
evtStr.post("foo 5");
evtStr.post("baz 6");
Will print
foo 1
foo 2
bar 3
baz 6
This is amazing! Thank you so much @garronej this looks like exactly what I need! Is this available in a release for me to try?
Will test this out today!
Is your feature request related to a problem? Please describe. I need have my Evt event emitter be idempotent since the source can emit duplicate events.
Describe the solution you'd like I'd love a
pipe
-like operator that can filter for events that have already been emitted.Describe alternatives you've considered RxJs has a
distinct
operator that does exactly what I need. Since I'm already using Evt and I like the library, I'd like to continue using it if possible.Additional context