title: Web Components (w/ React) - Past, Present, Future
- Intro
<HelloWorld/>
- Components in Components in Components
- It's "Just" JavaScript - For Each Loops in Your Component Templates
- "Generic" Placeholder / Containers - Add Any Components / Children
- Inside React Web Components
- Classes, Classes, Classes
- Extends
React.Component
- State & Lifecycle - Seconds Elapsed: 47
- Extends
- High Speed Batched Updates - 60 Frames/Second (60 FPS)
- Diffing Trees
- React @ Facebook - "Enterprise" React
- GraphQL, Relay, Flow 'n' Friends
- What's Next?
- I) Built-In Web Components Browser APIs
- II) JavaScript w/ Types
- III) More Fun - Fun(ctional) Languages
- IV) Going Mobile - React Native for Android, iOS Apps
- Community - Meetups & Conferences
React ★62400 is a (small) JavaScript library for building user interfaces. Declarative. Efficient. Flexible.
Let's make a <HelloWorld/>
web component / element / tag.
The simplest web component w/ React - a function returning a web snippet (HTML block)
function HelloWorld() {
return <h1>Hello, World!</h1>;
}
or in "fun(k)y" JavaScript 6+ arrow-style:
const HelloWorld = ()=> <h1>Hello, World!</h1>;
That's it.
Nesting of Web Components => Web Component Trees
Example:
function Message( {name} ) {
return <span>{ `Hello, ${name}!` }</span>;
}
function HelloWorld() {
return <h1><Message name="World"/></h1>;
}
and (again) use it like:
<HelloWorld/>
In Pseudo Code:
for link in links
<li><a href={link.url}>{link.title}</a></li>
end
No New Template Language. Use JavaScript 6+:
links.map(
link => <li><a href={link.url}>{link.title}</a></li>
)
Example:
function LinkList( {links} ) {
return(
<ul>
{links.map( link => <li><a href={link.url}>{link.title}</a></li> )}
</ul>);
}
and use it like
const links =
[
{ title: "football.db - Open Football Data", url: "https://github.com/openfootball" },
{ title: "beer.db - Open Beer, Brewery 'n' Brewpub Data", url: "https://github.com/openbeer" },
{ title: "world.db - Open World Data", url: "https://github.com/openmundi" }
];
...
<LinkList links={links}/>
function Page( {children} ) {
return(
<div>
<Header/>
<div>
{children}
</div>
<Footer/>
</div>);
}
and use it like:
<Page>
<div>
<b>News 'n' Updates</b>
<PostList posts={posts}/>
</div>
<div>
<b>Links 'n' Bookmarks</b>
<LinkList links={links}/>
</div>
</Page>
function HelloWorld() {
return <h1>Hello, World!</h1>;
}
gets converted to "plain vanilla" JavaScript:
function HelloWorld() {
return React.createElement( "h1", null, "Hello, World!" );
}
Try Babel online => babeljs.io/repl
function Message( {name} ) {
return <span>{ `Hello, ${name}!` }</span>;
}
function HelloWorld() {
return <h1><Message name="World"/></h1>;
}
gets converted to "plain vanilla" JavaScript:
function Message(_ref) {
var name = _ref.name;
return React.createElement( "span", null, "Hello, " + name + "!" );
}
function HelloWorld() {
return React.createElement("h1", null,
React.createElement(Message, { name: "World" })
);
}
function LinkList( {links} ) {
return (
<ul>
{links.map( link => <li><a href={link.url}>{link.title}</a></li> )}
</ul>);
}
gets converted to "plain vanilla" JavaScript:
function LinkList(_ref) {
var links = _ref.links;
return React.createElement( "ul", null,
links.map( function(link) {
return React.createElement( "li", null,
React.createElement( "a", { href: link.url }, link.title ));
}));
}
Use Classes for more "advanced" components. Example:
function HelloWorld() {
return <h1>Hello, World!</h1>;
}
is the same as:
class HelloWorld extends React.Componet {
render() {
return <h1>Hello, World!</h1>;
}
}
- Lifecyle e.g.
mount
- component turned on - andunmount
- component turned off - State e.g.
secondsElapsed
- a variable holding a number / counter, for example
class Timer extends React.Component {
constructor(props) {
super(props);
this.state = {secondsElapsed: 0};
}
tick() {
this.setState((prevState) => ({
secondsElapsed: prevState.secondsElapsed + 1
}));
}
componentDidMount() {
this.interval = setInterval(() => this.tick(), 1000);
}
componentWillUnmount() {
clearInterval(this.interval);
}
render() {
return (
<div>Seconds Elapsed: {this.state.secondsElapsed}</div>
);
}
}
React keeps a copy of the DOM (Document Object Model) in memory like a "frame buffer"; uses a diffing algorithm to calculate changes (in the two trees) and batches updates together in 60 frames per second.
- GraphQL & Relay - Data Queries & Binding
- Flow - Built-Time (Static) Data Flow Analysis & Type Checking
- ReasonML - "Better" Objective Functional Language (Compiles to JavaScript)
and more.
New (Upcoming) Web Standard Building Blocks
(<element>
) - W3C Spec
(hide DOM subtrees under shadow roots - createShadowRoot()
) - W3C Spec
(<template>
) - W3C Spec
(include and reuse HTML documents) - W3C Spec
Biggies
- TypeScript ★20098 (by Microsoft) - JavaScript Extended w/ Types
- Flow ★10693 (by Facebook) - Add Annotations for Type Checking
- Dart ★1038 (by Google) - New Language w/ (Optional) Types
And Others.
Biggies
- Elm ★3706 (by Evan Czaplicki 'n' friends) - Small (Pure) Functional Language for the Web
- Based on Haskell (Simplified)
- ReasonML ★2467 (by Facebook) - Larger (Pragmatic) Functional Language
- Based on OCaml (New ReasonML Syntax Closer to JavaScript)
And Others.
Why Fun(ctional)?
- "Stronger" Types
- No Null and No Undefined Possible
- e.g. Elm Uses Maybe types with Just a and Nothing and Tuple Units e.g.
()
)
- e.g. Elm Uses Maybe types with Just a and Nothing and Tuple Units e.g.
- Lists must always be of the same type
- If expressions must always return the same type (in if and else branch)
- Case expressions must always cover all possible branches / values
- And so on
- No Null and No Undefined Possible
- Immutability
- Cannot change/overwrite variables (change will always create a new variable)
- Great for "high-speed" diffing web component/element trees ("just" compare node references)
- Great for "time travel" debugging e.g. save or restore any state in time
Use React Native ★45909 (and JavaScript) to build "real" phone apps for Android an iOS. Example:
import React, { Component } from 'react';
import { Image, ScrollView, Text } from 'react-native';
class AwkwardScrollingImageWithText extends Component {
render() {
return (
<ScrollView>
<Image source={{uri: 'https://i.chzbgr.com/full/7345954048/h7E2C65F9/'}} />
<Text>
On iOS, a React Native ScrollView uses a native UIScrollView.
On Android, it uses a native ScrollView.
On iOS, a React Native Image uses a native UIImageView.
On Android, it uses a native ImageView.
React Native wraps the fundamental native components, giving you
the performance of a native app, plus the clean design of React.
</Text>
</ScrollView>
);
}
}
Meetups In Vienna, Austria
- React Vienna Meetup (FREE) - Monthly @ sektor5
- Reason Vienna Meetup (FREE) - Starting Up
- Elm Vienna Meetup (FREE) - Starting Up
Conferences
- React Conf (by Facebook)
- 2017 - March 13 & 14 - in Santa Clara, CA
- 2016 - February 22 & 23 - in San Francisco, CA
- 2015 - January 28 & 29 - Facebook HQ, CA
In Europe
- React Europe
- 2017 - May 18 & 19 in Paris, France
- 2016 - June 2 & 3 in Paris, France
- 2015 - July 2 & 3 in Paris, France
Regional in 2017
- React London 2017 - March 28
- React Amsterdam 2017 - April 21
- React Native Europe 2017 - September 6 & 7 in Wroclaw, Poland
- React.js Day 2017 - October 6 in Verona, Italy
- State.js React Conference 2017 - October 13 in Stockholm, Sweden
- Reactive Conf 2017 - October 25-27 in Bratislava, Slovakia