About
Reactive Programming is an event-driven programmation based on the observer / subscriber pattern via an event loop.
They are reactive implementing a reactor pattern.
It means that:
- functions create events
- functions subscribe to event
In another word, a change of state is propagated to the system where functions can react to them.
Event example
Backend
Some backend example events are:
- a timer has fired
- some data has arrived on a socket,
- some data has been read from the disk
- an exception has occurred
- an HTTP server has received a request
Frontend
Some frontend example events are:
- the user has clicked on a button
- the user has swiped
- the user has used a key
- the scroll is at the end of the page
Example
Imperative Programming vs Reactive programming
In an imperative programming setting, the expression a:=b+c would mean that a is being assigned the result of b+c in the instant the expression is evaluated, and later, the values of b and c can be changed with no effect on the value of a.
On the other hand, in reactive programming, the value of a is automatically updated whenever the values of b or c change, without the program having to re-execute the statement a:=b+c to determine the presently assigned value of a.
Application
Reactive Application are event-driven data application.
Example of reactive / event driven data application:
Model
Implementation
Most reactive system are implemented via an event loop.