SlideShare a Scribd company logo
NO MORE PROMISES. LET'S RXJS
REACTIVE EXTENSIONS FOR JAVASCRIPT
A B O U T M E
{
"name": "Ilia Idakiev",
"experience": [
“Google Developer Expert (GDE)“,
"Developer & Co-founder @ HILLGRAND",
"Lecturer in 'Advanced JS' @ Sofia University",
"Contractor / Consultant",
"Public / Private Courses”
],
"involvedIn": [
"Angular Sofia", "SofiaJS / BeerJS",
]
}
!
FUNCTIONAL
PROGRAMMING
REACTIVE EXTENSIONS FOR JAVASCRIPT
FUNCTIONAL PROGRAMMING
▸ Functional programming is a programming paradigm
that treats computation as the evaluation of mathematical
functions and avoids changing-state and mutable data. It is
a declarative programming paradigm, which means
programming is done with expressions or declarations
instead of statements.
REACTIVE EXTENSIONS FOR JAVASCRIPT
IMPERATIVE VS DECLARATIVE PROGRAMMING
function getAdmins(users) {
const admins = [];
for (let i = 0; i < users.length; i++) {
const currentUser = users[i];
if (!currentUser.isAdmin) { continue; }
admins.push(currentUser);
}
return admins;
}
Imperative programming focuses on describing how a
program operates.
function getAdmins(users) {
return users.filter(
currentUser => currentUser.isAdmin
);
}
Declarative programming focuses on expressing the logic
of a computation without describing its control flow.
REACTIVE EXTENSIONS FOR JAVASCRIPT
FUNCTIONAL CONCEPTS
▸ Pure Functions
▸ Composition
▸ Immutability
▸ Higher-order functions (Functions as first-class citizens)
▸ Currying and Partial Application - translating the evaluation of a function that
takes multiple arguments into evaluating a sequence of functions.
▸ Lazy evaluation - evaluate when needed.
REACTIVE EXTENSIONS FOR JAVASCRIPT
REFERENTIAL TRANSPARENCY
▸ An expression is called referentially transparent if it can be replaced with its
corresponding value without changing the program's behaviour. This requires
that the expression is pure, that is to say the expression value must be the same
for the same inputs and its evaluation must have no side effects.
REACTIVE EXTENSIONS FOR JAVASCRIPT
FUNCTIONAL PROGRAMMING ADVANTAGES
▸ Cleaner Code - Easy to test, debug and reason about (no side effects).
▸ Modularity - Breaking large problems into small parts.
▸ Reusability - Pure functions can be reused and composed.
▸ Efficiency - Lazy Evaluation (evaluate when needed)
ASYNCHRONY
REACTIVE EXTENSIONS FOR JAVASCRIPT
ASYNCHRONOUS JAVASCRIPT
▸ Continuation Passing Style (CPS)
▸ CPS with named callbacks (to reduce callback hell)
▸ Futures and Promises / async - await
▸ Async data streams - RxJS
FUTURES AND PROMISES
REACTIVE EXTENSIONS FOR JAVASCRIPT
▸ Futures and promises originated in functional programming and related
paradigms (such as logic programming) to decouple a value (a future) from
how it was computed (a promise), allowing the computation to be done
more flexibly, notably by parallelizing it.
WHERE DO PROMISES COME FROM?
REACTIVE EXTENSIONS FOR JAVASCRIPT
▸ A Promise is a proxy for a value not necessarily known when the promise is
created.
▸ It allows you to associate handlers with an asynchronous action's eventual
success value or failure reason.
▸ This lets asynchronous methods return values like synchronous methods:
instead of immediately returning the final value, the asynchronous method
returns a promise to supply the value at some point in the future.
PROMISES
REACTIVE EXTENSIONS FOR JAVASCRIPT
▸ Pending - initial state, neither fulfilled nor rejected.
▸ Fulfilled - the operation completed successfully.
▸ Rejected - the operation failed.
PROMISE STATES (STATE MACHINE)
REACTIVE EXTENSIONS FOR JAVASCRIPT
PROMISE EXAMPLE
const promise = new Promise(function (resolve, reject) {
setTimeout(function () {
const randomNumber = Math.floor(Math.random() * Math.floor(10));
if (randomNumber % 2 === 0) {
resolve('Success');
return;
}
reject('Error');
}, 300);
});
promise.then(console.log).catch(console.error);
Controlling the machine state
REACTIVE EXTENSIONS FOR JAVASCRIPT
PROMISE EXAMPLE (2)
Promise.resolve(10).then(x => x + 10).then(console.log);
WAIT A MINUTE
THIS LOOKS VERY SIMILAR TO…
REACTIVE EXTENSIONS FOR JAVASCRIPT
JS ARRAYS
[10].map(x => x + 1).forEach(console.log);
WHY IS IT CALLED MAP?
CATEGORY THEORY
REACTIVE EXTENSIONS FOR JAVASCRIPT
▸ Mathematical Abstractions - Helps us getting rid of details so we can look at
things a different way.
▸ Main Parts of Category Theory:
▸ Objects and Morphisms (functions) (which form a Category)
▸ Functors
▸ Natural Transformations
CATEGORY THEORY
REACTIVE EXTENSIONS FOR JAVASCRIPT
CATEGORIES
▸ A category consists of a collection of objects (just
abstractions) and morphisms (functions).

