Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

#КОЙ създаде React?

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

React не е нещо младо и неузряло

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Лето Божие 2015

Slide 18

Slide 18 text

#КОЙ използва React?

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

Малко теория

Slide 21

Slide 21 text

Mutable (stateful) UI

Slide 22

Slide 22 text

Първоначални данни функция 1 Първоначален интерфейс

Slide 23

Slide 23 text

Променени данни функция 3..+inf Промяна на интерфейса Нови данни (сървър) функция 4

Slide 24

Slide 24 text

Declarative UI

Slide 25

Slide 25 text

Данни Интерфейс функция 2 UI декларация Нови данни (сървър)

Slide 26

Slide 26 text

  • {beer.brand} - {beer.likes}

Slide 27

Slide 27 text

Immutable UI

Slide 28

Slide 28 text

Данни функция 1 Интерфейс функция 2 Нови данни (сървър)

Slide 29

Slide 29 text

function render(beers) { return '
    ' + beers.map(render_beer) + '
'; } function render_beer(beer) { return '
  • ' + beer.brand + ' ' + beer.likes + '
  • ; }

    Slide 30

    Slide 30 text

    Immutable != Declarative

    Slide 31

    Slide 31 text

    React

    Slide 32

    Slide 32 text

    No content

    Slide 33

    Slide 33 text

    React

    Slide 34

    Slide 34 text

    A JavaScript library for building user interfaces

    Slide 35

    Slide 35 text

    Getting started

    Slide 36

    Slide 36 text

    Hello World

    Slide 37

    Slide 37 text

    JSX • Синтактичен трансформатор • Вграден ECMAScript 6 transpiler (с опция --harmony) • Client-side & Server-side поддръжка

    Slide 38

    Slide 38 text

    JSX children  React.createElement(Component, { a1: code, a2: "str" }, children);

    Slide 39

    Slide 39 text

    JSX var Component = React.createClass({ … });  var Component = React.createClass({ displayName: "Component", … });

    Slide 40

    Slide 40 text

    Virtual DOM

    Slide 41

    Slide 41 text

    Virtual DOM • Структура от данни, скриваща мутациите върху DOM елементите • Представлява йерархия от обекти • Симулира immutable UI • Бърз алгоритъм за намиране на разлики

    Slide 42

    Slide 42 text

    Алгоритъм

    Slide 43

    Slide 43 text

    Алгоритъм var oldDOM = rootComponent.getCurrentVirtualDOMObject(), newDOM = rootComponent.render(); React.applyDifferences(oldDOM, newDOM);

    Slide 44

    Slide 44 text

    body { header(className="menu") { ul { li(href=…) { начало }, li(href=…) { вход }, li(href=…) { регистрация } }, }, div(className="users") { h1 { Пешо } h1 { Гошо } }, footer { Copyright 2015 ® } } IndexPage { NavigationMenu, IndexPageContent { UserList }, Footer } render Йерархия от React компоненти VirtualDOM

    Slide 45

    Slide 45 text

    div(className="test") { h1 { Здравей! } h2 { Тук си от 1234 милисекунди! } } HelloWorld { state: { initialTime: [Date Object], time: [Date Object] }, render() { ... } } render React компонент VirtualDOM елемент

    Slide 46

    Slide 46 text

    div(className="test") { h1 { Здравей! } h2 { Тук си от 1234 милисекунди! } } render VirtualDOM елемент Browser DOM

    Здравей!

    Тук си от 1234 милисекунди!

    Slide 47

    Slide 47 text

    div(className="test") { h1 { Здравей! } h2 { Тук си от 1234 милисекунди! } } diff Стар виртуален DOM Нов виртуален DOM div(className="test") { h1 { Здравей! } h2 { Тук си от 1222 милисекунди! } }

    Slide 48

    Slide 48 text

    div(className="test") { h1 { Здравей! } h2 { Тук си от 1234 милисекунди! } } Разлики Променен HTML

    Здравей!

    Тук си от 1234 милисекунди!

    apply diff

    Здравей!

    Тук си от 1222 милисекунди!

    Slide 49

    Slide 49 text

    Заради Virtual DOM... Може да се рендерира не само HTML: • React Native • React Canvas • React QT* • React GTK* • React WPF*

    Slide 50

    Slide 50 text

    React Native sneak peek var App = React.createClass({ render: function() { return ( ); } });

    Slide 51

    Slide 51 text

    Server-side rendering DEAL WITH IT

    Slide 52

    Slide 52 text

    Data flow

    Slide 53

    Slide 53 text

    Компонент props state Родител state Компонент state Компонент state

    Slide 54

    Slide 54 text

    Props render() { return Senior dog specialist } onSelect={function() { ... }} /> }

    Slide 55

    Slide 55 text

    Props render() { return (

    {this.props.name} {this.props.online && online}

    {this.props.position}

    ); }

    Slide 56

    Slide 56 text

    Prop Validation User.propTypes = { name: React.PropTypes.string.isRequired, online: React.PropTypes.bool, position: React.PropTypes.element, onSelect: React.PropTypes.func.isRequired };

    Slide 57

    Slide 57 text

    Prop Defaults User.defaultProps = { online: false, position: unknown };

    Slide 58

    Slide 58 text

    Properties • Immutable • Може да се подменят само от родител • При подмяна се пререндерира • componentWillReceiveProps, … • Може да са всякакви JS обекти • Може да се валидират

    Slide 59

    Slide 59 text

    State • Вътрешно състояние за компонент • Може да се променя и чете само отвътре • При промяна се пререндерира • componentWillUpdate, componentDidUpdate • Отново, може да съдържа всичко • Променя се само чрез `setState`

    Slide 60

    Slide 60 text

    Events • Custom event система – "оправя" разлики в браузърите • Clipboard, Keyboard, Mouse, Touch, Focus, Form, Scroll & Wheel • Закачат се като property-та на елементите

    Slide 61

    Slide 61 text

    Events render() { return ( <button className="big red btn"> Launch nukes </button> </form> ); }

    Slide 62

    Slide 62 text

    Data loading • componentDidMount • componentWillReceiveProps

    Slide 63

    Slide 63 text

    Data loading componentDidMount() { ajax('user/all', function(users) { this.setState({users: users}); }.bind(this)); }

    Slide 64

    Slide 64 text

    Events componentDidMount() { ajax('user/all', (users) => { this.setState({users: users}); }); }

    Slide 65

    Slide 65 text

    References class SearchForm extends React.Component { clear() { this.setState({text: ''}); } ... }

    Slide 66

    Slide 66 text

    References render() { } clear() { this.refs.searchForm.clear(); }

    Slide 67

    Slide 67 text

    Демота

    Slide 68

    Slide 68 text

    Обобщение

    Slide 69

    Slide 69 text

    JSX – синтаксис за вграждане на HTML-о-подобни тагове в JS

    Slide 70

    Slide 70 text

    Virtual DOM – структурата, която моделира HTML елементите

    Slide 71

    Slide 71 text

    Data flow – events, props, states

    Slide 72

    Slide 72 text

    Възможност за други имплементации (React Native) и Server-side rendering

    Slide 73

    Slide 73 text

    Добра енкапсулация

    Slide 74

    Slide 74 text

    Бърза разработка

    Slide 75

    Slide 75 text

    Лесно unit тестване (без браузър)

    Slide 76

    Slide 76 text

    No content