SlideShare a Scribd company logo
ReactNative Evening
CoWork South Bay
Torrance, CA
26 July 2017
@ 7:00 PM, PDT
Me
• Troy Miles
• Over 38 years of programming
experience
• Software engineer, speaker,
book and video author
• rockncoder@gmail.com
• @therockncoder
• lynda.com Author

Kotlin for Java Developers
“Learn once, write anywhere: Build mobile apps
with React”
React Native
• “Deliver native Android, iOS, and Windows apps,
using existing skills, teams, and code.”
• Released: March 27, 2015
• 51k+ GitHub Stars
Installation
• Node.js (& npm)
• Android SDK
• iOS SDK (on Mac only)
• React Native
Android Development
• Install Java 8
• Install Android Studio
• Install Android SDK 23 (Marshmallow)
• Install Intel HAXM (x86 Android Emulator)
iOS Development
• Install Xcode from macOS App Store
Mac Installation
• brew install node
• brew install watchman*
• npm i -g react-native-cli
Windows Installation
• choco install nodejs.install
• choco install python2
• choco install jdk8
iOS Development
• In order to build apps for iOS you must have a Mac
React-Native
• react-native init <app name>
• cd <app name>
• react-native run-android / run-ios
react-native CLI
Command Purpose
init [app name] creates a react-native app
run-android [options] builds app, starts on Android
run-ios [options] builds app, starts on iOS
start [options] starts webserver
new-library [options] generates a native library bridge
bundle [options] builds offline javascript bundle
unbundle [options] builds unbundle javascript
react-native CLI
Command Purpose
eject [options] takes the shackles off
link [options] <packageName> links all native dependencies
unlink [options] <packageName> unlink native dependency
install [options] <packageName> install+link native dependencies
uninstall [options] <packageName> uninstall+unlink native
upgrade [options] upgrade app's template files
log-android [options] starts adb logcat
log-ios [options] starts iOS device syslog tail
Application Root Directory
• All of the commands, for all of the tools are
designed work on the application root directory
• If used anywhere else bad things will happen
• be sure you are in the app root
• double check that you are in the app root
JavaScript
ECMAScript Versions
Version Date
ES1 June 1997
ES2 June 1998
ES3 December 1999
ES4 DOA 2006
ES5 December 2009
ES2015 / ES6 June 2015
ES2016 / ES7 2016
Collection Operators
• .isArray()
• .every()
• .forEach()
• .indexOf()
• .lastIndexOf()
• .some()
• .map()
• .reduce()
• .filter()
map
let junk = [1, 2, 3, 4, 'Alpha', 5, {name: 'Jason'}];

let letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'];

let nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];

console.log(nums);



// map iterates over all of the elements and returns a new array with the same
// number of elements

let nums2 = nums.map((elem) => elem * 2);

console.log(nums2);
/// [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40]


filter
let junk = [1, 2, 3, 4, 'Alpha', 5, {name: 'Jason'}];

let letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'];

let nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];

console.log(nums);



// filter iterates over the array and returns a new array with only the elements
// that pass the test

let nums3 = nums.filter((elem) => !!(elem % 2));

console.log(nums3);
/// [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
reduce
let junk = [1, 2, 3, 4, 'Alpha', 5, {name: 'Jason'}];

let letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'];

let nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];

console.log(nums);



// reduce iterates over the array passing the previous value and the current

// element it is up to you what the reduction does, let's concatenate the strings

let letters2 = letters.reduce((previous, current) => previous + current);

console.log(letters2);
/// ABCDEFGHIJK



// reduceRight does the same but goes from right to left

let letters3 = letters.reduceRight((previous, current) => previous + current);

console.log(letters3);
/// KJIHGFEDCBA

let
• let allows us to create a block scoped variables
• they live and die within their curly braces
• var is considered deprecated
• best practice is to use let instead of var
let
// let allows us to create block scoped variables

// they live and die within the curly braces

let val = 2;

console.info(`val = ${val}`);

{

let val = 59;

console.info(`val = ${val}`);

}

console.info(`val = ${val}`);



const
• const creates a variable that can't be changed
• best practice is to make any variable that should
not change a constant
• does not apply to object properties or array
elements
const
const name = 'Troy';

console.info(`My name is ${name}`);

// the line below triggers a type error

name = 'Miles';

Template strings
• Defined by using opening & closing back ticks
• Templates defined by ${JavaScript value}
• The value can be any simple JavaScript expression
• Allows multi-line strings (return is pass thru)
Template strings
let state = 'California';

let city = 'Long Beach';

console.info(`This weekend's workshop is in ${city}, ${state}.`);



// template strings can run simple expressions like addition

let cup_coffee = 4.5;

let cup_tea = 2.5;

console.info(`coffee: $${cup_coffee} + tea: $${cup_tea} = $$
{cup_coffee + cup_tea}.`);



// they can allow us to create multi-line strings

console.info(`This is line #1.

this is line #2.`);



