47
Breaking the Server-Client Divide with Node.js and React Dejan Glozic, Full-Stack Architect, IBM Cloud Data Services 2015 Programming Layer

Breaking the Server-Client Divide with Node.js and React

Embed Size (px)

Citation preview

Page 1: Breaking the Server-Client Divide with Node.js and React

Breaking the Server-Client Divide with Node.js and React

Dejan Glozic, Full-Stack Architect, IBM Cloud Data Services

2015 Programming Layer

Page 2: Breaking the Server-Client Divide with Node.js and React

About MeIBM Canada Toronto Lab

Full-Stack Architect IBM Cloud Data Services

@dglozic http://dejanglozic.com

Page 3: Breaking the Server-Client Divide with Node.js and React

What I Work On

Page 4: Breaking the Server-Client Divide with Node.js and React

Part 1Brief history of the server-client wars

Page 5: Breaking the Server-Client Divide with Node.js and React

First there was only serverIt sent pages with text, hyperlinks and images back to the browser.

Page 6: Breaking the Server-Client Divide with Node.js and React

Then we started running codeGreat improvement, pages started coming back tailored to the user and request.

Page 7: Breaking the Server-Client Divide with Node.js and React

Then came AjaxMicrosoft (yes, Microsoft) added XMLHTTPRequest.

JJG called this Ajax (I don’t even).

Page 8: Breaking the Server-Client Divide with Node.js and React

Then came the frameworksBecause spaghetti is great with meatballs, less great with jQuery.

Page 9: Breaking the Server-Client Divide with Node.js and React

It’s not done until it’s overdone‘Extreme Ajax’

desktop != server != client

Page 10: Breaking the Server-Client Divide with Node.js and React

2012, Twitter: Server is good!Pendulum swings back, because ‘time to the first tweet’ is less when server helps.

Page 11: Breaking the Server-Client Divide with Node.js and React

2013: Node.js extends UI tierNicholas Zakas says: UI is now client + Node.js server

Page 12: Breaking the Server-Client Divide with Node.js and React

2013: airbnb coins ‘Isomorphic’Then it creates rendr (Keynote spell checkr throws a hissy fit)

Page 13: Breaking the Server-Client Divide with Node.js and React

2014: React takes offYes, it was released in 2013 but you could not shut up about Angular then.

Page 14: Breaking the Server-Client Divide with Node.js and React

2015: React is HotAlso, a bunch of nerds get together at a Toronto conference to talk about all this.

Page 15: Breaking the Server-Client Divide with Node.js and React

Part 2Just enough React to make you dangerous.

Page 16: Breaking the Server-Client Divide with Node.js and React

Don’t compare React to Angular.

React is just for views. You need router, model and event layers.

Page 17: Breaking the Server-Client Divide with Node.js and React

It assumes life is shortYou (and others) should know what your code does 6 months from now.

Page 18: Breaking the Server-Client Divide with Node.js and React

It does not make you feel stupid<todo-cmp [model]="todo" (complete)="onCompletingTodo(todo)"></todo-cmp>

Page 19: Breaking the Server-Client Divide with Node.js and React

When the state changes, renderThat’s it. Seriously.

Page 20: Breaking the Server-Client Divide with Node.js and React

Virtual DOM is the keyReact diffs virtual and real DOM, applies delta only.

Page 21: Breaking the Server-Client Divide with Node.js and React

Virtual DOM in other contextsServer rendering, React Native.

Page 22: Breaking the Server-Client Divide with Node.js and React

Flux+React

DispatcherData Store

ViewServer ActionAction

Page 23: Breaking the Server-Client Divide with Node.js and React

Part 3In which we meet react-router and react-engine

JS

Page 24: Breaking the Server-Client Divide with Node.js and React

Flip the fake pagesBecause we are really just showing and hiding divs

Page 25: Breaking the Server-Client Divide with Node.js and React

Boxes inside other boxes

A

BC

Route: /A/B/C

Page 26: Breaking the Server-Client Divide with Node.js and React

React Express viewsVirtual DOM can render into a buffer - or an Express response.

Page 27: Breaking the Server-Client Divide with Node.js and React

react-router is JavaScriptAnd Node.js can run JavaScript on the server. Hmm…

Page 28: Breaking the Server-Client Divide with Node.js and React
Page 29: Breaking the Server-Client Divide with Node.js and React

Meet react-engineBlend server and client using React, Express, react-router and web pack

Page 30: Breaking the Server-Client Divide with Node.js and React

View

All together now

react-router

View react-engine server.js

react-engine client.js

react-router View

View

Server Client

Page 31: Breaking the Server-Client Divide with Node.js and React

Part 4Demo + code review, first attempt

Page 32: Breaking the Server-Client Divide with Node.js and React

How To Follow

• Source code on GitHub: http://github.com/dglozic/react-engine-demo

• Hosted on Bluemix: http://react-engine-demo.mybluemix.net

Page 33: Breaking the Server-Client Divide with Node.js and React

Part 5Once again, this time for the real world

Page 34: Breaking the Server-Client Divide with Node.js and React

Remember this page?

Page 35: Breaking the Server-Client Divide with Node.js and React

Not everybody uses ReactNeed a compromise UI composition solution for the uber-system.

Page 36: Breaking the Server-Client Divide with Node.js and React

Dust.js to the rescueHeader (HTML/CSS/JS)

Page content (React)Nav (ditto)

Microservice 1

Microservice 2 Microservice 3

Page 37: Breaking the Server-Client Divide with Node.js and React

Let’s try again

• Source code on GitHub: https://github.com/dglozic/fsto2015-demo

• Hosted on Bluemix: http://fsto-2015-demo.mybluemix.net/

Page 38: Breaking the Server-Client Divide with Node.js and React

ConclusionIsomorphic apps FTW

Page 39: Breaking the Server-Client Divide with Node.js and React

Server or client rendering? Yes!There is no need to choose sides any more.

Page 40: Breaking the Server-Client Divide with Node.js and React

Initial server renderingInstant browser content, automatic SEO

Page 41: Breaking the Server-Client Divide with Node.js and React

Client mountServer-rendered state is not lost

Page 42: Breaking the Server-Client Divide with Node.js and React

Client takes overAll the virtues of client side JS, guilt-free

Page 43: Breaking the Server-Client Divide with Node.js and React
Page 44: Breaking the Server-Client Divide with Node.js and React

Yes, I know about MeteorWe prefer flexibility of React ecosystem to ‘full framework’ lock-in of Meteor

Page 45: Breaking the Server-Client Divide with Node.js and React

React community hedgeOur full stack consists of multiple libraries, reducing single vendor risk

Page 46: Breaking the Server-Client Divide with Node.js and React

Q/A?

Page 47: Breaking the Server-Client Divide with Node.js and React

Thank you!Follow me on Twitter: @dglozicRead my blog: dejanglozic.com

2015 Programming Layer