(X, Y, Z - objects)
▸ The morphisms must obey the following laws:
▸ They must me composable.
▸ Compositions must me associative.
▸ For each object a, there is an identity morphism.
REACTIVE EXTENSIONS FOR JAVASCRIPT
CATEGORY THEORY IN JAVASCRIPT
add(1, 1) // > 2 - persists type
add(1, 0) // > 1 - identity function
add(1, 2) === add(2, 1) // > 3 - commutative
add(add(1, 2), 3) === add(1, add(2, 3)); // > 6 - associative and composable
multiply(2, add(3, 4)) === add(multiply(2, 3), multiply(2, 4)) // > 14 - distributive
REACTIVE EXTENSIONS FOR JAVASCRIPT
FUNCTORS
▸ A structure-preserving mapping between categories. (the return value is the same
type of functor)
▸ Let A and B be categories. A functor F from A to B is a mapping that:
▸ associates to each object a in A an object F(a) in B.
▸ associates to each morphism f in A a morphism F(f) in B such that the following two
conditions hold:
▸ F(ID(x)) = ID(F(X))
▸ F(g o f) = F(f) o F(g) for all morphisms f: x -> y, g: y -> z in A.
REACTIVE EXTENSIONS FOR JAVASCRIPT
CATEGORY THEORY OBJECTS IN JAVASCRIPT
const containerPrototype = {
map: function (fn) {
return Container(fn(this.value));
}
}
function Container(value) {
return Object.create(containerPrototype, { value: { value } });
}
console.log(Container(10).map(x => x + 100)); // > Container { value: 110 }
REACTIVE EXTENSIONS FOR JAVASCRIPT
CATEGORY THEORY OBJECTS IN JAVASCRIPT
Container(10).map(x => x + 100).map(x => '' + x); // > Container { value: '110' }
REACTIVE EXTENSIONS FOR JAVASCRIPT
CATEGORY THEORY OBJECTS IN JAVASCRIPT
[10].map(x => x + 100).map(x => '' + x);
REACTIVE EXTENSIONS FOR JAVASCRIPT
CATEGORY THEORY OBJECTS IN JAVASCRIPT
[10].map(x => x + 100).map(x => '' + x);
It’s a functor!
MAYBE FUNCTOR
REACTIVE EXTENSIONS FOR JAVASCRIPT
MAYBE FUNCTOR
const maybePrototype = {
map: function (fn) {
return this.value !== null ? Maybe(fn(this.value)) : Maybe(null);
}
}
function Maybe(value) {
return Object.create(maybePrototype, { value: { value } });
}
function matchFirst(string, regexp) {
return Maybe(string).map(string => string.match(regexp)).map(matches => matches[0]);
}
console.log(matchFirst(null, /test/)); // Maybe { value: null }
console.log(matchFirst('test', /rest/)); // Maybe { value: null }
console.log(matchFirst('test1test2', /testd/)); // Maybe { value: 'test1' }
REACTIVE EXTENSIONS FOR JAVASCRIPT
MAYBE FUNCTOR
const maybePrototype = {
map: function (fn) {
return this.value !== null ? Maybe(fn(this.value)) : Maybe(null);
}
}
function Maybe(value) {
return Object.create(maybePrototype, { value: { value } });
}
function matchFirst(string, regexp) {
return Maybe(string).map(string => string.match(regexp)).map(matches => matches[0]);
}
console.log(matchFirst(null, /test/)); // Maybe { value: null }
console.log(matchFirst('test', /rest/)); // Maybe { value: null }
console.log(matchFirst('test1test2', /testd/)); // Maybe { value: 'test1' }
REACTIVE EXTENSIONS FOR JAVASCRIPT
MAYBE FUNCTOR
const maybePrototype = {
map: function (fn) {
return this.value !== null ? Maybe(fn(this.value)) : Maybe(null);
}
}
function Maybe(value) {
return Object.create(maybePrototype, { value: { value } });
}
function matchFirst(string, regexp) {
return Maybe(string).map(string => string.match(regexp)).map(matches => matches[0]);
}
console.log(matchFirst(null, /test/)); // Maybe { value: null }
console.log(matchFirst('test', /rest/)); // Maybe { value: null }
console.log(matchFirst('test1test2', /testd/)); // Maybe { value: 'test1' }
REACTIVE EXTENSIONS FOR JAVASCRIPT
MAYBE FUNCTOR
const maybePrototype = {
map: function (fn) {
return this.value !== null ? Maybe(fn(this.value)) : Maybe(null);
}
}
function Maybe(value) {
return Object.create(maybePrototype, { value: { value } });
}
function matchFirst(string, regexp) {
return Maybe(string).map(string => string.match(regexp)).map(matches => matches[0]);
}
console.log(matchFirst(null, /test/)); // Maybe { value: null }
console.log(matchFirst('test', /rest/)); // Maybe { value: null }
console.log(matchFirst('test1test2', /testd/)); // Maybe { value: 'test1' }
REACTIVE EXTENSIONS FOR JAVASCRIPT
MAYBE FUNCTOR
const maybePrototype = {
map: function (fn) {
return this.value !== null ? Maybe(fn(this.value)) : Maybe(null);
}
}
function Maybe(value) {
return Object.create(maybePrototype, { value: { value } });
}
function matchFirst(string, regexp) {
return Maybe(string).map(string => string.match(regexp)).map(matches => matches[0]);
}
console.log(matchFirst(null, /test/)); // Maybe { value: null }
console.log(matchFirst('test', /rest/)); // Maybe { value: null }
console.log(matchFirst('test1test2', /testd/)); // Maybe { value: 'test1' }
REACTIVE EXTENSIONS FOR JAVASCRIPT
MAYBE FUNCTOR
const maybePrototype = {
map: function (fn) {
return this.value !== null ? Maybe(fn(this.value)) : Maybe(null);
}
}
function Maybe(value) {
return Object.create(maybePrototype, { value: { value } });
}
function matchFirst(string, regexp) {
return Maybe(string).map(string => string.match(regexp)).map(matches => matches[0]);
}
console.log(matchFirst(null, /test/)); // > Maybe { value: null }
console.log(matchFirst('test', /rest/)); // Maybe { value: null }
console.log(matchFirst('test1test2', /testd/)); // Maybe { value: 'test1' }
REACTIVE EXTENSIONS FOR JAVASCRIPT
MAYBE FUNCTOR
const maybePrototype = {
map: function (fn) {
return this.value !== null ? Maybe(fn(this.value)) : Maybe(null);
}
}
function Maybe(value) {
return Object.create(maybePrototype, { value: { value } });
}
function matchFirst(string, regexp) {
return Maybe(string).map(string => string.match(regexp)).map(matches => matches[0]);
}
console.log(matchFirst(null, /test/)); // > Maybe { value: null }
console.log(matchFirst('test', /rest/)); // > Maybe { value: null }
console.log(matchFirst('test1test2', /testd/)); // Maybe { value: 'test1' }
REACTIVE EXTENSIONS FOR JAVASCRIPT
MAYBE FUNCTOR
const maybePrototype = {
map: function (fn) {
return this.value !== null ? Maybe(fn(this.value)) : Maybe(null);
}
}
function Maybe(value) {
return Object.create(maybePrototype, { value: { value } });
}
function matchFirst(string, regexp) {
return Maybe(string).map(string => string.match(regexp)).map(matches => matches[0]);
}
console.log(matchFirst(null, /test/)); // > Maybe { value: null }
console.log(matchFirst('test', /rest/)); // > Maybe { value: null }
console.log(matchFirst('test1test2', /testd/)); // > Maybe { value: 'test1' }
ARE PROMISES FUNCTORS?
REACTIVE EXTENSIONS FOR JAVASCRIPT
PROMISE EXAMPLE (3)
Promise.resolve(10).then(x => x + 100).then(x => '' + x); // > Promise { value: '110' }
REACTIVE EXTENSIONS FOR JAVASCRIPT
PROMISE EXAMPLE (3)
Promise.resolve(10).then(x => x + 100).then(x => '' + x); // > Promise { value: '110' }
For values which are not promises, .then() acts like an asynchronous .map()
REACTIVE EXTENSIONS FOR JAVASCRIPT
PROMISE EXAMPLE (4)
Promise.resolve(10).then(x => Promise.resolve(x + 100)).then(x => '' + x);
// > Promise { value: '110' }
REACTIVE EXTENSIONS FOR JAVASCRIPT
PROMISE EXAMPLE (4)
Promise.resolve(10).then(x => Promise.resolve(x + 100)).then(x => '' + x);
// > Promise { value: '110' }
For values which are promises themselves, .then() acts like
the .flatMap() method from monads.
REACTIVE EXTENSIONS FOR JAVASCRIPT
PROMISE EXAMPLE (4)
Promise.resolve(10).then(x => Promise.resolve(x + 100)).then(x => '' + x);
// > Promise { value: '110' }
It’s flattening the structure! It’s not a functor!
REACTIVE EXTENSIONS FOR JAVASCRIPT
MONADS
▸ An extended functor.
▸ They flatten and map with context
YOU ALREADY ARE USING
MONADS!
REACTIVE EXTENSIONS FOR JAVASCRIPT
ARRAY.PROTOTYPE.FLAT AND ARRAY.PROTOTYPE.FLATMAP
[ 'H', ['e'], ['l'], ['l'], 'o'].flat();
[1, [2], 3].flatMap(val => val * 2)
SO WHAT ABOUT RXJS?
WHAT IS RXJS?
MARBLE TESTING RXJS STREAMS
REACTIVE EXTENSIONS FOR JAVASCRIPT
▸ RxJS is a library for reactive programming using
Observables, to make it easier to compose
asynchronous or callback-based code.
REACTIVE EXTENSIONS FOR JAVASCRIPT
CREATING AN OBSERVABLE (THE OLD WAY)
import 'rxjs/add/observable/of';
import ‘rxjs/add/operator/map';
of(10).map(x => x + 100).map(x => '' + x).subscribe(console.log);
REACTIVE EXTENSIONS FOR JAVASCRIPT
CREATING AN OBSERVABLE
import { of } from ‘rxjs';
import { map } from ‘rxjs/operators';
of(10).pipe(map(x => x + 100), map(x => '' + x)).subscribe(console.log);
IT’S A FUNCTOR!
REACTIVE EXTENSIONS FOR JAVASCRIPT
CREATING AN OBSERVABLE
import { of } from ‘rxjs';
import { map } from ‘rxjs/operators';
of(of(10), of(10)).pipe(switchMap(x => x), map(x => x + 100)).subscribe(console.log);
IT’S A MONAD!
WHAT ARE THE DIFFERENCES
RXJS AND PROMISES?
REACTIVE EXTENSIONS FOR JAVASCRIPT
CREATING AN OBSERVABLE STREAM (1)
import { from } from ‘rxjs';
import { map } from ‘rxjs/operators';
const stream$ = from([1, 2, 3, 4]).pipe(map(x => x + 1));
stream$.subscribe(console.log)
// > 2
// > 3
// > 4
// > 5
REACTIVE EXTENSIONS FOR JAVASCRIPT
CREATING AN OBSERVABLE STREAM (2)
import { interval } from ‘rxjs';
import { publish } from ‘rxjs/operators’;
const connectableTimer = interval(1000).pipe(publish());
connectableTimer.connect();
setTimeout(function () {
connectableTimer.subscribe(console.log);
// > 4
// > 5
// > 6
// > 7
// ...
}, 5000)
REACTIVE EXTENSIONS FOR JAVASCRIPT
HOT AND COLD OBSERVABLES
▸ Cold - An observable is “cold” if its underlying producer is created and
activated during subscription.
▸ Hot - An observable is “hot” if its underlying producer is either created or
activated outside of subscription.
1. OBSERVABLES ARE
STREAMS OF DATA(One or more values)
REACTIVE EXTENSIONS FOR JAVASCRIPT
COMMON THINGS THAT WE NEED
▸ debouncing
▸ cancelation
▸ retrying
▸ throttling
▸ timeouts
▸ detect only if something changed
RXJS HAS THEM ALL
2. BETTER FLOW CONTROL
(using the rxjs operators and rxjs observable factories/combiners)
3. DIFFERENT WAYS OF EMITTING DATA
(hot vs cold observables)
4. OBSERVABLES ARE CANCELLABLE
(using unsubscribe)
5. OBSERVABLES ARE LAZY
(we have to explicitly state that we want the observable to start)
6. CONTROLLING TIME(using schedulers)
WHAT IS COMMON ABOUT
RXJS AND PROMISES?
MARBLE TESTING RXJS STREAMS
WHAT IS COMMON ABOUT RXJS AND PROMISES?
▸ They are both monads like.
▸ Both are used to capture the effect of latency.
WHY ARE THEY REACTIVE?
DEMO
MARBLE TESTING RXJS STREAMS
CONNECT
GitHub > https://github.com/iliaidakiev (/slides/ - list of future and past events)
Twitter > @ilia_idakiev
THANK YOU!

