Coder Social home page Coder Social logo

lapalb / rxjs Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 9 KB

Created with StackBlitz ⚡️

Home Page: https://stackblitz.com/edit/angular-ivy-espbt9

CSS 0.99% HTML 29.54% TypeScript 69.47%
rxjs rx angular rxjs-operators rxjs-examples rxjs-observables

rxjs's Introduction

A Hands on project for Rx and RxJS.

RxJS

Reactive programming is an asynchronous programming paradigm concerned with data streams and the propagation of change. event handling, asynchronous programming, and handling multiple values.

The observer pattern is a software design pattern in which an object, called the subject, maintains a list of its dependents, called observers, and notifies them automatically of state changes. This pattern is similar (but not identical) to the publish/subscribe design pattern.

Observables are declarative—that is, you define a function for publishing values, but it is not executed until a consumer subscribes to it. The subscribed consumer then receives notifications until the function completes, or until they unsubscribe

An observable can deliver multiple values of any type—literals, messages, or events, depending on the context.

A handler for receiving observable notifications implements the Observer interface. It is an object that defines callback methods to handle the three types of notifications that an observable can send:

of(...items)—Returns an Observable instance that synchronously delivers the values provided as arguments.

from(iterable)—Converts its argument to an Observable instance. This method is commonly used to convert an array to an observable.

Whether the stream was keystrokes, an HTTP response, or an interval timer, the interface for listening to values and stopping listening is the same.

RxJS (Reactive Extensions for JavaScript) is a library for reactive programming. RxJS provides an implementation of the Observable type, which is needed until the type becomes part of the language and until browsers support it.

Provides utility functions for creating and working with observables.

These utility functions can be used for:

  • Converting existing code for async operations into observables
  • Iterating through the values in a stream
  • Mapping values to different types
  • Filtering streams
  • Composing multiple streams

Observable creation functions

import { from } from 'rxjs';
import { interval } from 'rxjs';
import { fromEvent } from 'rxjs';
import { ajax } from 'rxjs/ajax';
import { of } from 'rxjs';
const nums = of(1, 2, 3);

// Create an Observable out of a promise
const data = from(fetch('/api/endpoint'));

// Create an Observable that will publish a value on an interval
const secondsCounter = interval(1000);

// Create an Observable that will publish mouse movements
const mouseMoves = fromEvent(el, 'mousemove');

// Create an Observable that will create an AJAX request
  const apiData = ajax('/api/data');

Operator

Operators are functions that build on the observables foundation to enable sophisticated manipulation of collections. map(), filter(), concat(), and flatMap().

We can use pipes to link operators together

A set of operators applied to an observable is a recipe.that is, a set of instructions for producing the values you’re interested in. By itself, the recipe doesn’t do anything. You need to call subscribe() to produce a result through the recipe.

receipe = Opertator(Observable) //we then subscribe to receipe

Observale.pipe()

observables named with a trailing “$” sign.

Multicasting

A typical observable creates a new, independent execution for each subscribed observer. Multicasting is the practice of broadcasting to a list of multiple subscribers in a single execution

Operators are functions. There are two kinds of operators:

A Pipeable Operator is a function that takes an Observable as its input and returns another Observable. It is a pure operation: the previous Observable stays unmodified.

Creation Operators are the other kind of operator, which can be called as standalone functions to create a new Observable.

Observables of Observables, so-called higher-order Observables

Edit on StackBlitz ⚡️

rxjs's People

Contributors

lapalb avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.