How to avoid the use of Subjects in RX

后端 未结 2 1145
南笙
南笙 2021-02-19 13:55

So I keep reading everywhere that use of Subject is \"bad\" - and I kind of agree with the reasoning.

However, I am trying to think of the best way

2条回答
  •  一整个雨季
    2021-02-19 14:16

    A simple way to enter the observable is via an Action

    private Action _action;
    

    Create the observable

    public IObservable GetObservable()
    {
        return Observable.FromEvent>(
                    ev => _action += ev, 
                    ev => _action -= ev);
    }
    

    Then add to the observable using

    public void OnNext(ObservableArgs args)
    {
        _action?.Invoke(args);
    }
    

提交回复
热议问题