44
www.controlexpert.com www.signumframework.com www.signumsoftware.com Olmo de Corral Signum Framework Developer #olmocc [email protected] React

React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

www.controlexpert.comwww.signumframework.comwww.signumsoftware.com

Olmo de Corral

Signum Framework Developer#olmocc [email protected]

React

Page 2: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

A little bit of (my) History

Logic

C# SQL

Entities

C# WCF

Views

XAML

Scripts

C#

Logic

C# SQL

Templates

CSHTML

Scripts

JavaScript

jQuery

HTM

L

FO

RM

DATA

Logic

C# SQL

Entities

C#/JSON

Views

??

Scripts

TypeScriptTypeScript

Page 3: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Searching for a JS Framework

Page 4: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Searching for a JS Framework

Page 5: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Searching for a JS Framework

Model

View

Controller

Just

Render

Components™

Reactive

Page 6: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

The Web

Page 7: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

JSX Basics

Page 8: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

JSX Advanced

Page 9: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Custom Components

Intrinsic HTML Elements

In lowercase

React Components

In Uppercase

Page 10: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

PersonControl

Two-Way Databinding

Person

Name: “John”

DateOfBirth: 1984-10-13

InputControl

Value: “John”

DateTimePicker

SelectedDate: 1984-10-13

OnChange

Page 11: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

PersonControl

Unidirectional Data Flow

DateTimePicker

SelectedDate: 1984-10-13

Person

Name: “John”

DateOfBirth: 1984-10-13

Value: “John”

InputControl

OnChange

OnChange

Render

Page 12: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

DEMO 1:

Person Component

Handling Events

Be careful with this!

ForceUpdate

Page 13: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Props vs State

Props

Public

Read-only

Recommended

State

Private

Modifiable

Only if needed

(a.k.a. Parameters)

Page 14: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

DEMO 2:

DateTimePicker

Props vs State

SetState

Page 15: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Virtual DOM

Virtual DOM

FAST (javascript objects)

Recursive Tree

Contains:

Instances of React

Components and HTML

elements

Native DOM

SLOW (layout & render)

Complete Native Tree

Contains:

Real DOM nodes of

HTML elements

render()

FAST (React Elements)

Shallow Tree

Contains:

ReactElement(‘div’)

ReactElement(DateTime

Picker)

Person

Control

input DateTime

Picker

div

render()

Person

Control

input DateTime

Picker

div

div

inputbutton ul

li li

input

div

div

input button ul

li li

Batch Changes

Page 16: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Diff Algorithm Fast and Straightforward

Level by Level

http://calendar.perfplanet.com/2013/diff/

Comparing Lists

Comparing Nodes

Batching

Sub-tree Rendering

shouldComponentUpdate

Page 17: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

DEMO 3:

React Developer Tools

Page 18: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Component API

Page 19: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

GRADUATED IN REACT!!!

…but

Page 20: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Just the V in MVC…

Language

elm

Module System

CommonJS (Node)

AMD (Require.js)

UMD

ES6 Modules

Build Bundle

CSS Preprocessor CSS FrameworkAtScript

Page 21: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

React + Typescript

Page 22: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Popular Javascript Frameworks

Page 23: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Popular To-Javascript Languages

Page 24: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

React + Typescript + Angular

Page 25: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

React + Typescript

Page 26: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

TSX = TS + JSX

Typescript 1.6

Full JSX support

Strongly typed

Props vs State

Spread operator

New as operator for casting

Two outputs: preserve / react

BUG: Formatting Problems

Typescript 1.8

Syntax coloring

Stateless Function Components

Simplified props

Custom JSX Factories

BUG: Auto-completion problems

Flow analysis (return)

Lack of import auto-complete

Page 27: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

React Ecosystem

(Tested)

Page 28: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Lots of plugins and loaders

Typescript / Babel / CoffeeScript

CSS / LESS / SASS

Customize bundles

Uglyfx

Notify

Solves the whole bundling problem

Follows JS require / import

Sync and Async dependencies

Styles, fonts and other assets

Hash & Cache Invalidation

--watch mode

Tricky to configure

Black box WebPack Task Runner for

Visual Studio 2015 ... useful?

