smart and dumb components

118
DUMB & SMART COMPONENTS @hirez_io

Upload: shai-reznik

Post on 15-Apr-2017

982 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Smart and Dumb Components

DUMB & SMARTCOMPONENTS

@hirez_io

Page 2: Smart and Dumb Components

@shai_reznik

Long Time Front End

teacher, husband, daughter, improv,

mud wrestling

Page 3: Smart and Dumb Components

NG-WAT

Page 4: Smart and Dumb Components
Page 5: Smart and Dumb Components
Page 6: Smart and Dumb Components

SURVEYCOMPONETS?

REDUX / FLUX? RX?

Page 7: Smart and Dumb Components

THIS TALK

DATA FLOW

COMPONETS

SMART AND DUMB

Page 8: Smart and Dumb Components

STORYTIME!

Page 9: Smart and Dumb Components
Page 10: Smart and Dumb Components

ANGULAR?

Seriously?

move to React

and Flux bro...

Page 11: Smart and Dumb Components

This is NOT Jeff Cross

moving to react & flux...

Page 12: Smart and Dumb Components

A DAY LATER

Page 13: Smart and Dumb Components

Use REDUX!Use REDUX!

FLUX?FLUX?

So 2015...So 2015...

Page 14: Smart and Dumb Components
Page 15: Smart and Dumb Components

refactoring to REDUX...

Page 16: Smart and Dumb Components

A WEEK LATER

Page 17: Smart and Dumb Components
Page 18: Smart and Dumb Components

REDUX?

IT'S AWEFUL!

DON'T USE REDUX

Page 19: Smart and Dumb Components

It'll KIDNAP

your children!!!

Page 20: Smart and Dumb Components

REDUX?

CYCLE.JS dude...

It's much more FRP...

Page 21: Smart and Dumb Components
Page 22: Smart and Dumb Components

TOO MUCH STUFF!

Page 23: Smart and Dumb Components

TOO MANY WORDS!

Page 24: Smart and Dumb Components

FLUX

Page 25: Smart and Dumb Components

REDUX

Page 26: Smart and Dumb Components

REFLUX

Page 27: Smart and Dumb Components
Page 28: Smart and Dumb Components

CYCLE.JS

Page 29: Smart and Dumb Components

RXJS

Page 30: Smart and Dumb Components
Page 31: Smart and Dumb Components

NG-RX

Page 32: Smart and Dumb Components
Page 33: Smart and Dumb Components
Page 34: Smart and Dumb Components

RX-JFLUX

Page 35: Smart and Dumb Components
Page 36: Smart and Dumb Components

ELM

Page 37: Smart and Dumb Components

I FEEL DUMB

Page 38: Smart and Dumb Components
Page 39: Smart and Dumb Components

BUT...

Page 40: Smart and Dumb Components

I ALSO

LOVE IT!

Page 41: Smart and Dumb Components

IT'S GREAT

BECAUSE...

Page 42: Smart and Dumb Components

IT'S INSPIRING!

Page 43: Smart and Dumb Components

DON'T RUSH TO

CHANGE YOUR STACK

Page 44: Smart and Dumb Components

BUT DO LEARN THE

BACKGROUND

Page 45: Smart and Dumb Components

WE'RE DEALING WITH

THE SAME PROBLEM

Page 46: Smart and Dumb Components
Page 47: Smart and Dumb Components

DATA FLOW

Page 48: Smart and Dumb Components

FLUX / REDUX

1 way data flow

Page 49: Smart and Dumb Components

CYCLE + RX.JS

1 way data flowwith observables

Page 50: Smart and Dumb Components

EVERYTIME I HEAR ABOUT OBESERVABLES

Page 51: Smart and Dumb Components

DATA FLOW

Page 52: Smart and Dumb Components

DATA FLOW

VIEW LOGIC

CLIENT APP

Page 53: Smart and Dumb Components

DATA FLOW

VIEW LOGIC

CLIENT APP

Page 54: Smart and Dumb Components

DATA FLOW

VIEW LOGIC

Page 55: Smart and Dumb Components

DATA FLOW

VIEW

app brain

Page 56: Smart and Dumb Components

DATA FLOWcomponent tree app brain

Page 57: Smart and Dumb Components

WHAT'S A COMPONENT?

?

Page 58: Smart and Dumb Components

STORYTIME!

Page 59: Smart and Dumb Components

Back in the old days...

Page 60: Smart and Dumb Components

Tab 2 Tab 3

SIDE BARLinkLinkLinkLinkLinklink

Tab 1LOGO

Page 61: Smart and Dumb Components
Page 62: Smart and Dumb Components

ng-controller

ng-include

Page 63: Smart and Dumb Components

ng-include

Page 64: Smart and Dumb Components
Page 65: Smart and Dumb Components

Tab 2 Tab 3

SIDE BARLinkLinkLinkLinkLinklink

Tab 1LOGO

Page 66: Smart and Dumb Components

Tab 2 Tab 3

SIDE BARLinkLinkLinkLinkLinklink

Tab 1LOGO

Page 67: Smart and Dumb Components

Tab 2 Tab 3

SIDE BARLinkLinkLinkLinkLinklink

Tab 1LOGO

Page 68: Smart and Dumb Components

REACT

Page 69: Smart and Dumb Components

COMPONENT

+ =

Page 70: Smart and Dumb Components

DIRECTIVES!!!

