SlideShare a Scribd company logo
1 of 18
Reactive
Programming
Dwi Randy H - iOS Engineer
Overview
● What is Reactive Programming?
○ Reactive programming is a general programming term that is focused on reacting to changes, such
as data values or events. It can and often is done imperatively. A callback,delegate is an approach
to reactive programmingdone imperatively.
● Why we need Reactive Programming
○ More loosely coupled code
○ Make it easy to manage thread
○ A lot of operators that simplify work
○ Help to solve Real-Time Complex UI
○ Multi-platform standard
Example of Reactive Programming
A spreadsheet is a great example of reactive programming: cells dependent on other cells
automatically “react” when those other cells change.
Reference: https://learning.oreilly.com/library/view/reactive-programming-with/9781491931646/ch01.html
Rx Basic Building Blocks
● Observables = Dog
● Subscribers = Child
● Operators = Process
Down
Observables
Observable are the data source/stream, then that
observer reacts to whatever item or sequence of items
the observables emits.
They can emit data, completion and also failure
Hot and Cold Observables
Cold observables don’t do
anything until someone
starts observing them
(subscribe in Rx). They only
start running when they are
consumed
Hot Observables that can
active before subscription,
when an observer subscribes
to hot observable it will get
all values in the stream that
are emitted
Cold Observable
Hot Observable (Subject)
When We Need Cold or Hot
When we need to observable to
generating new values when
someone subscribing it and the
values are also not shared among
subscribers For example when we
call the API, Getting data from
local database
When you have Observable and we want
multiple subscribers to it, and you don’t
want them to cause regenerating the
values but rather reusing existing values
For example as LiveData in MVVM iOS
Reference: https://github.com/Reactive-Extensions/RxJS/blob/master/doc/gettingstarted/creating.md#cold-vs-hot-observables
Operator
An operator is simply a function that performs a
specific action. It takes a value, does something
with it and then returns it
● Creating
● Transforming
● Filtering
● Combining
Operator (Creating)
● Create
Create an observable from scratch by
calling observer method programmatically
● Just
Convert an object into Observable that
emits that object
Operator (Transforming)
● Map
Transform the items emitted by an
Observable by applying a function to each
item
● FlatMap
Transform the items emitted by an
Observable into Observables, then flatten
the emissions from those into a single
Observable
Observers
Observers consumes the data stream emitted by
observables
Observers subscribe to observable using subscribeOn()
method to receive data and then the data will be received
in onNext() callback()
Observer Callback
OnNext()
The callback to receive a
valueless notification of type
complete from the Observable.
OnComplete()
The callback to receive a
valueless notification of type
complete from the Observable.
onError()
The callback to receive notifications of
type error from the Observable, with an
attached Error.
Scheduler
Scheduler are component that tells observables
and observers on which thread they should run
- subscribeOn()
Specifies on which Scheduler to
Observables should operate
- observeOn()
Specifies on which Scheduler/Thread the
Subscribers should be notified
Scheduler Types Used
- Schedulers.io()
It is used for non CPU-intensive I/O type work
including interaction with the file system, performing
network calls, database interactions. This is usually
used in subscribeOn method
- Schedulers.computation
It is used for computational or CPU-intensive work
such as resizing images, processing large data sets,
Reference: https://proandroiddev.com/understanding-rxjava-subscribeon-and-observeon-
744b0c6a41ea
- AndroidSchedulers.trampoline
This is used to executes tasks in a FIFO (First
In, First Out). This scheduler runs the code on
current thread for example for Unit Testing
- AndroidSchedulers.mainThread()
This is used to bring back the execution to the
main thread so that UI modification can be
made. This is usually used in observeOn
method.
RxBinding & RxCocoa
- Library that makes it easier to use UI Component with reactive techniques.
Reference: https://github.com/ReactiveX/RxSwift
Thank you!

More Related Content

What's hot

[Webinar]: Working with Reactive Spring
[Webinar]: Working with Reactive Spring[Webinar]: Working with Reactive Spring
[Webinar]: Working with Reactive SpringKnoldus Inc.
 
How to build a streaming Lakehouse with Flink, Kafka, and Hudi
How to build a streaming Lakehouse with Flink, Kafka, and HudiHow to build a streaming Lakehouse with Flink, Kafka, and Hudi
How to build a streaming Lakehouse with Flink, Kafka, and HudiFlink Forward
 
Hello, kafka! (an introduction to apache kafka)
Hello, kafka! (an introduction to apache kafka)Hello, kafka! (an introduction to apache kafka)
Hello, kafka! (an introduction to apache kafka)Timothy Spann
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOPDzmitry Naskou
 
Reactive Programming in Java and Spring Framework 5
Reactive Programming in Java and Spring Framework 5Reactive Programming in Java and Spring Framework 5
Reactive Programming in Java and Spring Framework 5Richard Langlois P. Eng.
 
