Firing a custom event in Rx JS

I am trying to understand Reactive JS . In jQuery, I can fire custom events like

$(document).bind('eventbus', function(e, d) { console.log(d);});
$(document).trigger('eventbus', 'test');

and transmit data (ie, “test”). It is not clear how to do this in RxJS. I could try to convert jquery events as

var observable = $(document).ToObservable('eventbus');

but observable returns an event object, but not my data object. How to trigger custom events with data using RxJS? Do I always need to combine any other type of event? My goal is to create a simple eventbus using RxJS.

+3
source share
2 answers

Even if your question is a little old and already answered, I would like to share my opinion with you.

, , Observables. jQuery , , , - , . . , Observable, RxJS , :

function Component(){
    var self = {};
    var subject = new Rx.Subject();

    //raise notifications this way
    //subject.OnNext("myData"); //could be anything, a string, an object, whatever

    self.getObservableSomething = function(){
        return subject.AsObservable();
    }
    return self;
}

Rx, , . , F #, , IEvent IObservable.

, jQuery.

+7

Rx.Observable.FromJQueryEvent, jQuery, .ToObservable.

: jQuery + RxJS

0

Source: https://habr.com/ru/post/1751935/


All Articles