More Related Content

What's hot

What's hot (20)

Reactive programming every day
Reactive programming every dayReactive programming every day
Reactive programming every day
 
React lecture
React lectureReact lecture
React lecture
 
RxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScriptRxJS - The Reactive extensions for JavaScript
RxJS - The Reactive extensions for JavaScript
 
Predictable reactive state management - ngrx
Predictable reactive state management - ngrxPredictable reactive state management - ngrx
Predictable reactive state management - ngrx
 
My Gentle Introduction to RxJS
My Gentle Introduction to RxJSMy Gentle Introduction to RxJS
My Gentle Introduction to RxJS
 
Ngrx: Redux in angular
Ngrx: Redux in angularNgrx: Redux in angular
Ngrx: Redux in angular
 
Practical RxJava for Android
Practical RxJava for AndroidPractical RxJava for Android
Practical RxJava for Android
 
RxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrowRxJS101 - What you need to know to get started with RxJS tomorrow
RxJS101 - What you need to know to get started with RxJS tomorrow
 
Solid principles in practice the clean architecture - Droidcon Italy
Solid principles in practice the clean architecture - Droidcon ItalySolid principles in practice the clean architecture - Droidcon Italy
Solid principles in practice the clean architecture - Droidcon Italy
 
Java script advance-auroskills (2)
Java script advance-auroskills (2)Java script advance-auroskills (2)
Java script advance-auroskills (2)
 