Spring batch introduction
Spring batch introductionSpring batch introduction
Spring batch introductionAlex Fernandez
 
Apache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing dataApache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing dataDataWorks Summit/Hadoop Summit
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentationOleksii Usyk
 
A Thorough Comparison of Delta Lake, Iceberg and Hudi
A Thorough Comparison of Delta Lake, Iceberg and HudiA Thorough Comparison of Delta Lake, Iceberg and Hudi
A Thorough Comparison of Delta Lake, Iceberg and HudiDatabricks
 
Flink Batch Processing and Iterations
Flink Batch Processing and IterationsFlink Batch Processing and Iterations
Flink Batch Processing and IterationsSameer Wadkar
 
Fundamentals of Stream Processing with Apache Beam, Tyler Akidau, Frances Perry
Fundamentals of Stream Processing with Apache Beam, Tyler Akidau, Frances Perry Fundamentals of Stream Processing with Apache Beam, Tyler Akidau, Frances Perry
Fundamentals of Stream Processing with Apache Beam, Tyler Akidau, Frances Perry confluent
 
Spring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise PlatformSpring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise PlatformVMware Tanzu
 
Reactive stream processing using Akka streams
Reactive stream processing using Akka streams Reactive stream processing using Akka streams
Reactive stream processing using Akka streams Johan Andrén
 
Hudi architecture, fundamentals and capabilities
Hudi architecture, fundamentals and capabilitiesHudi architecture, fundamentals and capabilities
Hudi architecture, fundamentals and capabilitiesNishith Agarwal
 
Introduction to Spring Cloud
Introduction to Spring Cloud           Introduction to Spring Cloud
Introduction to Spring Cloud VMware Tanzu
 

What's hot (20)

[Webinar]: Working with Reactive Spring
[Webinar]: Working with Reactive Spring[Webinar]: Working with Reactive Spring
[Webinar]: Working with Reactive Spring
 
How to build a streaming Lakehouse with Flink, Kafka, and Hudi
How to build a streaming Lakehouse with Flink, Kafka, and HudiHow to build a streaming Lakehouse with Flink, Kafka, and Hudi
How to build a streaming Lakehouse with Flink, Kafka, and Hudi
 
Hello, kafka! (an introduction to apache kafka)
Hello, kafka! (an introduction to apache kafka)Hello, kafka! (an introduction to apache kafka)
Hello, kafka! (an introduction to apache kafka)
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
 
Reactive Programming in Java and Spring Framework 5
Reactive Programming in Java and Spring Framework 5Reactive Programming in Java and Spring Framework 5
Reactive Programming in Java and Spring Framework 5
 
Spring batch introduction
Spring batch introductionSpring batch introduction
Spring batch introduction
 
Apache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing dataApache Beam: A unified model for batch and stream processing data
Apache Beam: A unified model for batch and stream processing data
 
Spring data presentation
Spring data presentationSpring data presentation
Spring data presentation
 
Spring Webflux
Spring WebfluxSpring Webflux
Spring Webflux
 
Swagger UI
Swagger UISwagger UI
Swagger UI
 
A Thorough Comparison of Delta Lake, Iceberg and Hudi
A Thorough Comparison of Delta Lake, Iceberg and HudiA Thorough Comparison of Delta Lake, Iceberg and Hudi
A Thorough Comparison of Delta Lake, Iceberg and Hudi
 
Flink Batch Processing and Iterations
Flink Batch Processing and IterationsFlink Batch Processing and Iterations
Flink Batch Processing and Iterations
 
Fundamentals of Stream Processing with Apache Beam, Tyler Akidau, Frances Perry
Fundamentals of Stream Processing with Apache Beam, Tyler Akidau, Frances Perry Fundamentals of Stream Processing with Apache Beam, Tyler Akidau, Frances Perry
Fundamentals of Stream Processing with Apache Beam, Tyler Akidau, Frances Perry
 
Spring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise PlatformSpring Boot+Kafka: the New Enterprise Platform
Spring Boot+Kafka: the New Enterprise Platform
 
Reactive stream processing using Akka streams
Reactive stream processing using Akka streams Reactive stream processing using Akka streams
Reactive stream processing using Akka streams
 
Spring Batch 2.0
Spring Batch 2.0Spring Batch 2.0
Spring Batch 2.0
 
Reactive programming intro
Reactive programming introReactive programming intro
Reactive programming intro
 
Hudi architecture, fundamentals and capabilities
Hudi architecture, fundamentals and capabilitiesHudi architecture, fundamentals and capabilities
Hudi architecture, fundamentals and capabilities
 
Introduction to Spring Cloud
Introduction to Spring Cloud           Introduction to Spring Cloud
Introduction to Spring Cloud
 
