Slide 1

Slide 1 text

Component based Frontend architecture with React.JS @BastianHofmann

Slide 2

Slide 2 text

Application architecture

Slide 3

Slide 3 text

Code and component  re-use

Slide 4

Slide 4 text

Rapid Development

Slide 5

Slide 5 text

Handling large code-bases

Slide 6

Slide 6 text

With React.js

Slide 7

Slide 7 text

With small and independent components

Slide 8

Slide 8 text

webserver HTML browser JS controller

Slide 9

Slide 9 text

webserver HTML browser JS Ajax controller

Slide 10

Slide 10 text

webserver HTML browser JS Ajax controller

Slide 11

Slide 11 text

de duplication ode duplication code duplication code duplication code duplication code duplication code duplication code duplication code duplication code duplication code duplication code duplication code duplication code duplicatio code duplicat code duplic code dup code du code cod co co

Slide 12

Slide 12 text

A few words about me

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

http://speakerdeck.com/u/bastianhofmann

Slide 16

Slide 16 text

Application architecture

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

status quo

Slide 19

Slide 19 text

webserver loadbalancer pgsql memcached mongodb services

Slide 20

Slide 20 text

webserver

Slide 21

Slide 21 text

webserver HTML browser JS Ajax controller

Slide 22

Slide 22 text

Duplication and only some Code re- use

Slide 23

Slide 23 text

We can do  better

Slide 24

Slide 24 text

Small components over big controllers

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Self contained

Slide 33

Slide 33 text

Can be used everywhere

Slide 34

Slide 34 text

JS is part of the component

Slide 35

Slide 35 text

CSS can be part of the component

Slide 36

Slide 36 text

http://facebook.github.io/react/

Slide 37

Slide 37 text

JavaScript UI Library

Slide 38

Slide 38 text

Many small, self contained, reusable components

Slide 39

Slide 39 text

var HelloMessage = React.createClass(
 {
 render: function () {
 return
Hello {this.props.name}
;
 }
 }
 );
 
 ReactDOM.render(, mountNode);

Slide 40

Slide 40 text

var Timer = React.createClass({
 getInitialState: function () {
 return {secs: 0};
 },
 tick: function () {
 this.setState({secs: this.state.secs + 1});
 },
 componentDidMount: function () {
 this.interval = setInterval(this.tick, 1000);
 },
 componentWillUnmount: function () {
 clearInterval(this.interval);
 },
 render: function () {
 return (
Seconds Elapsed: {this.state.secs}
);
 }
 });
 
 ReactDOM.render(, mountNode);

Slide 41

Slide 41 text

var TodoList = React.createClass(
 {
 render: function () {
 var createItem = function (itemText) {
 return
  • {itemText}
  • ;
 };
 return (
      {this.props.items.map(createItem)}
    );
 }
 }
 );

    Slide 42

    Slide 42 text

    var TodoApp = React.createClass({
 render: function () {
 return (


    TODO

    
 

    
 );
 }
 });

    Slide 43

    Slide 43 text

    var Timer = React.createClass({
 getInitialState: function () {
 return {secs: 0};
 },
 tick: function () {
 this.setState({secs: this.state.secs + 1});
 },
 componentDidMount: function () {
 this.interval = setInterval(this.tick, 1000);
 },
 componentWillUnmount: function () {
 clearInterval(this.interval);
 },
 render: function () {
 return (
    Seconds Elapsed: {this.state.secs}
    );
 }
 });
 
 ReactDOM.render(, mountNode);

    Slide 44

    Slide 44 text

    Getting the data in there

    Slide 45

    Slide 45 text

    PHP Backend JSON React Frontend

    Slide 46

    Slide 46 text

    PHP Backend JSON React Frontend

    Slide 47

    Slide 47 text

    PHP Backend JSON React Frontend

    Slide 48

    Slide 48 text

    var TodoApp = React.createClass({
 getInitialState: function () {
 return {items: […]};
 },
 render: function () {
 return (


    TODO

    
 

    
 );
 }
 });

    Slide 49

    Slide 49 text

    PHP Backend JSON React Frontend

    Slide 50

    Slide 50 text

    Problematic

    Slide 51

    Slide 51 text

    Remember

    Slide 52

    Slide 52 text

    Self-contained

    Slide 53

    Slide 53 text

    Reusable

    Slide 54

    Slide 54 text

    PHP Backend JSON React Frontend

    Slide 55

    Slide 55 text

    PHP Backend JSON React Frontend

    Slide 56

    Slide 56 text

    PHP Backend JSON React Frontend

    Slide 57

    Slide 57 text

    PHP Backend JSON React Frontend

    Slide 58

    Slide 58 text

    Overfetching

    Slide 59

    Slide 59 text

    Underfetching

    Slide 60

    Slide 60 text

    Solutions

    Slide 61

    Slide 61 text

    GraphQL http://graphql.org/

    Slide 62

    Slide 62 text

    PHP Backend React Frontend GraphQL

    Slide 63

    Slide 63 text

    Request Cache

    Slide 64

    Slide 64 text

    Batching

    Slide 65

    Slide 65 text

    Multi-GET

    Slide 66

    Slide 66 text

    Futures

    Slide 67

    Slide 67 text

    Server side rendering

    Slide 68

    Slide 68 text

    SEO

    Slide 69

    Slide 69 text

    Better user experience

    Slide 70

    Slide 70 text

    Several approaches

    Slide 71

    Slide 71 text

    NodeJS service

    Slide 72

    Slide 72 text

    Request HTML nodeJS service PHP process Data JSON Rendered HTML string React

    Slide 73

    Slide 73 text

    Component based architecture

    Slide 74

    Slide 74 text

    Benefits

    Slide 75

    Slide 75 text

    Easy re-using of components

    Slide 76

    Slide 76 text

    Enables developers to only focus on their components

    Slide 77

    Slide 77 text

    Rapid prototyping

    Slide 78

    Slide 78 text

    Easier Refactoring

    Slide 79

    Slide 79 text

    Error Handling

    Slide 80

    Slide 80 text

    Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu Institution

    Slide 81

    Slide 81 text

    Profile Publications Publication Publication Publication AboutMe LeftColumn Image Menu EXCEPTION Institution

    Slide 82

    Slide 82 text

    Profile Publications Publication Publication Publication LeftColumn Image Menu Institution

    Slide 83

    Slide 83 text

    Experiments (A/B Testing)

    Slide 84

    Slide 84 text

    Partial roll outs

    Slide 85

    Slide 85 text

    Load components asynchronously

    Slide 86

    Slide 86 text

    Conclusion?

    Slide 87

    Slide 87 text

    Think about your architecture

    Slide 88

    Slide 88 text

    Small reusable components are great

    Slide 89

    Slide 89 text

    Refactor and make it better continuously

    Slide 90

    Slide 90 text

    Frontend and backend are part of the same application

    Slide 91

    Slide 91 text

    Don't rewrite your whole codebase in one go

    Slide 92

    Slide 92 text

    http://twitter.com/BastianHofmann http://lanyrd.com/people/BastianHofmann http://speakerdeck.com/u/bastianhofmann [email protected]