Page 29: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Associates Components with URLs

Using JSX!

Cumbersome API with many breaking changes

History repository needed?

Incomplete Typescript definition files (.d.ts)

keeps your UI in sync with the URL

https://github.com/reactjs/react-router

Page 30: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

React-Bootstrap

Good documentation

Very Complete (Modals, Tabs, Tooltips)

Too much? (Button, MenuItem)

Overlays repository need?

Incomplete Typescript definition files (.d.ts)

The most popular front-end framework, rebuilt for React.

https://react-bootstrap.github.io/

Page 31: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

React Widgets

Good documentation

High quality components

Dropdown / Combobox

Date-Time picker

No definition files (I built my own)

offers a set of html form inputs,

built from scratch with React

https://jquense.github.io/react-widgets/docs

Page 32: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

React Ecosystem

(Untested)

Page 33: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Server-Side Rendering

Person

input DateTime

Picker

div

div

inputbutton

input

div

div

input button

Batch Changes

Person

input DateTime

Picker

div

div

inputbutton

Generate

HTML String

<div>

<input/>

<div>

<input/>

<button/>

/div>

</div>

Browser

Server

ul

li li

ul

li li

?✓

Page 34: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

ReactJS.NET makes it easier to use Facebook's React and JSX from C# and other

.NET languages, focusing specifically on ASP.NET MVC (although it also works in

other environments).

On-the-fly JSX to JavaScript compilation

JSX to JavaScript compilation via popular

minification/combination libraries

Server-side component rendering

Typescript support?

<script src="@Url.Content("~/Scripts/HelloWorld.jsx")"></script>

bundles.Add(new JsxBundle("~/bundles/main").Include("~/Scripts/HelloWorld.jsx"))

@Html.React("CommentsBox", new { initialComments = Model.Comments })

Page 35: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

React Hot Loader will keep it mounted, preserving the state.

http://gaearon.github.io/react-hot-loader/

Works on IIS?

Page 36: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

React Native

A FRAMEWORK FOR BUILDING

NATIVE APPS USING REACT

Native Components

Asynchronous Execution

Touch Handling

Flexbox and Styling

Extensibility

Page 37: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Flux Implementations

•Materil Flux

•Fluxette

•Freezer

•Fluxury

•Fluxy

Reflux

•Flummox

•Marty.js

•McFly

•Delorean

•Lux

Page 38: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Signum.React

Page 39: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Logic

C# SQL

Entities

C# WCF

Views

XAML

Scripts

C#

Logic

C# SQL

Templates

CSHTML

Scripts

JavaScript

jQuery

HTM

L

FO

RM

DATA

Logic

C# SQL

Entities

C#/JSON

Views

TSX

Scripts

TypeScriptTypeScript

Signum Framework UIs

Page 40: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Entities

Enums

Messages

Entities

Enums

Messages

T4S

Code-generation

with templates

REST - JSON

Metadata

Translations

PermissionsBusines Logic

API ContollersReact

Components

Server-Side Client-Side

Run-T

ime

Com

pile-T

ime

Page 41: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

DEMO 4:

Signum.React

Page 42: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Entities

Enums

Messages

Entities

Enums

Messages

T4S

Code-generation

with templates

Metadata

Translations

PermissionsBusines Logic

API ContollersReact

Components

Server-Side Client-Side

Run-T

ime

Com

pile-T

ime

cshtml

Page 43: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

Conclusion

1. React is Awesome

Simplicity

Expressivity

Performance

… but incomplete

1. React + Typescript is even better

Compile-time checked

Auto completion

Safe renames

...missing .d.ts

3. Big Ecosystem

Webpack

React Bootstrap

React Widgets

React Router

4. You may need server-side solution

Auto-generate definition files from C#

Expose meta-data with reflection

Facilitate migration

React Native

React.Net

React Hot Loader

Page 44: React - roland-weigelt.de · Lots of plugins and loaders Typescript / Babel / CoffeeScript CSS / LESS / SASS Customize bundles Uglyfx Notify Solves the whole bundling problem Follows

THE ENDOlmo de Corral

Signum Framework Developer #olmocc [email protected]

www.controlexpert.com

www.signumframework.com

www.signumsoftware.com