wonka icon indicating copy to clipboard operation
wonka copied to clipboard

Add makeReplaySubject source

Open EliaECoyote opened this issue 5 years ago • 7 comments

Related to #75.

This PR aims at adding a makeReplaySubject source. Please note that replay subjects should replay values even after completion

EliaECoyote avatar Feb 24 '20 17:02 EliaECoyote

hey @kitten, did you get a chance to checkout this PR?

EliaECoyote avatar Mar 14 '20 18:03 EliaECoyote

Sorry! I totally forgot to reply here. 😢 I was meaning to ask, do you think it may make more sense to turn this into a replay operator?

kitten avatar Mar 14 '20 19:03 kitten

My intention was to add another separate PR for a shareReplay operator, which would be pretty easy to implement through the makeReplaySubject source, e.g.:

let shareReplay = (bufferSize: int, source: sourceT('a)): sourceT('a) => {
  ley replaySubject = Wonka_sources.makeReplaySubject(bufferSize)};
  let _subscription = source
    |> Wonka_sinks.subscribe(state.replaySubject.next);
  state.replaySubject.source;
};

Honestly I don't see any reason to allow devs to use only the shareReplay operator: do you want to elaborate on that please?

EliaECoyote avatar Mar 14 '20 20:03 EliaECoyote

Sure can 👍 most of the time it won’t make sense to emulate a replay operator using the replay subject imo, since we’re just creating an operator that accepts operations and re-emits them.

So if we turn this around and have a replay operator instead of a subject, a replay subject would just be the replay operator applied to a subject, which saves us from having two subject types 😇

kitten avatar Mar 14 '20 20:03 kitten

Speaking from a personal experience, BehaviorSubject is used more

Austaras avatar Jun 22 '20 19:06 Austaras

@Austaras The motivation here is that BehaviorSubject and ReplaySubject can be derived from shareReplay. If you have a peek at the "compliance" tests for operators there's a lot that operators can guarantee, so it'll require a more rigorous implementation that is then also sure to work for the subjects, which can be aliases.

I haven't taken the time to implement and fix some of the issues for Wonka in a while, so I'll pick up this PR and rewrite it into an operator with an alias. @EliaECoyote Sorry that this has been around for a while. I'll make sure to ping you on the progress on this and either way will credit any result of this to you in the changelog and PR.

kitten avatar Jul 02 '20 17:07 kitten

Well that may do the work, but IMO the ability to synchronously get latest state is vital and it seems to be impossible for an operator to achieve.

Austaras avatar Aug 06 '20 16:08 Austaras