Page 71: Smart and Dumb Components

NOT EXACTLY...

Page 72: Smart and Dumb Components

DIRECTIVE

DIRECTIVE

2 way binding

LESS RESTRICTIVE

Page 73: Smart and Dumb Components
Page 74: Smart and Dumb Components

ANGULAR 2@Component({ selector: 'my-component', templateUrl: ' my-template.html'})export class MyComponent { constructor() { }}

Page 75: Smart and Dumb Components

ANGULAR 2@Component({ selector: 'my-component', templateUrl: ' my-template.html'})export class MyComponent { constructor() { }}

1 way data binding!

@Input() myProperty

;

Page 76: Smart and Dumb Components

ANGULAR 1.5angular.module('myApp')

.component('my-component', {controller: MyComponent,

templateUrl: ' my-template.html'})

function MyComponent {}

Page 77: Smart and Dumb Components

ANGULAR 1.5angular.module('myApp')

.component('my-component', {controller: MyComponent,

templateUrl: ' my-template.html'})

function MyComponent {}

1 way data binding!

myProperty: “<“

Page 78: Smart and Dumb Components

PARENTCOMPONENT

CHILDCOMPONENT

COMPOSITION

Page 79: Smart and Dumb Components

PARENTCOMPONENT

CHILDCOMPONENT

eventsstate

API

Page 80: Smart and Dumb Components

injectsSERVICES

API

COMPONENT

Page 81: Smart and Dumb Components
Page 82: Smart and Dumb Components

app braincomponent tree

?

Page 83: Smart and Dumb Components

OPTION #1

ROOTAPP LOGIC

COMPONENT COMPONENT

COMPONENT COMPONENT

Page 84: Smart and Dumb Components

OPTION #1

ROOTAPP LOGIC

COMPONENT COMPONENT

COMPONENT COMPONENT

state

Page 85: Smart and Dumb Components

OPTION #1

ROOTAPP LOGIC

COMPONENT COMPONENT

COMPONENT COMPONENT

events

Page 86: Smart and Dumb Components

NOT OPTIMAL

<child1 handle-click=”child1Click()”></child1><child2 handle-click=”child2Click()”

grandchild1-data=”data.items”grandchild2-data=”data.filters”grandchild3-data=”data.user”></child2>

ROOT TEMPLATE

Page 87: Smart and Dumb Components

NOT OPTIMAL

<child1 handle-click=”child1Click()”></child1><child2 handle-click=”child2Click()”

grandchild1-data=”data.items”grandchild2-data=”data.filters”grandchild3-data=”data.user”></child2>

ROOT TEMPLATE

Page 88: Smart and Dumb Components

OPTION #2

ROOTAPP LOGIC

COMPONENT COMPONENT

COMPONENT COMPONENT

Page 89: Smart and Dumb Components

CAN'T REUSE

COMPONETS!

Page 90: Smart and Dumb Components

DUMB & SMARTCOMPONENTS

Page 91: Smart and Dumb Components

WHAT IS A DUMB COMPONENT?

Page 92: Smart and Dumb Components

EXAMPLES

Page 93: Smart and Dumb Components

WELL... THAT WAS DUMB...

Page 94: Smart and Dumb Components

ACTUALLY...

Page 95: Smart and Dumb Components
Page 96: Smart and Dumb Components

https://medium.com/@dan_abramov

Page 97: Smart and Dumb Components

https://medium.com/@dan_abramov

Page 98: Smart and Dumb Components

HIGHER ORDER COMPONENTS

Page 99: Smart and Dumb Components

BE THAT GUYBE THAT GUY

Page 100: Smart and Dumb Components

DUMBCOMPONENTS

Page 101: Smart and Dumb Components

PARENT

DUMB

eventsstate

Page 102: Smart and Dumb Components

REUSABLE

EXMAPLES:select, user-card, panel...

Page 103: Smart and Dumb Components
Page 104: Smart and Dumb Components

SMARTCOMPONENTS

Page 105: Smart and Dumb Components

SMART

injects

APP LEVELSERVICES

Page 106: Smart and Dumb Components

SMART

methods

state

APP

Page 107: Smart and Dumb Components

OPTION #1

ROOTAPP LOGIC

COMPONENT COMPONENT

COMPONENT COMPONENT

Page 108: Smart and Dumb Components

OPTION #2

ROOTAPP LOGIC

COMPONENT COMPONENT

COMPONENT COMPONENT

Page 109: Smart and Dumb Components

OPTION #3

SMARTAPP LOGIC

DUMB SMART

DUMB SMART

Page 110: Smart and Dumb Components

DEMOTIME!

Page 111: Smart and Dumb Components
Page 112: Smart and Dumb Components

AND... WE'RE BACK!

Page 113: Smart and Dumb Components

BONNIE RECOMMENDS

Page 114: Smart and Dumb Components

DUMB:

MOCKUPS + ONGOING REFACTORING

SMART:

ALL THE REST...

Page 115: Smart and Dumb Components

MORE TO COVER

* PRESENTATION STATE?

* ”OK” COMPONENTS?

* MORE...

Page 116: Smart and Dumb Components
Page 117: Smart and Dumb Components

SUMMARY✔USE COMPONENTS

✔DUMB IS MORE REUSABLE

✔GET INSPIRED FROM OTHERS!

Page 118: Smart and Dumb Components

THANK YOU!

@hirez_io @shai_reznik

Sign up for free