Angular and The Case for RxJS
Angular and The Case for RxJSAngular and The Case for RxJS
Angular and The Case for RxJS
 
Typescript barcelona
Typescript barcelonaTypescript barcelona
Typescript barcelona
 
Using React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIsUsing React, Redux and Saga with Lottoland APIs
Using React, Redux and Saga with Lottoland APIs
 
Practical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme ChangePractical QML - Key Navigation, Dynamic Language and Theme Change
Practical QML - Key Navigation, Dynamic Language and Theme Change
 
Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...
 
Java script – basic auroskills (2)
Java script – basic   auroskills (2)Java script – basic   auroskills (2)
Java script – basic auroskills (2)
 
Java script
Java scriptJava script
Java script
 
Async JavaScript Unit Testing
Async JavaScript Unit TestingAsync JavaScript Unit Testing
Async JavaScript Unit Testing
 
JavaScript Functions
JavaScript FunctionsJavaScript Functions
JavaScript Functions
 
Finagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at PinterestFinagle and Java Service Framework at Pinterest
Finagle and Java Service Framework at Pinterest
 

Similar to No more promises lets RxJS 2 Edit

TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
Eelco Visser
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
Sigma Software
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
Mario Fusco
 
Ekeko Technology Showdown at SoTeSoLa 2012
Ekeko Technology Showdown at SoTeSoLa 2012Ekeko Technology Showdown at SoTeSoLa 2012
Ekeko Technology Showdown at SoTeSoLa 2012
Coen De Roover
 

Similar to No more promises lets RxJS 2 Edit (20)

No More Promises! Let's RxJS!
No More Promises! Let's RxJS!No More Promises! Let's RxJS!
No More Promises! Let's RxJS!
 
Reactive Programming - ReactFoo 2020 - Aziz Khambati
Reactive Programming - ReactFoo 2020 - Aziz KhambatiReactive Programming - ReactFoo 2020 - Aziz Khambati
Reactive Programming - ReactFoo 2020 - Aziz Khambati
 
Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScript
 
Functional programming in javascript
Functional programming in javascriptFunctional programming in javascript
Functional programming in javascript
 
Coding in Style
Coding in StyleCoding in Style
Coding in Style
 