Kafka 101
Kafka 101Kafka 101
Kafka 101
 

Similar to Introduction to Reactive programming

Reactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaNexThoughts Technologies
 
Reactive Programming
Reactive ProgrammingReactive Programming
Reactive ProgrammingKnoldus Inc.
 
Introduction to RxJava on Android
Introduction to RxJava on AndroidIntroduction to RxJava on Android
Introduction to RxJava on AndroidChris Arriola
 
RxJava 2 Reactive extensions for the JVM
RxJava 2  Reactive extensions for the JVMRxJava 2  Reactive extensions for the JVM
RxJava 2 Reactive extensions for the JVMNetesh Kumar
 
Observables in Angular
Observables in AngularObservables in Angular
Observables in AngularKnoldus Inc.
 
Intro to Functional Programming with RxJava
Intro to Functional Programming with RxJavaIntro to Functional Programming with RxJava
Intro to Functional Programming with RxJavaMike Nakhimovich
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programmingAraf Karsh Hamid
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014Thomas Lockney
 
TDC2016SP - Trilha Node.Js
TDC2016SP - Trilha Node.JsTDC2016SP - Trilha Node.Js
TDC2016SP - Trilha Node.Jstdc-globalcode
 
RxJava2 Slides
RxJava2 SlidesRxJava2 Slides
RxJava2 SlidesYarikS
 
Андрій Рева, "How to build reactive java application"
Андрій Рева, "How to build reactive java application"Андрій Рева, "How to build reactive java application"
Андрій Рева, "How to build reactive java application"Sigma Software
 
Predictable reactive state management - ngrx
Predictable reactive state management - ngrxPredictable reactive state management - ngrx
Predictable reactive state management - ngrxIlia Idakiev
 
Nicholas Gustilo "Clean Android: building great mobile apps"
Nicholas Gustilo "Clean Android: building great mobile apps"Nicholas Gustilo "Clean Android: building great mobile apps"
Nicholas Gustilo "Clean Android: building great mobile apps"IT Event
 
Workflows via Event driven architecture
Workflows via Event driven architectureWorkflows via Event driven architecture
Workflows via Event driven architectureMilan Patel
 
Angular 16 – the rise of Signals
Angular 16 – the rise of SignalsAngular 16 – the rise of Signals
Angular 16 – the rise of SignalsCoding Academy
 

Similar to Introduction to Reactive programming (20)

Reactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJava
 
Reactive Programming
Reactive ProgrammingReactive Programming
Reactive Programming
 
Introduction to RxJava on Android
Introduction to RxJava on AndroidIntroduction to RxJava on Android
Introduction to RxJava on Android
 
RxJava 2 Reactive extensions for the JVM
RxJava 2  Reactive extensions for the JVMRxJava 2  Reactive extensions for the JVM
RxJava 2 Reactive extensions for the JVM
 
RxJava@Android
RxJava@AndroidRxJava@Android
RxJava@Android
 
Introduction to reactive programming
Introduction to reactive programmingIntroduction to reactive programming
Introduction to reactive programming
 
Observables in Angular
Observables in AngularObservables in Angular
Observables in Angular
 
Intro to Functional Programming with RxJava
Intro to Functional Programming with RxJavaIntro to Functional Programming with RxJava
Intro to Functional Programming with RxJava
 
RxSwift
RxSwiftRxSwift
RxSwift
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programming
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Reactive programming   using rx java & akka actors - pdx-scala - june 2014Reactive programming   using rx java & akka actors - pdx-scala - june 2014
Reactive programming using rx java & akka actors - pdx-scala - june 2014
 
TDC2016SP - Trilha Node.Js
TDC2016SP - Trilha Node.JsTDC2016SP - Trilha Node.Js
TDC2016SP - Trilha Node.Js
 
RxJava2 Slides
RxJava2 SlidesRxJava2 Slides
RxJava2 Slides
 
Андрій Рева, "How to build reactive java application"
Андрій Рева, "How to build reactive java application"Андрій Рева, "How to build reactive java application"
Андрій Рева, "How to build reactive java application"
 
Predictable reactive state management - ngrx
Predictable reactive state management - ngrxPredictable reactive state management - ngrx
Predictable reactive state management - ngrx
 
Nicholas Gustilo "Clean Android: building great mobile apps"
Nicholas Gustilo "Clean Android: building great mobile apps"Nicholas Gustilo "Clean Android: building great mobile apps"
Nicholas Gustilo "Clean Android: building great mobile apps"
 
Introduction to Redux.pptx
Introduction to Redux.pptxIntroduction to Redux.pptx
Introduction to Redux.pptx
 
Workflows via Event driven architecture
Workflows via Event driven architectureWorkflows via Event driven architecture
Workflows via Event driven architecture
 
Javantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
Javantura v3 - Going Reactive with RxJava – Hrvoje CrnjakJavantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
Javantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
 
Angular 16 – the rise of Signals
Angular 16 – the rise of SignalsAngular 16 – the rise of Signals
Angular 16 – the rise of Signals
 

Recently uploaded

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 

Recently uploaded (20)

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 

Introduction to Reactive programming

  • 2. Overview ● What is Reactive Programming? ○ Reactive programming is a general programming term that is focused on reacting to changes, such as data values or events. It can and often is done imperatively. A callback,delegate is an approach to reactive programmingdone imperatively. ● Why we need Reactive Programming ○ More loosely coupled code ○ Make it easy to manage thread ○ A lot of operators that simplify work ○ Help to solve Real-Time Complex UI ○ Multi-platform standard
  • 3. Example of Reactive Programming A spreadsheet is a great example of reactive programming: cells dependent on other cells automatically “react” when those other cells change. Reference: https://learning.oreilly.com/library/view/reactive-programming-with/9781491931646/ch01.html
  • 4. Rx Basic Building Blocks ● Observables = Dog ● Subscribers = Child ● Operators = Process Down
  • 5. Observables Observable are the data source/stream, then that observer reacts to whatever item or sequence of items the observables emits. They can emit data, completion and also failure
  • 6. Hot and Cold Observables Cold observables don’t do anything until someone starts observing them (subscribe in Rx). They only start running when they are consumed Hot Observables that can active before subscription, when an observer subscribes to hot observable it will get all values in the stream that are emitted
  • 9. When We Need Cold or Hot When we need to observable to generating new values when someone subscribing it and the values are also not shared among subscribers For example when we call the API, Getting data from local database When you have Observable and we want multiple subscribers to it, and you don’t want them to cause regenerating the values but rather reusing existing values For example as LiveData in MVVM iOS Reference: https://github.com/Reactive-Extensions/RxJS/blob/master/doc/gettingstarted/creating.md#cold-vs-hot-observables
  • 10. Operator An operator is simply a function that performs a specific action. It takes a value, does something with it and then returns it ● Creating ● Transforming ● Filtering ● Combining
  • 11. Operator (Creating) ● Create Create an observable from scratch by calling observer method programmatically ● Just Convert an object into Observable that emits that object
  • 12. Operator (Transforming) ● Map Transform the items emitted by an Observable by applying a function to each item ● FlatMap Transform the items emitted by an Observable into Observables, then flatten the emissions from those into a single Observable
  • 13. Observers Observers consumes the data stream emitted by observables Observers subscribe to observable using subscribeOn() method to receive data and then the data will be received in onNext() callback()
  • 14. Observer Callback OnNext() The callback to receive a valueless notification of type complete from the Observable. OnComplete() The callback to receive a valueless notification of type complete from the Observable. onError() The callback to receive notifications of type error from the Observable, with an attached Error.
  • 15. Scheduler Scheduler are component that tells observables and observers on which thread they should run - subscribeOn() Specifies on which Scheduler to Observables should operate - observeOn() Specifies on which Scheduler/Thread the Subscribers should be notified
  • 16. Scheduler Types Used - Schedulers.io() It is used for non CPU-intensive I/O type work including interaction with the file system, performing network calls, database interactions. This is usually used in subscribeOn method - Schedulers.computation It is used for computational or CPU-intensive work such as resizing images, processing large data sets, Reference: https://proandroiddev.com/understanding-rxjava-subscribeon-and-observeon- 744b0c6a41ea - AndroidSchedulers.trampoline This is used to executes tasks in a FIFO (First In, First Out). This scheduler runs the code on current thread for example for Unit Testing - AndroidSchedulers.mainThread() This is used to bring back the execution to the main thread so that UI modification can be made. This is usually used in observeOn method.
  • 17. RxBinding & RxCocoa - Library that makes it easier to use UI Component with reactive techniques. Reference: https://github.com/ReactiveX/RxSwift

Editor's Notes

  1. imperative programming is a programming paradigm that uses statements that change a program's state. In much the same way that the imperative mood in natural languages expresses commands, an imperative program consists of commands for the computer to perform. Imperative programming focuses on describing how a program operates.
  2. Reactive programming adalah paradigma pemrograman yang berkaitan dengan aliran data dan juga penyebaran perubahan Ketika menggunakan reactive programming data stream akan menjadi pondasi dari aplikasi kita Events, Messages, Calls bahkan failures akan di sampaikan oleh data stream dengan reactive programming kita meng observe data stream dan melakukan reaksi ketika nilai di berikan
  3. https://github.com/dwirandyh/bdlproperti-android/blob/6bb087dca0f466ad82e48c56d5d21b390dca95d3/app/src/main/java/com/dwirandyh/bdlproperti/core/rxbinding/RxSearchObservable.kt