Arrow functions
• Succinct syntax
• Doesn’t bind its own this, arguments, or super
• Facilitate a more functional style of coding
• Can’t be used as constructors
Arrow functions
• When only one parameter, parenthesis optional
• When zero or more than one parameter,
parenthesis required
Arrow function
let anon_func = function (num1, num2) {

return num1 + num2;

};

console.info(`Anonymous func: ${anon_func(1, 2)}`);



let arrow_func = (num1, num2) => num1 + num2;

console.info(`Arrow func: ${arrow_func(3, 4)}`);

this
• this is handled different in arrow functions
• In anonymous function this is bound to the global
object
• In arrow function this is what it was in the outer
scope
Destructuring
• Maps the data on the right side of the equals sign
to the variables on the left
• The data type decides the way values are mapped
• It is either object or array destructuring
Object Destructuring
16// this is a demo of the power of destructuring
17// we have two objects with the same 3 properties
18 const binary = {kb: 1024, mb: 1048576, gb: 1073741824};
19 const digital = {kb: 1000, mb: 1000000, gb: 1000000000};
20// We use a ternary statement to choose which object
21// assign properties based on their property names
22 const {kb, mb, gb} = (useBinary) ? binary : digital;
Array Destructuring
5
6 let [param1, bob, key] = ['first', 'second', '3rd'];
7 console.info(`param1 = ${param1}, bob = ${bob}, key = ${key}`);
8 // param1 = first, bob = second, key = 3rd
Spread syntax
• Expands an expression in places where multiple
arguments, elements, or variables are expected
The spread operator
11
12 // the spread operator
13 const myArray = ['Bob', 'Sue', 'Fido'];
14 function printFamily(person1, person2, pet) {
15 console.info(`Person 1: ${person1}, Person 2: ${person2}, and their pet: ${pet}`);
16 }
17 printFamily(...myArray);
18 // Person 1: Bob, Person 2: Sue, and their pet: Fido
19
Class
• Syntactic sugar over JavaScript use of function
constructors
• JavaScript uses proto-typical inheritance
• If a class extends another, it must include super()
as first instruction in its constructor
• Only create a constructor if it does something
Class
• Syntactic sugar over JavaScript use of function
constructors
• JavaScript uses proto-typical inheritance
• If a class extends another, it must include super()
as first instruction in its constructor
• Only create a constructor if it does something
import
• Imports functions, objects, or primitives from other
files
• import <name> from “<module name>”;
• import {name } from “<module name>”;
• import * as Greetings from “<module name>”;
• relative path indicates not an npm package
export
• export <var a>
• export {a, b};
export default
• only one per file
• common pattern for libraries
• const Greetings = {sayHi, sayBye};
• export default Greetings;
• export default {sayHi, sayBye};
Importing Old School JS
• Many JS libraries don’t support the new syntax
• How do we use them?
• import ‘jquery’;
React
React
• A JavaScript library for building user interfaces
• Created by Facebook & Instagram
• Initial release March 2013
• Current version 15.6.1
• Next major version 16.0.0, will have breaking
changes
React
• Virtual DOM
• One-way data flow
• JSX - JavaScript eXtension allows in HTML
generation
• Component-based
React API
• The use of JSX is optional in React
• You can use the React “API” instead
• The createClass method is deprecated and will be
removed in React 16
Component
• Fundamental building block of React
• Can be created with a JS Class or Function
• The render method is mandatory
Class Component
3
4 class Square extends React.Component {
5 render() {
6 return (
7 <button
8 className="square"
9 onClick={() => this.props.onClick()}>
10 {this.props.value}
11 </button>
12 );
13 }
14 }
15
Functional Component
15
16 function Square(props) {
17 return (
18 <button
19 className="square"
20 onClick={() => props.onClick()}>
21 {props.value}
22 </button>
23 );
24 }
React.PropTypes
• React.PropTypes is deprecated
• It will be deleted in React 16
• Use the npm package “prop-types” instead
• import	PropTypes	from	‘prop-types’;
PropTypes
• PropTypes allow you to declare what properties
your component expects
• React validates property at runtime
• Using propTypes is optional
Some PropTypes
Component Command
PropTypes.array an optional array
PropTypes.bool an optional bool
PropTypes.element An optional React element
PropTypes.func An optional function
PropTypes.node Anything that can be rendered
PropTypes.number An optional number
PropTypes.object An optional object
PropTypes.string An optional string
PropTypes.symbol An optional Symbol
PropType in code
1
2 import React from 'react';
3 import ReactDOM from 'react-dom';
4 import PropTypes from 'prop-types';
5
6 class App extends React.Component {
7 render () {
8 return React.DOM.span(null, `My name is ${this.props.name}`);
9 }
10 }
11
12 App.propTypes = {
13 name: PropTypes.string.isRequired
14 };
15
16 ReactDOM.render(
17 React.createElement(App, {}),
18 document.getElementById('root')
19 );
20
21
When property is missing
React Components
• Can be created two ways:
• Using JavaScript
• Using JSX
Components via JS
• React’s API contains method createElement()
• Takes 3 parameters: type, props, children
render() {
return React.createElement('h1', null, "Hello there.");
JSX
• JavaScript Syntax EXtension
• A mixture of JavaScript and HTML syntax
• Compiles to JavaScript
• Is optional but preferred over using JavaScript
• Is easier to read
JSX Attributes
• Can assign either a string or an expression
• Strings can be either single or double quotes
• Expressions must be enclosed with curly braces
Boolean Attributes
• HTML has a few boolean attributes, if present they
are true
• Some of these include: checked, selected,
disabled
• In JSX,
• <Component disabled={true / false} />
Forbidden Attributes
• Two attributes are JavaScript keywords
• JavaScript keywords can’t be used in JSX
• class -> className
• for -> htmlFor
JSX Spread Syntax
• a shortcut to passing props to a component
• uses ES2015 spread operator
• <Component {…object} />
JSX Spread Syntax
return (
<Timer
id={this.props.id}
amount={this.props.amount}
elapsed={this.props.elapsed}
runningSince={this.props.runningSince}
onStartClick={this.props.onStartClick}
onStopClick={this.props.onStopClick}
onResetClick={this.props.onResetClick}
onSetClick={this.handleSetClick}
/>
);
JSX Spread Syntax
return (
<Timer
{...this.props}
onSetClick={this.handleSetClick}
/>
);
JSX Debugging Tip
• Assign component to a variable
• console.log the variable
JSX Debugging Tip
const timerComp = (
<Timer troy='miles'
{...this.props}
onSetClick={this.handleSetClick}
/>
);
console.log(timerComp);
JSX Debugging Tip
JSX Debugging Tip
Lifecycle Events
Event When
componentWillMount invoked once before rendering
componentDidMount invoked after component loaded
componentWillReceiveProps invoked when receiving new props
shouldComponentUpdate asks if component should update
componentWillUpdate invoked before rendering new props
componentDidUpdate invoked after rendered new props
componentWillUnmount invoked before component removed
System Components
Component
ActivityIndicator
Button
DatePickerIOS
DrawerLayoutAndroid
FlatList
Image
KeyboardAvoidingView
System Components
Component
ListView
Modal
NavigatorIOS
Picker
PickerIOS
ProgressBarAndroid
ProgressViewIOS
System Components
Component
RefreshControl
ScrollView
SectionList
SegmentedControlIOS
Slider
SnapshotViewIOS
StatusBar
System Components
Component
Switch
TabBarIOS
TabBarIOS.Item
Text
TextInput
ToolbarAndroid
TouchableHighlight
System Components
Component
TouchableNativeFeedback
TouchableOpacity
TouchableWithoutFeedback
View
ViewPagerAndroid
VirtualizedList
WebViewAPIs
Platform Differences
• Not all components work with all devices
• Some are for iOS only or Android only
• Those that end in IOS are for iOS
• Those that end in Android are for Android
Summary
• React Native allows you to make mobile apps in JS
• While easier than native development, it is not easy

More Related Content

What's hot

Angular Weekend
Angular WeekendAngular Weekend
Angular Weekend
Troy Miles
 
ECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing EraECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing Era
Allen Wirfs-Brock
 
Introduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaIntroduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoa
Florent Pillet
 
What To Expect From PHP7
What To Expect From PHP7What To Expect From PHP7
What To Expect From PHP7
Codemotion
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
Luke Donnet
 
Akka Futures and Akka Remoting
Akka Futures  and Akka RemotingAkka Futures  and Akka Remoting
Akka Futures and Akka Remoting
Knoldus Inc.
 
Javascript Promises/Q Library
Javascript Promises/Q LibraryJavascript Promises/Q Library
Javascript Promises/Q Library
async_io
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
Visual Engineering
 
Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015
Jiayun Zhou
 
Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#
Riccardo Terrell
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
Haehnchen
 
Codegeneration With Xtend
Codegeneration With XtendCodegeneration With Xtend
Codegeneration With Xtend
Sven Efftinge
 
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Ville Mattila
 
Introduction to Asynchronous scala
Introduction to Asynchronous scalaIntroduction to Asynchronous scala
Introduction to Asynchronous scalaStratio
 
Akka and the Zen of Reactive System Design
Akka and the Zen of Reactive System DesignAkka and the Zen of Reactive System Design
Akka and the Zen of Reactive System Design
Lightbend
 
CoffeeScript - TechTalk 21/10/2013
CoffeeScript - TechTalk 21/10/2013CoffeeScript - TechTalk 21/10/2013
CoffeeScript - TechTalk 21/10/2013
Spyros Ioakeimidis
 
Avoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.js
cacois
 
Callbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptCallbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascript
Łukasz Kużyński
 
Concurrecny inf sharp
Concurrecny inf sharpConcurrecny inf sharp
Concurrecny inf sharp
Riccardo Terrell
 

What's hot (20)

Angular Weekend
Angular WeekendAngular Weekend
Angular Weekend
 
ECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing EraECMAScript 6: A Better JavaScript for the Ambient Computing Era
ECMAScript 6: A Better JavaScript for the Ambient Computing Era
 
Introduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoaIntroduction to reactive programming & ReactiveCocoa
Introduction to reactive programming & ReactiveCocoa
 
What To Expect From PHP7
What To Expect From PHP7What To Expect From PHP7
What To Expect From PHP7
 
Exploring Clojurescript
Exploring ClojurescriptExploring Clojurescript
Exploring Clojurescript
 
Akka Futures and Akka Remoting
Akka Futures  and Akka RemotingAkka Futures  and Akka Remoting
Akka Futures and Akka Remoting
 
Javascript Promises/Q Library
Javascript Promises/Q LibraryJavascript Promises/Q Library
Javascript Promises/Q Library
 
Workshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testingWorkshop 23: ReactJS, React & Redux testing
Workshop 23: ReactJS, React & Redux testing
 
Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015Akka Cluster in Java - JCConf 2015
Akka Cluster in Java - JCConf 2015
 
Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#Actor Clustering with Docker Containers and Akka.Net in F#
Actor Clustering with Docker Containers and Akka.Net in F#
 
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years laterSymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
SymfonyCon Berlin 2016 - Symfony Plugin for PhpStorm - 3 years later
 
The Joy Of Ruby
The Joy Of RubyThe Joy Of Ruby
The Joy Of Ruby
 
Codegeneration With Xtend
Codegeneration With XtendCodegeneration With Xtend
Codegeneration With Xtend
 
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
Running a Scalable And Reliable Symfony2 Application in Cloud (Symfony Sweden...
 
Introduction to Asynchronous scala
Introduction to Asynchronous scalaIntroduction to Asynchronous scala
Introduction to Asynchronous scala
 
Akka and the Zen of Reactive System Design
Akka and the Zen of Reactive System DesignAkka and the Zen of Reactive System Design
Akka and the Zen of Reactive System Design
 
CoffeeScript - TechTalk 21/10/2013
CoffeeScript - TechTalk 21/10/2013CoffeeScript - TechTalk 21/10/2013
CoffeeScript - TechTalk 21/10/2013
 
Avoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.jsAvoiding Callback Hell with Async.js
Avoiding Callback Hell with Async.js
 
Callbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascriptCallbacks, promises, generators - asynchronous javascript
Callbacks, promises, generators - asynchronous javascript
 
Concurrecny inf sharp
Concurrecny inf sharpConcurrecny inf sharp
Concurrecny inf sharp
 

Similar to React Native Evening

React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
Troy Miles
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
Troy Miles
 
Functional Programming in JavaScript
Functional Programming in JavaScriptFunctional Programming in JavaScript
Functional Programming in JavaScript
Troy Miles
 
Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
Felix Geisendörfer
 
ES6: Features + Rails
ES6: Features + RailsES6: Features + Rails
ES6: Features + Rails
Santosh Wadghule
 
Javascript status 2016
Javascript status 2016Javascript status 2016
Javascript status 2016
Arshavski Alexander
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
Eduard Tomàs
 
JavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# Developers
Rick Beerendonk
 
AkJS Meetup - ES6++
AkJS Meetup -  ES6++AkJS Meetup -  ES6++
AkJS Meetup - ES6++
Isaac Johnston
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing UpDavid Padbury
 
Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8
Wilson Su
 
JavaScript in 2015
JavaScript in 2015JavaScript in 2015
JavaScript in 2015
Igor Laborie
 
Angular2 for Beginners
Angular2 for BeginnersAngular2 for Beginners
Angular2 for Beginners
Oswald Campesato
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
Domenic Denicola
 
Es6 hackathon
Es6 hackathonEs6 hackathon
Es6 hackathon
Justin Alexander
 
What's New in JavaScript
What's New in JavaScriptWhat's New in JavaScript
What's New in JavaScript
Dan Cohn
 
Don't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax Trees
Jamund Ferguson
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
Lars Marius Garshol
 

Similar to React Native Evening (20)

React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 
Functional Programming in JavaScript
Functional Programming in JavaScriptFunctional Programming in JavaScript
Functional Programming in JavaScript
 
Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)Nodejs - A quick tour (v6)
Nodejs - A quick tour (v6)
 
ES6: Features + Rails
ES6: Features + RailsES6: Features + Rails
ES6: Features + Rails
 
Javascript status 2016
Javascript status 2016Javascript status 2016
Javascript status 2016
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
 
JavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# Developers
 
AkJS Meetup - ES6++
AkJS Meetup -  ES6++AkJS Meetup -  ES6++
AkJS Meetup - ES6++
 
JavaScript Growing Up
JavaScript Growing UpJavaScript Growing Up
JavaScript Growing Up
 
Wider than rails
Wider than railsWider than rails
Wider than rails
 
Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8Practical JavaScript Programming - Session 8/8
Practical JavaScript Programming - Session 8/8
 
JavaScript in 2015
JavaScript in 2015JavaScript in 2015
JavaScript in 2015
 
Angular2 for Beginners
Angular2 for BeginnersAngular2 for Beginners
Angular2 for Beginners
 
ES6 is Nigh
ES6 is NighES6 is Nigh
ES6 is Nigh
 
Es6 hackathon
Es6 hackathonEs6 hackathon
Es6 hackathon
 
What's New in JavaScript
What's New in JavaScriptWhat's New in JavaScript
What's New in JavaScript
 
Don't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax TreesDon't Be Afraid of Abstract Syntax Trees
Don't Be Afraid of Abstract Syntax Trees
 
es6
es6es6
es6
 
JSLT: JSON querying and transformation
JSLT: JSON querying and transformationJSLT: JSON querying and transformation
JSLT: JSON querying and transformation
 

More from Troy Miles

AWS Lambda Function with Kotlin
AWS Lambda Function with KotlinAWS Lambda Function with Kotlin
AWS Lambda Function with Kotlin
Troy Miles
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application Testing
Troy Miles
 
ReactJS.NET
ReactJS.NETReactJS.NET
ReactJS.NET
Troy Miles
 
What is Angular version 4?
What is Angular version 4?What is Angular version 4?
What is Angular version 4?
Troy Miles
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN Stack
Troy Miles
 
Functional Programming in Clojure
Functional Programming in ClojureFunctional Programming in Clojure
Functional Programming in Clojure
Troy Miles
 
MEAN Stack Warm-up
MEAN Stack Warm-upMEAN Stack Warm-up
MEAN Stack Warm-up
Troy Miles
 
The JavaScript You Wished You Knew
The JavaScript You Wished You KnewThe JavaScript You Wished You Knew
The JavaScript You Wished You Knew
Troy Miles
 
Build a Game in 60 minutes
Build a Game in 60 minutesBuild a Game in 60 minutes
Build a Game in 60 minutes
Troy Miles
 
Quick & Dirty & MEAN
Quick & Dirty & MEANQuick & Dirty & MEAN
Quick & Dirty & MEAN
Troy Miles
 
A Quick Intro to ReactiveX
A Quick Intro to ReactiveXA Quick Intro to ReactiveX
A Quick Intro to ReactiveX
Troy Miles
 
JavaScript Foundations Day1
JavaScript Foundations Day1JavaScript Foundations Day1
JavaScript Foundations Day1
Troy Miles
 
AngularJS Beginner Day One
AngularJS Beginner Day OneAngularJS Beginner Day One
AngularJS Beginner Day One
Troy Miles
 
AngularJS on Mobile with the Ionic Framework
AngularJS on Mobile with the Ionic FrameworkAngularJS on Mobile with the Ionic Framework
AngularJS on Mobile with the Ionic FrameworkTroy Miles
 
Building Cross-Platform Mobile Apps
Building Cross-Platform Mobile AppsBuilding Cross-Platform Mobile Apps
Building Cross-Platform Mobile Apps
Troy Miles
 
Cross Platform Game Programming with Cocos2d-js
Cross Platform Game Programming with Cocos2d-jsCross Platform Game Programming with Cocos2d-js
Cross Platform Game Programming with Cocos2d-js
Troy Miles
 
10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips
Troy Miles
 
Cross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Apps with the Ionic FrameworkCross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Apps with the Ionic Framework
Troy Miles
 
Ionic framework one day training
Ionic framework one day trainingIonic framework one day training
Ionic framework one day training
Troy Miles
 
Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8
Troy Miles
 

More from Troy Miles (20)

AWS Lambda Function with Kotlin
AWS Lambda Function with KotlinAWS Lambda Function with Kotlin
AWS Lambda Function with Kotlin
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application Testing
 
ReactJS.NET
ReactJS.NETReactJS.NET
ReactJS.NET
 
What is Angular version 4?
What is Angular version 4?What is Angular version 4?
What is Angular version 4?
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN Stack
 
Functional Programming in Clojure
Functional Programming in ClojureFunctional Programming in Clojure
Functional Programming in Clojure
 
MEAN Stack Warm-up
MEAN Stack Warm-upMEAN Stack Warm-up
MEAN Stack Warm-up
 
The JavaScript You Wished You Knew
The JavaScript You Wished You KnewThe JavaScript You Wished You Knew
The JavaScript You Wished You Knew
 
Build a Game in 60 minutes
Build a Game in 60 minutesBuild a Game in 60 minutes
Build a Game in 60 minutes
 
Quick & Dirty & MEAN
Quick & Dirty & MEANQuick & Dirty & MEAN
Quick & Dirty & MEAN
 
A Quick Intro to ReactiveX
A Quick Intro to ReactiveXA Quick Intro to ReactiveX
A Quick Intro to ReactiveX
 
JavaScript Foundations Day1
JavaScript Foundations Day1JavaScript Foundations Day1
JavaScript Foundations Day1
 
AngularJS Beginner Day One
AngularJS Beginner Day OneAngularJS Beginner Day One
AngularJS Beginner Day One
 
AngularJS on Mobile with the Ionic Framework
AngularJS on Mobile with the Ionic FrameworkAngularJS on Mobile with the Ionic Framework
AngularJS on Mobile with the Ionic Framework
 
Building Cross-Platform Mobile Apps
Building Cross-Platform Mobile AppsBuilding Cross-Platform Mobile Apps
Building Cross-Platform Mobile Apps
 
Cross Platform Game Programming with Cocos2d-js
Cross Platform Game Programming with Cocos2d-jsCross Platform Game Programming with Cocos2d-js
Cross Platform Game Programming with Cocos2d-js
 
10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips10 Groovy Little JavaScript Tips
10 Groovy Little JavaScript Tips
 
Cross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Apps with the Ionic FrameworkCross Platform Mobile Apps with the Ionic Framework
Cross Platform Mobile Apps with the Ionic Framework
 
Ionic framework one day training
Ionic framework one day trainingIonic framework one day training
Ionic framework one day training
 
Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8Cocos2d-x C++ Windows 8 &Windows Phone 8
Cocos2d-x C++ Windows 8 &Windows Phone 8
 

Recently uploaded

E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
Hornet Dynamics
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
Rakesh Kumar R
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
Deuglo Infosystem Pvt Ltd
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
Aftab Hussain
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 

Recently uploaded (20)

E-commerce Application Development Company.pdf
E-commerce Application Development Company.pdfE-commerce Application Development Company.pdf
E-commerce Application Development Company.pdf
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Fundamentals of Programming and Language Processors
Fundamentals of Programming and Language ProcessorsFundamentals of Programming and Language Processors
Fundamentals of Programming and Language Processors
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Empowering Growth with Best Software Development Company in Noida - Deuglo
Empowering Growth with Best Software  Development Company in Noida - DeugloEmpowering Growth with Best Software  Development Company in Noida - Deuglo
Empowering Growth with Best Software Development Company in Noida - Deuglo
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeA Study of Variable-Role-based Feature Enrichment in Neural Models of Code
A Study of Variable-Role-based Feature Enrichment in Neural Models of Code
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 

React Native Evening

  • 1. ReactNative Evening CoWork South Bay Torrance, CA 26 July 2017 @ 7:00 PM, PDT
  • 2.
  • 3. Me • Troy Miles • Over 38 years of programming experience • Software engineer, speaker, book and video author • rockncoder@gmail.com • @therockncoder • lynda.com Author

  • 4. Kotlin for Java Developers
  • 5. “Learn once, write anywhere: Build mobile apps with React”
  • 6. React Native • “Deliver native Android, iOS, and Windows apps, using existing skills, teams, and code.” • Released: March 27, 2015 • 51k+ GitHub Stars
  • 7. Installation • Node.js (& npm) • Android SDK • iOS SDK (on Mac only) • React Native
  • 8. Android Development • Install Java 8 • Install Android Studio • Install Android SDK 23 (Marshmallow) • Install Intel HAXM (x86 Android Emulator)
  • 9. iOS Development • Install Xcode from macOS App Store
  • 10. Mac Installation • brew install node • brew install watchman* • npm i -g react-native-cli
  • 11. Windows Installation • choco install nodejs.install • choco install python2 • choco install jdk8
  • 12. iOS Development • In order to build apps for iOS you must have a Mac
  • 13. React-Native • react-native init <app name> • cd <app name> • react-native run-android / run-ios
  • 14. react-native CLI Command Purpose init [app name] creates a react-native app run-android [options] builds app, starts on Android run-ios [options] builds app, starts on iOS start [options] starts webserver new-library [options] generates a native library bridge bundle [options] builds offline javascript bundle unbundle [options] builds unbundle javascript
  • 15. react-native CLI Command Purpose eject [options] takes the shackles off link [options] <packageName> links all native dependencies unlink [options] <packageName> unlink native dependency install [options] <packageName> install+link native dependencies uninstall [options] <packageName> uninstall+unlink native upgrade [options] upgrade app's template files log-android [options] starts adb logcat log-ios [options] starts iOS device syslog tail
  • 16. Application Root Directory • All of the commands, for all of the tools are designed work on the application root directory • If used anywhere else bad things will happen • be sure you are in the app root • double check that you are in the app root
  • 18. ECMAScript Versions Version Date ES1 June 1997 ES2 June 1998 ES3 December 1999 ES4 DOA 2006 ES5 December 2009 ES2015 / ES6 June 2015 ES2016 / ES7 2016
  • 19. Collection Operators • .isArray() • .every() • .forEach() • .indexOf() • .lastIndexOf() • .some() • .map() • .reduce() • .filter()
  • 20. map let junk = [1, 2, 3, 4, 'Alpha', 5, {name: 'Jason'}];
 let letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'];
 let nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
 console.log(nums);
 
 // map iterates over all of the elements and returns a new array with the same // number of elements
 let nums2 = nums.map((elem) => elem * 2);
 console.log(nums2); /// [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40] 

  • 21. filter let junk = [1, 2, 3, 4, 'Alpha', 5, {name: 'Jason'}];
 let letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'];
 let nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
 console.log(nums);
 
 // filter iterates over the array and returns a new array with only the elements // that pass the test
 let nums3 = nums.filter((elem) => !!(elem % 2));
 console.log(nums3); /// [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]
  • 22. reduce let junk = [1, 2, 3, 4, 'Alpha', 5, {name: 'Jason'}];
 let letters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'];
 let nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20];
 console.log(nums);
 
 // reduce iterates over the array passing the previous value and the current
 // element it is up to you what the reduction does, let's concatenate the strings
 let letters2 = letters.reduce((previous, current) => previous + current);
 console.log(letters2); /// ABCDEFGHIJK
 
 // reduceRight does the same but goes from right to left
 let letters3 = letters.reduceRight((previous, current) => previous + current);
 console.log(letters3); /// KJIHGFEDCBA

  • 23. let • let allows us to create a block scoped variables • they live and die within their curly braces • var is considered deprecated • best practice is to use let instead of var
  • 24. let // let allows us to create block scoped variables
 // they live and die within the curly braces
 let val = 2;
 console.info(`val = ${val}`);
 {
 let val = 59;
 console.info(`val = ${val}`);
 }
 console.info(`val = ${val}`);
 

  • 25. const • const creates a variable that can't be changed • best practice is to make any variable that should not change a constant • does not apply to object properties or array elements
  • 26. const const name = 'Troy';
 console.info(`My name is ${name}`);
 // the line below triggers a type error
 name = 'Miles';

  • 27. Template strings • Defined by using opening & closing back ticks • Templates defined by ${JavaScript value} • The value can be any simple JavaScript expression • Allows multi-line strings (return is pass thru)
  • 28. Template strings let state = 'California';
 let city = 'Long Beach';
 console.info(`This weekend's workshop is in ${city}, ${state}.`);
 
 // template strings can run simple expressions like addition
 let cup_coffee = 4.5;
 let cup_tea = 2.5;
 console.info(`coffee: $${cup_coffee} + tea: $${cup_tea} = $$ {cup_coffee + cup_tea}.`);
 
 // they can allow us to create multi-line strings
 console.info(`This is line #1.
 this is line #2.`);
 

  • 29. Arrow functions • Succinct syntax • Doesn’t bind its own this, arguments, or super • Facilitate a more functional style of coding • Can’t be used as constructors
  • 30. Arrow functions • When only one parameter, parenthesis optional • When zero or more than one parameter, parenthesis required
  • 31. Arrow function let anon_func = function (num1, num2) {
 return num1 + num2;
 };
 console.info(`Anonymous func: ${anon_func(1, 2)}`);
 
 let arrow_func = (num1, num2) => num1 + num2;
 console.info(`Arrow func: ${arrow_func(3, 4)}`);

  • 32. this • this is handled different in arrow functions • In anonymous function this is bound to the global object • In arrow function this is what it was in the outer scope
  • 33. Destructuring • Maps the data on the right side of the equals sign to the variables on the left • The data type decides the way values are mapped • It is either object or array destructuring
  • 34. Object Destructuring 16// this is a demo of the power of destructuring 17// we have two objects with the same 3 properties 18 const binary = {kb: 1024, mb: 1048576, gb: 1073741824}; 19 const digital = {kb: 1000, mb: 1000000, gb: 1000000000}; 20// We use a ternary statement to choose which object 21// assign properties based on their property names 22 const {kb, mb, gb} = (useBinary) ? binary : digital;
  • 35. Array Destructuring 5 6 let [param1, bob, key] = ['first', 'second', '3rd']; 7 console.info(`param1 = ${param1}, bob = ${bob}, key = ${key}`); 8 // param1 = first, bob = second, key = 3rd
  • 36. Spread syntax • Expands an expression in places where multiple arguments, elements, or variables are expected
  • 37. The spread operator 11 12 // the spread operator 13 const myArray = ['Bob', 'Sue', 'Fido']; 14 function printFamily(person1, person2, pet) { 15 console.info(`Person 1: ${person1}, Person 2: ${person2}, and their pet: ${pet}`); 16 } 17 printFamily(...myArray); 18 // Person 1: Bob, Person 2: Sue, and their pet: Fido 19
  • 38. Class • Syntactic sugar over JavaScript use of function constructors • JavaScript uses proto-typical inheritance • If a class extends another, it must include super() as first instruction in its constructor • Only create a constructor if it does something
  • 39. Class • Syntactic sugar over JavaScript use of function constructors • JavaScript uses proto-typical inheritance • If a class extends another, it must include super() as first instruction in its constructor • Only create a constructor if it does something
  • 40. import • Imports functions, objects, or primitives from other files • import <name> from “<module name>”; • import {name } from “<module name>”; • import * as Greetings from “<module name>”; • relative path indicates not an npm package
  • 41. export • export <var a> • export {a, b};
  • 42. export default • only one per file • common pattern for libraries • const Greetings = {sayHi, sayBye}; • export default Greetings; • export default {sayHi, sayBye};
  • 43. Importing Old School JS • Many JS libraries don’t support the new syntax • How do we use them? • import ‘jquery’;
  • 44. React
  • 45. React • A JavaScript library for building user interfaces • Created by Facebook & Instagram • Initial release March 2013 • Current version 15.6.1 • Next major version 16.0.0, will have breaking changes
  • 46. React • Virtual DOM • One-way data flow • JSX - JavaScript eXtension allows in HTML generation • Component-based
  • 47. React API • The use of JSX is optional in React • You can use the React “API” instead • The createClass method is deprecated and will be removed in React 16
  • 48. Component • Fundamental building block of React • Can be created with a JS Class or Function • The render method is mandatory
  • 49. Class Component 3 4 class Square extends React.Component { 5 render() { 6 return ( 7 <button 8 className="square" 9 onClick={() => this.props.onClick()}> 10 {this.props.value} 11 </button> 12 ); 13 } 14 } 15
  • 50. Functional Component 15 16 function Square(props) { 17 return ( 18 <button 19 className="square" 20 onClick={() => props.onClick()}> 21 {props.value} 22 </button> 23 ); 24 }
  • 51. React.PropTypes • React.PropTypes is deprecated • It will be deleted in React 16 • Use the npm package “prop-types” instead • import PropTypes from ‘prop-types’;
  • 52. PropTypes • PropTypes allow you to declare what properties your component expects • React validates property at runtime • Using propTypes is optional
  • 53. Some PropTypes Component Command PropTypes.array an optional array PropTypes.bool an optional bool PropTypes.element An optional React element PropTypes.func An optional function PropTypes.node Anything that can be rendered PropTypes.number An optional number PropTypes.object An optional object PropTypes.string An optional string PropTypes.symbol An optional Symbol
  • 54. PropType in code 1 2 import React from 'react'; 3 import ReactDOM from 'react-dom'; 4 import PropTypes from 'prop-types'; 5 6 class App extends React.Component { 7 render () { 8 return React.DOM.span(null, `My name is ${this.props.name}`); 9 } 10 } 11 12 App.propTypes = { 13 name: PropTypes.string.isRequired 14 }; 15 16 ReactDOM.render( 17 React.createElement(App, {}), 18 document.getElementById('root') 19 ); 20 21
  • 55. When property is missing
  • 56. React Components • Can be created two ways: • Using JavaScript • Using JSX
  • 57. Components via JS • React’s API contains method createElement() • Takes 3 parameters: type, props, children render() { return React.createElement('h1', null, "Hello there.");
  • 58. JSX • JavaScript Syntax EXtension • A mixture of JavaScript and HTML syntax • Compiles to JavaScript • Is optional but preferred over using JavaScript • Is easier to read
  • 59. JSX Attributes • Can assign either a string or an expression • Strings can be either single or double quotes • Expressions must be enclosed with curly braces
  • 60. Boolean Attributes • HTML has a few boolean attributes, if present they are true • Some of these include: checked, selected, disabled • In JSX, • <Component disabled={true / false} />
  • 61. Forbidden Attributes • Two attributes are JavaScript keywords • JavaScript keywords can’t be used in JSX • class -> className • for -> htmlFor
  • 62. JSX Spread Syntax • a shortcut to passing props to a component • uses ES2015 spread operator • <Component {…object} />
  • 63. JSX Spread Syntax return ( <Timer id={this.props.id} amount={this.props.amount} elapsed={this.props.elapsed} runningSince={this.props.runningSince} onStartClick={this.props.onStartClick} onStopClick={this.props.onStopClick} onResetClick={this.props.onResetClick} onSetClick={this.handleSetClick} /> );
  • 64. JSX Spread Syntax return ( <Timer {...this.props} onSetClick={this.handleSetClick} /> );
  • 65. JSX Debugging Tip • Assign component to a variable • console.log the variable
  • 66. JSX Debugging Tip const timerComp = ( <Timer troy='miles' {...this.props} onSetClick={this.handleSetClick} /> ); console.log(timerComp);
  • 69. Lifecycle Events Event When componentWillMount invoked once before rendering componentDidMount invoked after component loaded componentWillReceiveProps invoked when receiving new props shouldComponentUpdate asks if component should update componentWillUpdate invoked before rendering new props componentDidUpdate invoked after rendered new props componentWillUnmount invoked before component removed
  • 75. Platform Differences • Not all components work with all devices • Some are for iOS only or Android only • Those that end in IOS are for iOS • Those that end in Android are for Android
  • 76. Summary • React Native allows you to make mobile apps in JS • While easier than native development, it is not easy