Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

JavaScript developer friendly syntax

Slide 4

Slide 4 text

let meaningOfLife = 41 + 1;

Slide 5

Slide 5 text

let add = (x, y) => x + y; add(2, 2); add(41, 1);

Slide 6

Slide 6 text

let fruits = ["Apple", "Orange"];

Slide 7

Slide 7 text

if (true) { print_string("Hello World!"); };

Slide 8

Slide 8 text

OCaml semantics

Slide 9

Slide 9 text

Reason Syntax OCaml Syntax OCaml AST

Slide 10

Slide 10 text

Records

Slide 11

Slide 11 text

let jane = {name: "Jane", age: 40};

Slide 12

Slide 12 text

let jane = {name: "Jane", age: 40};

Slide 13

Slide 13 text

type person = { name: string, age: int, }; let jane = {name: "Jane", age: 40};

Slide 14

Slide 14 text

type person = { name: string, age: int, }; let jane = {name: "Jane", age: 40}; let tim = {...jane, name: "Tim"};

Slide 15

Slide 15 text

Compiles to JavaScript

Slide 16

Slide 16 text

Reason Syntax OCaml Syntax OCaml AST JavaScript BuckleScript

Slide 17

Slide 17 text

Reason Syntax OCaml Syntax OCaml AST Native Code JavaScript BuckleScript

Slide 18

Slide 18 text

Fromatter

Slide 19

Slide 19 text

Reason Syntax OCaml Syntax OCaml AST Native Code JavaScript BuckleScript

Slide 20

Slide 20 text

Reason Syntax OCaml Syntax OCaml AST Native Code JavaScript refmt BuckleScript

Slide 21

Slide 21 text

Statically Typed Language

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Why yet another one?

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

const pieces = [ { kind: "king", color: "black", position: [3, 4] }, { kind: "pawn", color: "black", position: [4, 2] }, { kind: "knight", color: "white", position: [3, 3] } ]; JavaScript

Slide 26

Slide 26 text

interface Piece { kind: string; color: string; position: number[]; } const pieces = [ { kind: "king", color: "black", position: [3, 4] }, { kind: "pawn", color: "black", position: [4, 2] }, { kind: "knight", color: "white", position: [3, 3] } ]; const getKinds = (pieces: Piece[]) => pieces.map(piece => piece.kind); TypeScript

Slide 27

Slide 27 text

interface Piece { kind: string; color: string; position: number[]; } const pieces = [ { kind: "king", color: "black", position: [3, 4] }, { kind: "pawn", color: "black", position: [4, 2] }, { kind: "knight", color: "white", position: [3, 3] } ]; const getKinds = (pieces: Piece[]) => pieces.map(piece => piece.kind); TypeScript

Slide 28

Slide 28 text

type piece = { kind: string, color: string, position: (int, int), }; let pieces = [ {kind: "king", color: "black", position: (3, 4)}, {kind: "pawn", color: "black", position: (4, 2)}, {kind: "knight", color: "white", position: (3, 3)}, ]; let getKinds = pieces => List.map(item => item.kind, pieces); Reason

Slide 29

Slide 29 text

Variants

Slide 30

Slide 30 text

type direction = | Up | Down | Left | Right;

Slide 31

Slide 31 text

type direction = | Up | Down | Left | Right; let move = Left;

Slide 32

Slide 32 text

type direction = | Up(int) | Down(int) | Left(int) | Right(int); let move = Left(2);

Slide 33

Slide 33 text

type data = {names: list(string)}; type request = | Loading | Error(int) | Success(data);

Slide 34

Slide 34 text

type color = Black | White; type kind = Queen | King | Rook | Bishop | Knight | Pawn; type piece = { color, kind, position: (int, int), }; let pieces = [ {kind: King, color: Black, position: (3, 4)}, {kind: Pawn, color: Black, position: (4, 2)}, {kind: Knight, color: White, position: (3, 3)}, ];

Slide 35

Slide 35 text

