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'??
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.
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.
RxJS (Reactive Extensions for JavaScript) is a library for reactive programming using observables that makes it easier to compose asynchronous or callback-based code.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With