1

I cant work out what the syntax is to combine these two observables, property Configuration and BalanceDtos in Rx.NET, can do it in RxJS no problem (example below), any ideas? This is as close as I can get it, but its not correct.

public IObservable<Subroutine> Configuration { get; set; }

    public List<IObservable<List<OtherObject>>> BalanceDtos { get; set; }

    public IObservable<List<OtherObject>> GetSubRoutinesTotal
    {
        get
        {
            return Observable.CombineLatest(Configuration, BalanceDtos.CombineLatest()).Select((config, bals) =>
            {
                Subroutine test1 = config; //these are the objects that I want coming out of this CombineLatest observable.
                List<OtherObject> test2 = bals;
            });
        }
    }

So what I want is when either the property Configuration observable changes, or any of the observables in the BalanceDto property change it should emit that change

Marbles would be:

-c1-b1-b2-b3-c2
---[c1,b1]-[c1,b2]-[c1-b3]-[c2,b3] 

With RxJS in typescript I would write the following:

let obsArray$: Observable<Subroutine>;
   let otherModel$: Observable<OtherObject>[];
   combineLatest([obsArray$, combineLatest(otherModel$)]).subscribe(([obsArray, otherModel]) => {
       let test1: Subroutine = obsArray;
       let tes2: OtherObject[] = otherModel;
   });

I just cant work out what the syntax is for the same thing in Rx.NET. I have looked at other examples for Rx.NET CombineLatest, but they always combine objects of the same type.

SolarBear
  • 4,534
  • 4
  • 37
  • 53
Joe Pinder
  • 41
  • 1
  • 4
  • 1
    Could you provide sample input and output, as a marble diagram `+--1---2---3--|` or other way, or describe how the observable and the `List` of observables should be combined? – Theodor Zoulias Dec 09 '20 at 04:29
  • Updated to add comment to question, thanks! – Joe Pinder Dec 11 '20 at 06:15
  • I am a bit confused with the marble diagram. Shouldn't include two source sequences, and a third one with the results? (like [this](http://reactivex.io/documentation/operators/combinelatest.html)) – Theodor Zoulias Dec 11 '20 at 11:40
  • Your not comparing apples with apples here, your rxjs are flat observables with one of those observables being an array of values where as you .Net example contains a list of observables `List>> BalanceDtos`, the the js equivalent would be `Observable[];` . given that it's not really clear what exactly your expecting and the "marble diagram" doesn't really help – Liam Dec 11 '20 at 11:42
  • Sorry, I have updated the question so the Rx.NET and RxJS examples are operating on the same object types. Hopefully this makes it clearer what I am trying to achive. – Joe Pinder Dec 11 '20 at 16:32

1 Answers1

1

I have figured out how to do this now, here is the solution:

public IObservable<Subroutine> Configuration { get; set; }

    public List<IObservable<List<OtherObject>>> BalanceDtos { get; set; }

    public IObservable<List<OtherObject>> GetSubRoutinesTotal
    {
        get
        {
           return BalanceDtos.CombineLatest().CombineLatest(Configuration, (bals, config) =>
            {
                Subroutine test1 = config; //these are the objects that I want coming out of this CombineLatest observable.
                IList<List<OtherObject>> test2 = bals;
                return test2[0];
            });
        }
    }
Joe Pinder
  • 41
  • 1
  • 4