type color = Black | White; type kind = Queen | King | Rook | Bishop | Knight | Pawn; type piece = { color, kind, position: (int, int), }; let pieces = [ {kind: King, color: Black, position: (3, 4)}, {kind: Pawn, color: Black, position: (4, 2)}, {kind: Knight, color: White, position: (3, 3)}, ];

Slide 36

Slide 36 text

type color = Black | White; type kind = Queen | King | Rook | Bishop | Knight | Pawn; type piece = { color, kind, position: (int, int), }; let pieces = [ {kind: King, color: Black, position: (3, 4)}, {kind: Pawn, color: Black, position: (4, 2)}, {kind: Knight, color: White, position: (3, 3)}, ];

Slide 37

Slide 37 text

Pattern Matching

Slide 38

Slide 38 text

switch () { | => | => | ... };

Slide 39

Slide 39 text

switch (1) { | 0 => "off" | 1 => "on" | _ => "off" };

Slide 40

Slide 40 text

let displayText = switch (1) { | 0 => "off" | 1 => "on" | _ => "off" };

Slide 41

Slide 41 text

type data = {names: list(string)}; type request = | Loading | Error(int) | Success(data); let ui = switch (Loading) { | Loading => "Loading ..." | Error(code) => "Something went wrong. Error: " ++ string_of_int(code) | Success(data) => List.fold_left((a, b) => a ++ b, "Names:", data.names) };

Slide 42

Slide 42 text

type data = {names: list(string)}; type request = | Loading | Error(int) | Success(data); let ui = switch (Loading) { | Loading => "Loading ..." | Error(401) => "You aren’t authenticated." | Error(code) => "Something went wrong. Error: " ++ string_of_int(code) | Success(data) => List.fold_left((a, b) => a ++ b, "Names:", data.names) };

Slide 43

Slide 43 text

type data = {names: list(string)}; type request = | Loading | Error(int) | Success(data); let ui = switch (Loading) { | Loading => "Loading ..." | Error(401 | 402) => "You aren’t authenticated." | Error(code) => "Something went wrong. Error: " ++ string_of_int(code) | Success(data) => List.fold_left((a, b) => a ++ b, "Names:", data.names) };

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

– Tony Hoare “I call it my billion-dollar mistake …”

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

Lesson I Don’t implement anything just because it’s easy!

Slide 49

Slide 49 text

Lesson II Null is BAD!

Slide 50

Slide 50 text

null; // doesn't exist!

Slide 51

Slide 51 text

Option

Slide 52

Slide 52 text

let foo = None; let foo = Some(42); let foo = Some([1, 2, 3]); let foo = Some("Hello World!");

Slide 53

Slide 53 text

let foo = None; let foo = Some(42); let foo = Some([1, 2, 3]); let foo = Some("Hello World!"); switch (foo) { | None => "Sadly I don't know." | Some(value) => "It's " ++ value };

Slide 54

Slide 54 text

Functions

Slide 55

Slide 55 text

let add = (x, y) => x + y; add(2, 2); add(41, 1);

Slide 56

Slide 56 text

let name = (~firstName, ~lastName) => firstName ++ " " ++ lastName; /* Jane Doe */ name(~firstName="Jane", ~lastName="Doe"); /* Jane Doe */ name(~lastName="Doe", ~firstName="Jane");

Slide 57

Slide 57 text

ReasonReact

Slide 58

Slide 58 text

Stateless Component let component = ReasonReact.statelessComponent("Greeting"); let make = (_children) => { ...component, render: _self =>

(ReasonReact.string("Hello"))

, }; ReactDOMRe.renderToElementWithId(, "root"); Greeting.re App.re

Slide 59

Slide 59 text

