question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Equivalent to Rx.Subject

See original GitHub issue

Hello everyone, I’m new to most and I was wondering if there is an equivalent to Rx’s Subject? In particular, I’m curious if there is a way for recreating Rx.ReplaySubject

For some more information on what I’m trying to accomplish.

I’m trying to rewrite Cycle.js using Most instead of RxJs. I haven’t been able to find a way to recreate the circular dependency between Observables.

In Cycle.js it’s roughly like this (although a little more complex)

const sinksProxy = new Rx.Subject()
const sources = driverFn( sinkProxy )
const sinks = application( sources )
sinks.subscribe( value => sinksProxy.onNext(value) )

Thanks in advance!

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:18 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
TylorScommented, Dec 6, 2015

For anyone else looking for this, I have an implementation here https://github.com/TylorS/most-subject. In combination with https://github.com/mostjs/hold a ReplaySubject-like stream can be created though only with 1 past value, as that’s the common use case.

@briancavalier Do you think it is safe to close this?

1reaction
briancavaliercommented, Nov 2, 2015

Hey @TylorS, this is a really interesting situation–one I’ve not really thought about before. I’d love to find a way to do it declaratively, rather than having to subscribe and feed the events back in. It’s totally not obvious how to do it declaratively right now, though (but I’ll give it more thought!)

Anyway, I think it would be annoying to try to do it in the current version of most.js. There’s been some previous discussion about providing an externalized imperative event pushing api in #72. That PR is a bit long in the tooth, and should probably be abandoned, but the idea certainly seems like it’d work for what you’re doing in that sample code.

One question: How do external events make their way into the cycle? Does someone (perhaps code inside driverFn or application end up calling sinkProxy.onNext?

I went back and forth on adding an API like that, since it tends to either put the burden managing race conditions on the caller, or introduce inefficiency if you force every event to be queued and sent in a future call stack. But I’ve made my peace with it 😃

Would it work for you if there were some new API that looked like:

import most from 'most';
const { sink, stream } = most.whatever();

sink.add(x); // add x to stream

Thoughts?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is there an equivalent of Subject for RxJava's Single?
Unfortunately there is no equivalent available in RxJava 1. However, as you have mentioned, you can achieve the desired result by calling ...
Read more >
Subject - RxJS
What is a Subject? An RxJS Subject is a special type of Observable that allows values to be multicasted to many Observers. ·...
Read more >
Types of Subjects in RxJava. Subjects are both an Observer ...
Subjects are both an Observer and Observable, it's like a proxy multicasting device or ... ReplaySubject is similar to cache() operator.
Read more >
Intro to Rx - Key Types - Introduction to Rx
AsyncSubject<T> is similar to the Replay and Behavior subjects in the way that it caches values, however it will only store the last...
Read more >
Subjects - Learn RxJS
Typical observables would be comparable to a 1 on 1 conversation. There are 4 variants of subjects: Subject - No initial value or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found