TI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class FunctionsTI1220 Lecture 6: First-class Functions
TI1220 Lecture 6: First-class Functions
 
Why react matters
Why react mattersWhy react matters
Why react matters
 
Composition birds-and-recursion
Composition birds-and-recursionComposition birds-and-recursion
Composition birds-and-recursion
 
CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 29
 
Cycle.js - Functional reactive UI framework (Nikos Kalogridis)
Cycle.js - Functional reactive UI framework (Nikos Kalogridis)Cycle.js - Functional reactive UI framework (Nikos Kalogridis)
Cycle.js - Functional reactive UI framework (Nikos Kalogridis)
 
Cycle.js - A functional reactive UI framework
Cycle.js - A functional reactive UI frameworkCycle.js - A functional reactive UI framework
Cycle.js - A functional reactive UI framework
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 
Столпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай МозговойСтолпы функционального программирования для адептов ООП, Николай Мозговой
Столпы функционального программирования для адептов ООП, Николай Мозговой
 
FP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyondFP in Java - Project Lambda and beyond
FP in Java - Project Lambda and beyond
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015   by Max PetruckReact, Redux, ES2015   by Max Petruck
React, Redux, ES2015 by Max Petruck
 
Scala for Java Devs
Scala for Java DevsScala for Java Devs
Scala for Java Devs
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 
Ekeko Technology Showdown at SoTeSoLa 2012
Ekeko Technology Showdown at SoTeSoLa 2012Ekeko Technology Showdown at SoTeSoLa 2012
Ekeko Technology Showdown at SoTeSoLa 2012
 
React, Redux, ES2015 by Max Petruck
React, Redux, ES2015 by Max PetruckReact, Redux, ES2015 by Max Petruck
React, Redux, ES2015 by Max Petruck
 
From Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risksFrom Java to Scala - advantages and possible risks
From Java to Scala - advantages and possible risks
 

More from Ilia Idakiev

More from Ilia Idakiev (14)

Deep Dive into Zone.JS
Deep Dive into Zone.JSDeep Dive into Zone.JS
Deep Dive into Zone.JS
 
Creating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-htmlCreating lightweight JS Apps w/ Web Components and lit-html
Creating lightweight JS Apps w/ Web Components and lit-html
 
Deterministic JavaScript Applications
Deterministic JavaScript ApplicationsDeterministic JavaScript Applications
Deterministic JavaScript Applications
 
Web Components Everywhere
Web Components EverywhereWeb Components Everywhere
Web Components Everywhere
 
Building Reusable Custom Elements With Angular
Building Reusable Custom Elements With AngularBuilding Reusable Custom Elements With Angular
Building Reusable Custom Elements With Angular
 
State management for enterprise angular applications
State management for enterprise angular applicationsState management for enterprise angular applications
State management for enterprise angular applications
 
Offline progressive web apps with NodeJS and React
Offline progressive web apps with NodeJS and ReactOffline progressive web apps with NodeJS and React
Offline progressive web apps with NodeJS and React
 
Testing rx js using marbles within angular
Testing rx js using marbles within angularTesting rx js using marbles within angular
Testing rx js using marbles within angular
 
Predictable reactive state management for enterprise apps using NGRX/platform
Predictable reactive state management for enterprise apps using NGRX/platformPredictable reactive state management for enterprise apps using NGRX/platform
Predictable reactive state management for enterprise apps using NGRX/platform
 
Angular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of SpeedAngular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of Speed
 
Angular Offline Progressive Web Apps With NodeJS
Angular Offline Progressive Web Apps With NodeJSAngular Offline Progressive Web Apps With NodeJS
Angular Offline Progressive Web Apps With NodeJS
 
Introduction to Offline Progressive Web Applications
Introduction to Offline Progressive Web ApplicationsIntroduction to Offline Progressive Web Applications
Introduction to Offline Progressive Web Applications
 
Reflective injection using TypeScript
Reflective injection using TypeScriptReflective injection using TypeScript
Reflective injection using TypeScript
 
Zone.js
Zone.jsZone.js
Zone.js
 

Recently uploaded

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 

Recently uploaded (20)

Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 