Props let component = ReasonReact.statelessComponent("Greeting"); let make = (~name, _children) => { ...component, render: _self =>

(ReasonReact.string(“Hello " ++ name))

, }; ReactDOMRe.renderToElementWithId(, "root"); Greeting.re App.re

Slide 60

Slide 60 text

Props let component = ReasonReact.statelessComponent("Greeting"); let make = (~name, _children) => { ...component, render: _self =>

(ReasonReact.string("Hello " ++ name))

, }; ReactDOMRe.renderToElementWithId(, "root"); Greeting.re App.re

Slide 61

Slide 61 text

Props let component = ReasonReact.statelessComponent("Greeting"); let make = (~name, _children) => { ...component, render: _self =>

(ReasonReact.string("Hello " ++ name))

, }; ReactDOMRe.renderToElementWithId(, "root"); Greeting.re App.re

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

type state = {count: int};

Slide 64

Slide 64 text

type state = {count: int}; type action = | Add(int) | Reset;

Slide 65

Slide 65 text

type state = {count: int}; type action = | Add(int) | Reset; let s = ReasonReact.string;

Slide 66

Slide 66 text

type state = {count: int}; type action = | Add(int) | Reset; let s = ReasonReact.string; let component = ReasonReact.reducerComponent("Counter");

Slide 67

Slide 67 text

type state = {count: int}; type action = | Add(int) | Reset; let s = ReasonReact.string; let component = ReasonReact.reducerComponent("Counter"); let make = _children => { ...component, initialState: () => {count: 0},

Slide 68

Slide 68 text

type state = {count: int}; type action = | Add(int) | Reset; let s = ReasonReact.string; let component = ReasonReact.reducerComponent("Counter"); let make = _children => { ...component, initialState: () => {count: 0}, reducer: (action, state) => switch (action) { | Add(value) => ReasonReact.Update({count: state.count + value}) | Reset => ReasonReact.Update({count: 0}) },

Slide 69

Slide 69 text

type state = {count: int}; type action = | Add(int) | Reset; let s = ReasonReact.string; let component = ReasonReact.reducerComponent("Counter"); let make = _children => { ...component, initialState: () => {count: 0}, reducer: (action, state) => switch (action) { | Add(value) => ReasonReact.Update({count: state.count + value}) | Reset => ReasonReact.Update({count: 0}) }, render: self =>
(s(string_of_int(self.state.count)))

Slide 70

Slide 70 text

let s = ReasonReact.string; let component = ReasonReact.reducerComponent("Counter"); let make = _children => { ...component, initialState: () => {count: 0}, reducer: (action, state) => switch (action) { | Add(value) => ReasonReact.Update({count: state.count + value}) | Reset => ReasonReact.Update({count: 0}) }, render: self =>
(s(string_of_int(self.state.count))) self.send(Add(1)))> (s(“Add")) self.send(Add(2)))> (s("Add 2")) self.send(Reset))> (s("Reset"))
, };

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

Manage your State with GraphQL

Slide 73

Slide 73 text

Interop with JavaScript

Slide 74

Slide 74 text

BuckleScript allows us to write bindings ReasonReact - wrapJsForReason - wrapReasonForJs

Slide 75

Slide 75 text

[@bs.module "rebass"] external jsArrow : ReasonReact.reactClass = "Arrow"; let make = (~direction: string, children) => ReasonReact.wrapJsForReason( ~reactClass=jsArrow, ~props={"direction": direction}, children, );

Slide 76

Slide 76 text

Slide 77

Slide 77 text

Slide 78

Slide 78 text

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

Variants to the rescue!

Slide 81

Slide 81 text

[@bs.module "rebass"] external jsArrow : ReasonReact.reactClass = "Arrow"; type direction = | Up | Down; let make = (~direction, children) => { let directionString = switch (direction) { | Up => "up" | Down => "down" }; ReasonReact.wrapJsForReason( ~reactClass=jsArrow, ~props={"direction": directionString}, children, ); };

Slide 82

Slide 82 text

;

Slide 83

Slide 83 text

;

Slide 84

Slide 84 text

;

Slide 85

Slide 85 text

So what now?

Slide 86

Slide 86 text

Don’t be that person

Slide 87

Slide 87 text

Time Innovation React Ecosystem

Slide 88

Slide 88 text

Time Innovation React Ecosystem Reason Ecosystem

Slide 89

Slide 89 text

Day 1: Workshop Day 2: Talks Day 3: Hackathon

Slide 90

Slide 90 text

The End