Skip to content
the poor coder

rxjs que recibe como parametro un observable

Poor Man
Published
Reading time
2 min read
On this page

Understanding RxJS que recibe como parametro un observable#

As a blogger and a software developer, I have come across various libraries and frameworks which help in achieving specific functionalities in code. One such library that has been of great help to me is RxJS. RxJS is a library for reactive programming using observables that makes it easier to compose asynchronous or callback-based code.

What is an Observable?#

An observable is an object that emits values over time. These values can be anything: numbers, strings, objects, or even other observables. An observable can be considered as a stream of events that can be observed or subscribed to by an observer. Observables are used extensively in RxJS.

RxJS que recibe como parametro un observable#

The RxJS function que recibe como parametro un observable is used to create a new observable from an existing one. This function can be used in various scenarios like filtering, transforming, or mapping the data emitted by the original observable.

Text
import {Observable} from 'rxjs';

const originalObservable = new Observable((observer) => {
  observer.next('Hello');
  observer.next('World');
});

const newObservable = que(originalObservable);

newObservable.subscribe((value) => {
  console.log(value);
});

// Output: 
// Hello
// World

In the above example, we have created a new observable from the original one using the que function. The new observable will emit the same values as the original one. We have subscribed to the new observable and logged the emitted values to the console.

Multiple ways to use que function#

There are multiple ways to use the que function in RxJS:

  • que can be used to create a new observable that emits only the first value emitted by the original observable:
Text
import {Observable} from 'rxjs';

const originalObservable = new Observable((observer) => {
  observer.next('Hello');
  observer.next('World');
});

const newObservable = que(originalObservable.take(1));

newObservable.subscribe((value) => {
  console.log(value);
});

// Output: 
// Hello
  • que can be used to create a new observable that emits values only when a specific condition is met:
Text
import {Observable} from 'rxjs';

const originalObservable = new Observable((observer) => {
  observer.next(10);
  observer.next(20);
  observer.next(30);
  observer.next(40);
});

const newObservable = que(originalObservable.filter((value) => value >= 30));

newObservable.subscribe((value) => {
  console.log(value);
});

// Output: 
// 30
// 40

In the above example, we have used the filter operator to create a new observable that emits only those values that are greater than or equal to 30. The que function is then used to create a new observable from the filtered observable.

Conclusion#

RxJS is a powerful library that provides various operators and functions to manipulate observables easily. The que function is one such function that can be used to create a new observable from an existing one. By using the que function, we can filter, transform, or map the data emitted by observables and create new observables with specific functionalities.

Keep going

2023

how to sort an array

How to Sort an Array If you have an array and you want to order its elements in a specific way, you need to use a sorting algorithm. There are several sorting algorithms available, but two of the most commonly used are…

javascript2 min read
2023

jquery mobile or desktop

jQuery Mobile or Desktop? As a web developer, I have had some experience with both jQuery Mobile and jQuery Desktop. Both frameworks have their pros and cons, and which one to use really depends on the specific project…

javascript1 min read
2023

node.js folder structure

Node.js Folder Structure If you are new to Node.js, it can be daunting to create a folder structure that will work for your project. The structure you choose will depend on the size and complexity of your project. Here…

javascript1 min read
ESC