No more promises lets RxJS 2 Edit

  • 1. NO MORE PROMISES. LET'S RXJS REACTIVE EXTENSIONS FOR JAVASCRIPT
  • 2. A B O U T M E { "name": "Ilia Idakiev", "experience": [ “Google Developer Expert (GDE)“, "Developer & Co-founder @ HILLGRAND", "Lecturer in 'Advanced JS' @ Sofia University", "Contractor / Consultant", "Public / Private Courses” ], "involvedIn": [ "Angular Sofia", "SofiaJS / BeerJS", ] } !
  • 4. REACTIVE EXTENSIONS FOR JAVASCRIPT FUNCTIONAL PROGRAMMING ▸ Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data. It is a declarative programming paradigm, which means programming is done with expressions or declarations instead of statements.
  • 5. REACTIVE EXTENSIONS FOR JAVASCRIPT IMPERATIVE VS DECLARATIVE PROGRAMMING function getAdmins(users) { const admins = []; for (let i = 0; i < users.length; i++) { const currentUser = users[i]; if (!currentUser.isAdmin) { continue; } admins.push(currentUser); } return admins; } Imperative programming focuses on describing how a program operates. function getAdmins(users) { return users.filter( currentUser => currentUser.isAdmin ); } Declarative programming focuses on expressing the logic of a computation without describing its control flow.
  • 6. REACTIVE EXTENSIONS FOR JAVASCRIPT FUNCTIONAL CONCEPTS ▸ Pure Functions ▸ Composition ▸ Immutability ▸ Higher-order functions (Functions as first-class citizens) ▸ Currying and Partial Application - translating the evaluation of a function that takes multiple arguments into evaluating a sequence of functions. ▸ Lazy evaluation - evaluate when needed.
  • 7. REACTIVE EXTENSIONS FOR JAVASCRIPT REFERENTIAL TRANSPARENCY ▸ An expression is called referentially transparent if it can be replaced with its corresponding value without changing the program's behaviour. This requires that the expression is pure, that is to say the expression value must be the same for the same inputs and its evaluation must have no side effects.
  • 8. REACTIVE EXTENSIONS FOR JAVASCRIPT FUNCTIONAL PROGRAMMING ADVANTAGES ▸ Cleaner Code - Easy to test, debug and reason about (no side effects). ▸ Modularity - Breaking large problems into small parts. ▸ Reusability - Pure functions can be reused and composed. ▸ Efficiency - Lazy Evaluation (evaluate when needed)
  • 10. REACTIVE EXTENSIONS FOR JAVASCRIPT ASYNCHRONOUS JAVASCRIPT ▸ Continuation Passing Style (CPS) ▸ CPS with named callbacks (to reduce callback hell) ▸ Futures and Promises / async - await ▸ Async data streams - RxJS
  • 12. REACTIVE EXTENSIONS FOR JAVASCRIPT ▸ Futures and promises originated in functional programming and related paradigms (such as logic programming) to decouple a value (a future) from how it was computed (a promise), allowing the computation to be done more flexibly, notably by parallelizing it. WHERE DO PROMISES COME FROM?
  • 13. REACTIVE EXTENSIONS FOR JAVASCRIPT ▸ A Promise is a proxy for a value not necessarily known when the promise is created. ▸ It allows you to associate handlers with an asynchronous action's eventual success value or failure reason. ▸ This lets asynchronous methods return values like synchronous methods: instead of immediately returning the final value, the asynchronous method returns a promise to supply the value at some point in the future. PROMISES
  • 14. REACTIVE EXTENSIONS FOR JAVASCRIPT ▸ Pending - initial state, neither fulfilled nor rejected. ▸ Fulfilled - the operation completed successfully. ▸ Rejected - the operation failed. PROMISE STATES (STATE MACHINE)
  • 15. REACTIVE EXTENSIONS FOR JAVASCRIPT PROMISE EXAMPLE const promise = new Promise(function (resolve, reject) { setTimeout(function () { const randomNumber = Math.floor(Math.random() * Math.floor(10)); if (randomNumber % 2 === 0) { resolve('Success'); return; } reject('Error'); }, 300); }); promise.then(console.log).catch(console.error); Controlling the machine state
  • 16. REACTIVE EXTENSIONS FOR JAVASCRIPT PROMISE EXAMPLE (2) Promise.resolve(10).then(x => x + 10).then(console.log);
  • 17. WAIT A MINUTE THIS LOOKS VERY SIMILAR TO…
  • 18. REACTIVE EXTENSIONS FOR JAVASCRIPT JS ARRAYS [10].map(x => x + 1).forEach(console.log);
  • 19. WHY IS IT CALLED MAP?
  • 21. REACTIVE EXTENSIONS FOR JAVASCRIPT ▸ Mathematical Abstractions - Helps us getting rid of details so we can look at things a different way. ▸ Main Parts of Category Theory: ▸ Objects and Morphisms (functions) (which form a Category) ▸ Functors ▸ Natural Transformations CATEGORY THEORY
  • 22. REACTIVE EXTENSIONS FOR JAVASCRIPT CATEGORIES ▸ A category consists of a collection of objects (just abstractions) and morphisms (functions).
 (X, Y, Z - objects) ▸ The morphisms must obey the following laws: ▸ They must me composable. ▸ Compositions must me associative. ▸ For each object a, there is an identity morphism.
  • 23. REACTIVE EXTENSIONS FOR JAVASCRIPT CATEGORY THEORY IN JAVASCRIPT add(1, 1) // > 2 - persists type add(1, 0) // > 1 - identity function add(1, 2) === add(2, 1) // > 3 - commutative add(add(1, 2), 3) === add(1, add(2, 3)); // > 6 - associative and composable multiply(2, add(3, 4)) === add(multiply(2, 3), multiply(2, 4)) // > 14 - distributive
  • 24. REACTIVE EXTENSIONS FOR JAVASCRIPT FUNCTORS ▸ A structure-preserving mapping between categories. (the return value is the same type of functor) ▸ Let A and B be categories. A functor F from A to B is a mapping that: ▸ associates to each object a in A an object F(a) in B. ▸ associates to each morphism f in A a morphism F(f) in B such that the following two conditions hold: ▸ F(ID(x)) = ID(F(X)) ▸ F(g o f) = F(f) o F(g) for all morphisms f: x -> y, g: y -> z in A.
  • 25. REACTIVE EXTENSIONS FOR JAVASCRIPT CATEGORY THEORY OBJECTS IN JAVASCRIPT const containerPrototype = { map: function (fn) { return Container(fn(this.value)); } } function Container(value) { return Object.create(containerPrototype, { value: { value } }); } console.log(Container(10).map(x => x + 100)); // > Container { value: 110 }
  • 26. REACTIVE EXTENSIONS FOR JAVASCRIPT CATEGORY THEORY OBJECTS IN JAVASCRIPT Container(10).map(x => x + 100).map(x => '' + x); // > Container { value: '110' }
  • 27. REACTIVE EXTENSIONS FOR JAVASCRIPT CATEGORY THEORY OBJECTS IN JAVASCRIPT [10].map(x => x + 100).map(x => '' + x);
  • 28. REACTIVE EXTENSIONS FOR JAVASCRIPT CATEGORY THEORY OBJECTS IN JAVASCRIPT [10].map(x => x + 100).map(x => '' + x); It’s a functor!
  • 30. REACTIVE EXTENSIONS FOR JAVASCRIPT MAYBE FUNCTOR const maybePrototype = { map: function (fn) { return this.value !== null ? Maybe(fn(this.value)) : Maybe(null); } } function Maybe(value) { return Object.create(maybePrototype, { value: { value } }); } function matchFirst(string, regexp) { return Maybe(string).map(string => string.match(regexp)).map(matches => matches[0]); } console.log(matchFirst(null, /test/)); // Maybe { value: null } console.log(matchFirst('test', /rest/)); // Maybe { value: null } console.log(matchFirst('test1test2', /testd/)); // Maybe { value: 'test1' }
  • 31. REACTIVE EXTENSIONS FOR JAVASCRIPT MAYBE FUNCTOR const maybePrototype = { map: function (fn) { return this.value !== null ? Maybe(fn(this.value)) : Maybe(null); } } function Maybe(value) { return Object.create(maybePrototype, { value: { value } }); } function matchFirst(string, regexp) { return Maybe(string).map(string => string.match(regexp)).map(matches => matches[0]); } console.log(matchFirst(null, /test/)); // Maybe { value: null } console.log(matchFirst('test', /rest/)); // Maybe { value: null } console.log(matchFirst('test1test2', /testd/)); // Maybe { value: 'test1' }
  • 32. REACTIVE EXTENSIONS FOR JAVASCRIPT MAYBE FUNCTOR const maybePrototype = { map: function (fn) { return this.value !== null ? Maybe(fn(this.value)) : Maybe(null); } } function Maybe(value) { return Object.create(maybePrototype, { value: { value } }); } function matchFirst(string, regexp) { return Maybe(string).map(string => string.match(regexp)).map(matches => matches[0]); } console.log(matchFirst(null, /test/)); // Maybe { value: null } console.log(matchFirst('test', /rest/)); // Maybe { value: null } console.log(matchFirst('test1test2', /testd/)); // Maybe { value: 'test1' }
  • 33. REACTIVE EXTENSIONS FOR JAVASCRIPT MAYBE FUNCTOR const maybePrototype = { map: function (fn) { return this.value !== null ? Maybe(fn(this.value)) : Maybe(null); } } function Maybe(value) { return Object.create(maybePrototype, { value: { value } }); } function matchFirst(string, regexp) { return Maybe(string).map(string => string.match(regexp)).map(matches => matches[0]); } console.log(matchFirst(null, /test/)); // Maybe { value: null } console.log(matchFirst('test', /rest/)); // Maybe { value: null } console.log(matchFirst('test1test2', /testd/)); // Maybe { value: 'test1' }
  • 34. REACTIVE EXTENSIONS FOR JAVASCRIPT MAYBE FUNCTOR const maybePrototype = { map: function (fn) { return this.value !== null ? Maybe(fn(this.value)) : Maybe(null); } } function Maybe(value) { return Object.create(maybePrototype, { value: { value } }); } function matchFirst(string, regexp) { return Maybe(string).map(string => string.match(regexp)).map(matches => matches[0]); } console.log(matchFirst(null, /test/)); // Maybe { value: null } console.log(matchFirst('test', /rest/)); // Maybe { value: null } console.log(matchFirst('test1test2', /testd/)); // Maybe { value: 'test1' }
  • 35. REACTIVE EXTENSIONS FOR JAVASCRIPT MAYBE FUNCTOR const maybePrototype = { map: function (fn) { return this.value !== null ? Maybe(fn(this.value)) : Maybe(null); } } function Maybe(value) { return Object.create(maybePrototype, { value: { value } }); } function matchFirst(string, regexp) { return Maybe(string).map(string => string.match(regexp)).map(matches => matches[0]); } console.log(matchFirst(null, /test/)); // > Maybe { value: null } console.log(matchFirst('test', /rest/)); // Maybe { value: null } console.log(matchFirst('test1test2', /testd/)); // Maybe { value: 'test1' }
  • 36. REACTIVE EXTENSIONS FOR JAVASCRIPT MAYBE FUNCTOR const maybePrototype = { map: function (fn) { return this.value !== null ? Maybe(fn(this.value)) : Maybe(null); } } function Maybe(value) { return Object.create(maybePrototype, { value: { value } }); } function matchFirst(string, regexp) { return Maybe(string).map(string => string.match(regexp)).map(matches => matches[0]); } console.log(matchFirst(null, /test/)); // > Maybe { value: null } console.log(matchFirst('test', /rest/)); // > Maybe { value: null } console.log(matchFirst('test1test2', /testd/)); // Maybe { value: 'test1' }
  • 37. REACTIVE EXTENSIONS FOR JAVASCRIPT MAYBE FUNCTOR const maybePrototype = { map: function (fn) { return this.value !== null ? Maybe(fn(this.value)) : Maybe(null); } } function Maybe(value) { return Object.create(maybePrototype, { value: { value } }); } function matchFirst(string, regexp) { return Maybe(string).map(string => string.match(regexp)).map(matches => matches[0]); } console.log(matchFirst(null, /test/)); // > Maybe { value: null } console.log(matchFirst('test', /rest/)); // > Maybe { value: null } console.log(matchFirst('test1test2', /testd/)); // > Maybe { value: 'test1' }
  • 39. REACTIVE EXTENSIONS FOR JAVASCRIPT PROMISE EXAMPLE (3) Promise.resolve(10).then(x => x + 100).then(x => '' + x); // > Promise { value: '110' }
  • 40. REACTIVE EXTENSIONS FOR JAVASCRIPT PROMISE EXAMPLE (3) Promise.resolve(10).then(x => x + 100).then(x => '' + x); // > Promise { value: '110' } For values which are not promises, .then() acts like an asynchronous .map()
  • 41. REACTIVE EXTENSIONS FOR JAVASCRIPT PROMISE EXAMPLE (4) Promise.resolve(10).then(x => Promise.resolve(x + 100)).then(x => '' + x); // > Promise { value: '110' }
  • 42. REACTIVE EXTENSIONS FOR JAVASCRIPT PROMISE EXAMPLE (4) Promise.resolve(10).then(x => Promise.resolve(x + 100)).then(x => '' + x); // > Promise { value: '110' } For values which are promises themselves, .then() acts like the .flatMap() method from monads.
  • 43. REACTIVE EXTENSIONS FOR JAVASCRIPT PROMISE EXAMPLE (4) Promise.resolve(10).then(x => Promise.resolve(x + 100)).then(x => '' + x); // > Promise { value: '110' } It’s flattening the structure! It’s not a functor!
  • 44. REACTIVE EXTENSIONS FOR JAVASCRIPT MONADS ▸ An extended functor. ▸ They flatten and map with context
  • 45. YOU ALREADY ARE USING MONADS!
  • 46. REACTIVE EXTENSIONS FOR JAVASCRIPT ARRAY.PROTOTYPE.FLAT AND ARRAY.PROTOTYPE.FLATMAP [ 'H', ['e'], ['l'], ['l'], 'o'].flat(); [1, [2], 3].flatMap(val => val * 2)
  • 47. SO WHAT ABOUT RXJS?
  • 49. MARBLE TESTING RXJS STREAMS REACTIVE EXTENSIONS FOR JAVASCRIPT ▸ RxJS is a library for reactive programming using Observables, to make it easier to compose asynchronous or callback-based code.
  • 50. REACTIVE EXTENSIONS FOR JAVASCRIPT CREATING AN OBSERVABLE (THE OLD WAY) import 'rxjs/add/observable/of'; import ‘rxjs/add/operator/map'; of(10).map(x => x + 100).map(x => '' + x).subscribe(console.log);
  • 51. REACTIVE EXTENSIONS FOR JAVASCRIPT CREATING AN OBSERVABLE import { of } from ‘rxjs'; import { map } from ‘rxjs/operators'; of(10).pipe(map(x => x + 100), map(x => '' + x)).subscribe(console.log);
  • 53. REACTIVE EXTENSIONS FOR JAVASCRIPT CREATING AN OBSERVABLE import { of } from ‘rxjs'; import { map } from ‘rxjs/operators'; of(of(10), of(10)).pipe(switchMap(x => x), map(x => x + 100)).subscribe(console.log);
  • 55. WHAT ARE THE DIFFERENCES RXJS AND PROMISES?
  • 56. REACTIVE EXTENSIONS FOR JAVASCRIPT CREATING AN OBSERVABLE STREAM (1) import { from } from ‘rxjs'; import { map } from ‘rxjs/operators'; const stream$ = from([1, 2, 3, 4]).pipe(map(x => x + 1)); stream$.subscribe(console.log) // > 2 // > 3 // > 4 // > 5
  • 57. REACTIVE EXTENSIONS FOR JAVASCRIPT CREATING AN OBSERVABLE STREAM (2) import { interval } from ‘rxjs'; import { publish } from ‘rxjs/operators’; const connectableTimer = interval(1000).pipe(publish()); connectableTimer.connect(); setTimeout(function () { connectableTimer.subscribe(console.log); // > 4 // > 5 // > 6 // > 7 // ... }, 5000)
  • 58. REACTIVE EXTENSIONS FOR JAVASCRIPT HOT AND COLD OBSERVABLES ▸ Cold - An observable is “cold” if its underlying producer is created and activated during subscription. ▸ Hot - An observable is “hot” if its underlying producer is either created or activated outside of subscription.
  • 59. 1. OBSERVABLES ARE STREAMS OF DATA(One or more values)
  • 60. REACTIVE EXTENSIONS FOR JAVASCRIPT COMMON THINGS THAT WE NEED ▸ debouncing ▸ cancelation ▸ retrying ▸ throttling ▸ timeouts ▸ detect only if something changed
  • 62. 2. BETTER FLOW CONTROL (using the rxjs operators and rxjs observable factories/combiners)
  • 63. 3. DIFFERENT WAYS OF EMITTING DATA (hot vs cold observables)
  • 64. 4. OBSERVABLES ARE CANCELLABLE (using unsubscribe)
  • 65. 5. OBSERVABLES ARE LAZY (we have to explicitly state that we want the observable to start)
  • 67. WHAT IS COMMON ABOUT RXJS AND PROMISES?
  • 68. MARBLE TESTING RXJS STREAMS WHAT IS COMMON ABOUT RXJS AND PROMISES? ▸ They are both monads like. ▸ Both are used to capture the effect of latency.
  • 69. WHY ARE THEY REACTIVE?
  • 70. DEMO
  • 71. MARBLE TESTING RXJS STREAMS CONNECT GitHub > https://github.com/iliaidakiev (/slides/ - list of future and past events) Twitter > @ilia_idakiev