mvi an architecture for reactive programming

25
an architecture for reactive programming MVI

Upload: luca-mezzalira

Post on 09-Jan-2017

61 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: Mvi an architecture for reactive programming

an architecture for reactive programming

MVI

Page 2: Mvi an architecture for reactive programming

HELLO!

I am Luca MezzaliraSolutions Architect @ DAZNGoogle Developer Expert on Web TechnologiesCommunity Manager of London JavaScript User Group

Page 3: Mvi an architecture for reactive programming

AGENDA▸ Reactive

programming

▸ Model - View - Intent

▸ Cycle.js

Page 4: Mvi an architecture for reactive programming

1.REACTIVE PROGRAMMING

Page 5: Mvi an architecture for reactive programming

PROGRAMMING PARADIGMSFUNCTIONALIt is a declarative programming paradigm, which means programming is done with expressions. In functional code, the output value of a function depends only on the arguments that are input to the function, so calling a function f twice with the same value for an argument x will produce the same result f(x) each time.

IMPERATIVEIt 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.

REACTIVEIt is a programming paradigm oriented around data flows and the propagation of change. This means that it should be possible to express static or dynamic data flows with ease in the programming languages used, and that the underlying execution model will automatically propagate changes through the data flow.

Page 6: Mvi an architecture for reactive programming

PASSIVE

REACTIVE

BA BA

Page 7: Mvi an architecture for reactive programming

Imperative vs Reactive

Page 8: Mvi an architecture for reactive programming

OBSERVER PATTERNThe 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 any state changes, usually by calling one of their methods. It is mainly used to implement distributed event handling systems.

Page 9: Mvi an architecture for reactive programming

STREAMSA stream is a sequence of ongoing events ordered in time. It can emit three different things: a value (of some type), an error, or a "completed" signal.

EVERYTHING CAN BE A STREAM

Page 10: Mvi an architecture for reactive programming

2.MODEL VIEW INTENT

Page 11: Mvi an architecture for reactive programming

VIEW MODELPRESENTER

https://en.wikipedia.org/wiki/Model-view-presenter

Page 12: Mvi an architecture for reactive programming

VIEW INTENT

MODEL

RENDERER

futurice.com/blog/reactive-mvc-and-the-virtual-dom

Page 13: Mvi an architecture for reactive programming

VIEWInput: data events from the Model.Output: a Virtual DOM rendering of the model, and raw user input events (such as clicks, keyboard typing, accelerometer events, etc).

VIEW

RENDERER

Page 14: Mvi an architecture for reactive programming

INTENTInput: raw user input events from the View.Output: model-friendly user intention events.

INTENT

Page 15: Mvi an architecture for reactive programming

MODELInput: user interaction events from the Intent.Output: data events.

MODEL

Page 16: Mvi an architecture for reactive programming

MVI RULES▸ A module shouldn’t control

any other module (controller in MVC)

▸ The only shared part between modules are observables

▸ Intent is a component with only one responsibility: It should interpret what the user is trying to do in terms of model updates, and export these "user intentions" as events

Page 17: Mvi an architecture for reactive programming

3.Cycle.js

Page 18: Mvi an architecture for reactive programming

Cycle.js

Page 19: Mvi an architecture for reactive programming

Core concepts▸ Pure Functions▸ Streams▸ Components▸ Drivers

Page 20: Mvi an architecture for reactive programming

DRIVERSDrivers are functions that listen to Observable sinks (their input), perform imperative side effects, and may return Observable sources (their output).

http://cycle.js.org/drivers.html

Cycle.js DOMDriver

Page 21: Mvi an architecture for reactive programming

Cycle Diversity▸ Refactored in Typescript▸ It accepts different type of

reactive libraries (xstream, rxjs 4 and 5, most)

▸ Integration with Snabbdom for DOM rendering by default

https://github.com/cyclejs/cyclejs/releases/tag/v7.0.0

Page 22: Mvi an architecture for reactive programming

React-Native

React

https://github.com/cyclejs/cycle-react-native

https://github.com/pH200/cycle-react

Snabbdom-jsxhttps://github.com/yelouafi/snabbdom-jsx

Page 23: Mvi an architecture for reactive programming

Cycle.js in action

Page 24: Mvi an architecture for reactive programming

Shall we useReactive Programming

in any project?