DEV Community

xRdev_38
xRdev_38

Posted on

RxJS for Beginners

RxJS for Beginners

RxJS helps manage async streams in Angular and other frameworks.

Create an Observable

import { Observable } from 'rxjs';

const obs = new Observable(sub => {
  sub.next('Hello');
  sub.next('World');
  sub.complete();
});
obs.subscribe(console.log);
Enter fullscreen mode Exit fullscreen mode

Use Operators

import { of } from 'rxjs';
import { map, filter } from 'rxjs/operators';

of(1, 2, 3).pipe(
  filter(x => x > 1),
  map(x => x * 2)
).subscribe(console.log); // 4, 6
Enter fullscreen mode Exit fullscreen mode

Conclusion

RxJS makes handling async data and complex events easier.

Top comments (2)

Collapse
 
nathan_tarbert profile image
Nathan Tarbert

Very cool, love how simple you kept it. Makes RxJS feel a lot less intimidating

Collapse
 
dariomannu profile image
Dario Mannu

You may need to check out Rimmel, then...