Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the `window` mean in RxJS?

Tags:

rxjs

I'v heard about the buffer. Seems like the window is similar to the buffer. What's the difference between them? and WHY it's called a 'window'??

like image 656
yaya Avatar asked Mar 06 '15 14:03

yaya


People also ask

What is pipe () in RxJS?

pipe() can be called on one or more functions, each of which can take one argument ("UnaryFunction") and uses it to return a value. It returns a function that takes one argument, passes it to the first UnaryFunction, and then passes the result to the next one, passes that result to the next one, and so on.

What is of () RxJS?

RxJS' of() is a creational operator that allows you to create an RxJS Observable from a sequence of values. According to the official docs: of() converts the arguments to an observable sequence. In Angular, you can use the of() operator to implement many use cases.

What is RxJS stand for?

RxJS (Reactive Extensions for JavaScript) is a library for reactive programming using observables that makes it easier to compose asynchronous or callback-based code.


1 Answers

Buffer is a specialization of Window.

Window notifies you immediately of new windows, along with an observable to observe the values that will be in that window.

In contrast, Buffer does not notify you immediately of new windows. Instead it internally collects the items in the window. When the window is complete, Buffer will send a notification with an array containing all of the items in the window.

Conceptually, you can write buffer by using window like so:

Rx.Observable.prototype.buffer = function () {
    return this.window
        .apply(this, arguments)
        .flatMap(function (w) { return w.toArray(); });
};

As to why it is called "window"...unless the Rx authors come answer, any answers will be purely speculative. Window is a term commonly used to represent a time interval in many disciplines, including software development & signal processing.

like image 133
Brandon Avatar answered Oct 12 '22 19:10

Brandon