سؤال

I am trying to use RxJS, but the example I got is a little old. The code I need to run is this:

myInput.toObservable("keyup")
        .Throttle(200)
        .Subscribe(function () {

but toObservable has been removed. My research didn't help. I even found this post requesting toObservable 's return, but no explanation of the alternative.

https://github.com/Reactive-Extensions/rxjs-jquery/issues/4

Does anyone know what is the alternative for toObservable?

هل كانت مفيدة؟

المحلول

There's a very complete example of using the jQuery extensions for rxjs here that accomplishes something very similar to what you want:

var throttledInput = myInput
    .keyupAsObservable()
    .select( function (ev) {
        return $(ev.target).val();
    })
    .throttle(200)
    .distinctUntilChanged();

You should be able to subscribe to the result and perform whatever you'd like then.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top