Draft:Rxjs
| Draft article not currently submitted for review.
This is a draft Articles for creation (AfC) submission. It is not currently pending review. While there are no deadlines, abandoned drafts may be deleted after six months. To edit the draft click on the "Edit" tab at the top of the window. To be accepted, a draft should:
It is strongly discouraged to write about either yourself or your business or employer. If you do so, you must declare it. Where to get help
How to improve a draft
You can also browse Wikipedia:Featured articles and Wikipedia:Good articles to find examples of Wikipedia's best writing on topics similar to your proposed article. Improving your odds of a speedy review To improve your odds of a faster review, tag your draft with relevant WikiProject tags using the button below. This will let reviewers know a new draft has been submitted in their area of interest. For instance, if you wrote about a female astronomer, you would want to add the Biography, Astronomy, and Women scientists tags. Editor resources
Last edited by Qwerfjkl (bot) (talk | contribs) 15 days ago. (Update) |
Technical overview
[edit]RxJS (Reactive Extensions for JavaScript) is a library for reactive programming in JavaScript and TypeScript.[1][2] It represents asynchronous computations as streams of values over time and provides a set of operators for composing, transforming, and coordinating those streams.[1]
In functional and reactive programming terms, RxJS can be understood as a domain-specific language (DSL) for creating and querying dataflows over time.[3] This DSL is commonly described in terms of four core abstractions:
- Observables – blueprints for data sources that push values to observers over time.[4]
- Operators – higher-order dataflow combinators that transform, filter, and combine observable streams.[5][6]
- Subscriptions – handles that track the lifecycle of a running observable execution and allow cancellation.[7]
- Schedulers – timing and concurrency policies that control when work and notifications are executed.[8]
Observable
[edit]An Observable<T> represents a blueprint for a dataflow source. It describes how values of type T will be delivered to an interested party (an observer) over time. An observable is not active until it is subscribed to; calling subscribe turns the blueprint into a concrete running dataflow.[4][9]
An observable may emit zero or more next notifications carrying values, followed by either a terminal error notification (indicating failure) or a terminal complete notification (indicating successful completion). Observables in RxJS are push-based: the source decides when to emit values, rather than the consumer pulling them on demand.[4]
An observer defines how to react to these notifications via three callbacks: one for values (next), one for terminal errors (error), and one for successful completion (complete).[9]
Operator
[edit]An RxJS operator is a higher-order dataflow combinator function. Operators take one or more policy functions—small functions that express rules such as mapping, filtering, accumulation, or error handling—and produce an OperatorFunction<T, R>.[5][6]
An OperatorFunction<T, R> is a function that accepts an input Observable<T> and returns an output Observable<R>. In this sense, operators do not create data in isolation; instead, they compose existing streams into new streams, encoding policies about how the dataflow should be transformed, filtered, routed, or timed.[5]
In practice, operators are typically used inside pipe(...) calls to build dataflow pipelines, for example by mapping each value, filtering based on predicates, combining multiple streams, or introducing time-based behaviour such as debouncing and throttling.[10]
Subscription
[edit]A Subscription represents the lifecycle of a single observable execution. When an observer subscribes to an observable, the subscription records that running dataflow and provides an unsubscribe method that can be used to cancel it.[7][4]
Calling unsubscribe signals that the consumer is no longer interested in further notifications. This triggers associated teardown logic, such as cancelling timers, removing event listeners, or closing network connections. Subscriptions can also aggregate other subscriptions and teardown functions, so that a single parent subscription can manage the lifecycles of multiple child resources.[7]
Scheduler
[edit]A Scheduler encapsulates a timing and concurrency policy. It controls when scheduled work is executed and when notifications are delivered, without changing the core semantics of the observable.[8]
Schedulers provide two essential capabilities: a notion of "current time" and a method for scheduling work to run immediately or after a delay. Different schedulers can model immediate execution, asynchronous execution (for example, using timers or the event loop), or virtual time, which is useful for deterministic testing of time-dependent code.[11]
Time-based operators such as interval, timer, delay, debounceTime, and throttleTime make use of schedulers internally.[5] By choosing different schedulers, the same dataflow logic can be executed under different timing and concurrency strategies.[8]
Type-level view (informal)
[edit]The core abstractions used by RxJS can be informally represented with the following type shapes:
// Observable: blueprint for a dataflow source
interface Observable<T> {
subscribe(observer: Partial<Observer<T>>): Subscription;
}
// Observer: reacts to notifications from an Observable
interface Observer<T> {
next(value: T): void;
error(err: any): void;
complete(): void;
}
// Operator: higher-order dataflow combinator
type OperatorFunction<T, R> = (source$: Observable<T>) => Observable<R>;
// Example “policy” function shapes
type Mapper<T, R> = (value: T) => R;
type Predicate<T> = (value: T) => boolean;
type Reducer<S, T> = (state: S, value: T) => S;
type EqualityFn<T> = (a: T, b: T) => boolean;
// Subscription: tracks the lifecycle of an Observable execution
interface Subscription {
unsubscribe(): void;
add(teardown: () => void): void;
closed: boolean;
}
// Scheduler: timing and concurrency policy
interface SchedulerLike {
now(): number;
schedule<TState>(
work: (state?: TState) => void,
delay?: number,
state?: TState
): Subscription;
}
Taken together, these abstractions allow RxJS to describe, transform, and coordinate asynchronous dataflows in a composable, declarative way.
- ^ a b "RxJS - Overview". RxJS. ReactiveX. Retrieved 25 November 2025.
- ^ "The RxJS library". Angular. Google. Retrieved 25 November 2025.
- ^ "Reactive Programming in JavaScript With RxJS". Semaphore CI. 16 November 2023. Retrieved 25 November 2025.
- ^ a b c d "Observable". RxJS. ReactiveX. Retrieved 25 November 2025.
- ^ a b c d "Operators". RxJS. ReactiveX. Retrieved 25 November 2025.
- ^ a b "Operators". ReactiveX. Retrieved 25 November 2025.
- ^ a b c "Subscription". RxJS. ReactiveX. Retrieved 25 November 2025.
- ^ a b c "Scheduler". RxJS. ReactiveX. Retrieved 25 November 2025.
- ^ a b "Observable". ReactiveX. Retrieved 25 November 2025.
- ^ "Operators". Learn RxJS. Retrieved 25 November 2025.
- ^ "Scheduling and Concurrency". RxJS Book. Retrieved 25 November 2025.
