modern ui development with node.js

122
Modern UI Development With Node.js

Upload: ryan-anklam

Post on 21-Aug-2015

1.110 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Modern UI Development With Node.js

Modern UI Development

With Node.js

Page 2: Modern UI Development With Node.js

@bittersweetryan

Page 3: Modern UI Development With Node.js
Page 4: Modern UI Development With Node.js
Page 5: Modern UI Development With Node.js

1990 1991

Sir Tim Berners-Lee writes HTML, URI, and

HTTP

Worlds first web page launched

CSS becomes W3C Recommendation

Page 6: Modern UI Development With Node.js

2011

Spike Brehm coins the term “isomorphic”

http://nerds.airbnb.com/isomorphic-javascript-future-web-apps/

2015

Michael Jackson says “universal” is better

https://medium.com/@mjackson/universal-javascript-4761051b7ae9

Page 7: Modern UI Development With Node.js

<code>

Page 8: Modern UI Development With Node.js

Step  0

Page 9: Modern UI Development With Node.js

Use. Modules.

http://mattsbrickgallery.tumblr.com/post/48739663720

Page 10: Modern UI Development With Node.js

An IIFE is not a module!

ES6 or CommonJS

Page 11: Modern UI Development With Node.js

ES6 ModulesECMA spec

browsers will (eventually) implement strict mode default

named exports and imports

Page 12: Modern UI Development With Node.js

ES6 Modulesspec had been under churn

browser support coming along slowly transpolation can get messy

cannot conditionally load them

Page 13: Modern UI Development With Node.js

CommonJSNode.js default module system

A single syntax for all the modules conditional loading

Page 14: Modern UI Development With Node.js

CommonJSNo strict mode default

different syntax for browser and node conditional loading is a double edge sword

Page 15: Modern UI Development With Node.js

The code you write today is

the code that will be copied tomorrow.

https://pixabay.com/p-26556/?no_redirect

Page 16: Modern UI Development With Node.js

ES6

Page 17: Modern UI Development With Node.js

ES2015

Page 18: Modern UI Development With Node.js

What is the first thing developers do when they start coding in a new

project?

Page 19: Modern UI Development With Node.js

⌘+v⌘+c

Page 20: Modern UI Development With Node.js

⌘+v

⌘+c

Page 21: Modern UI Development With Node.js

⌘+v⌘+c

Page 22: Modern UI Development With Node.js

Babel now!

Page 23: Modern UI Development With Node.js

classes

Page 24: Modern UI Development With Node.js

ui components as classes

Page 25: Modern UI Development With Node.js
Page 26: Modern UI Development With Node.js
Page 27: Modern UI Development With Node.js

These aren’t even mixins!

Page 28: Modern UI Development With Node.js

They should be modules!

Page 29: Modern UI Development With Node.js

UI components are modules

Page 30: Modern UI Development With Node.js
Page 31: Modern UI Development With Node.js
Page 32: Modern UI Development With Node.js
Page 33: Modern UI Development With Node.js

<build>

Page 34: Modern UI Development With Node.js

The build pipeline is the

foundation modern UI

projects are built on.

http://mdti.net/wp-content/uploads/2014/10/exterior-wall-crack-cropped.jpg

Page 35: Modern UI Development With Node.js

Your build chain is your development lifeline.

Treat it accordingly

Page 36: Modern UI Development With Node.js

Each step is a module.

Page 37: Modern UI Development With Node.js

Each module does one thing (demo)

Page 38: Modern UI Development With Node.js

If you have to require more than one plugin you might want to create another module.

Rule of thumb

Page 39: Modern UI Development With Node.js

Tip!Save your globs in a separate JSON file and

require them into your build modules.

Page 40: Modern UI Development With Node.js

Use your build tool to automate mundane tasks.

http://www.companiesandmarkets.com/Content/DynamicMedia/cms-uploaded/X-20140605161048330.jpg

Page 41: Modern UI Development With Node.js

testing

Page 42: Modern UI Development With Node.js

just do it

Page 43: Modern UI Development With Node.js

Test as you code

Page 44: Modern UI Development With Node.js

Test as you code

Test before you push

Page 45: Modern UI Development With Node.js

Test as you code

Test before you push

Test in you CI Server

Page 46: Modern UI Development With Node.js

Tip! Make testing easy and people will do it.

Page 47: Modern UI Development With Node.js

Easy is… fast automated easy to bootstrap having a culture of testing

Page 48: Modern UI Development With Node.js

Code  Quality

Page 49: Modern UI Development With Node.js

eslint

Page 50: Modern UI Development With Node.js

Why lint? catch common errors

catch oops moments (console.log, debugger)

Page 51: Modern UI Development With Node.js

Why eslint? Style checker

Pluggable Future friendly: ES6, JSX

configure rules [ignore, warn, error]

Page 52: Modern UI Development With Node.js

csslint

Page 53: Modern UI Development With Node.js

Nesting is the worst thing to happen to CSS.

Page 54: Modern UI Development With Node.js

You should never see this in css!

Page 55: Modern UI Development With Node.js

Don’t let lint errors in your

repos.

https://odetojoandkatniss.files.wordpress.com/2013/12/gc-nope.png

Page 56: Modern UI Development With Node.js

How?

Page 57: Modern UI Development With Node.js

push hooks

Page 58: Modern UI Development With Node.js

http://www.sitepoint.com/introduction-git-hooks/

pre-commit pre-push

pre-rebase commit-msg post-update

post-checkout post-merge

For GITAdd these files to your .git directory’s hooks folder

Page 59: Modern UI Development With Node.js

http://www.sitepoint.com/introduction-git-hooks/

pre-commit pre-pushpre-rebase

commit-msg post-update

post-checkout post-merge

This is your “Nope” button

Page 60: Modern UI Development With Node.js

git push --no-verify

Page 61: Modern UI Development With Node.js
Page 62: Modern UI Development With Node.js

Continuously Lint & Test Add your testing and linting

as part of the build process and in your CI tool.

Page 63: Modern UI Development With Node.js

Public shaming is a great motivator.

Page 64: Modern UI Development With Node.js

Automate Adding Hooks

Page 65: Modern UI Development With Node.js
Page 66: Modern UI Development With Node.js

<serve>

Page 67: Modern UI Development With Node.js

business logic, maybe some sql

Page 68: Modern UI Development With Node.js

business logic, maybe some sql

php/jsp/asp/erb/etc

Page 69: Modern UI Development With Node.js

business logic, maybe some sql

php/jsp/asp/erb/etc

run some JS on the client

Page 70: Modern UI Development With Node.js

RESTful API’s

Page 71: Modern UI Development With Node.js

RESTful API’s

JS template on the server

Page 72: Modern UI Development With Node.js

RESTful API’s

JS template on the server

interactive JS on the client

Page 73: Modern UI Development With Node.js

There is a large cost to context switching.

Page 74: Modern UI Development With Node.js

Proceed with Caution! Let node do what it’s good at, nothing more.

Don’t block Don’t implement business logic

fire & forget, take advantage of the message queue

Page 75: Modern UI Development With Node.js

Make calls to async services Compose a template Send the response

Page 76: Modern UI Development With Node.js

Some things have to be synchronous.

Keep as many of those at startup as you can.

Page 77: Modern UI Development With Node.js

Be aware of the “hot” path!

Code that will run with EVERY request.

Page 78: Modern UI Development With Node.js

Keep your functional programming off the hot path.

Page 79: Modern UI Development With Node.js

But what if?

Page 80: Modern UI Development With Node.js

RESTful API’s

Page 81: Modern UI Development With Node.js

RESTful API’s

JavaScript

Page 82: Modern UI Development With Node.js

Isomorphic!

Page 83: Modern UI Development With Node.js

Unimorphic!

Page 84: Modern UI Development With Node.js

Isomorual!

Page 85: Modern UI Development With Node.js

Universal!

Page 86: Modern UI Development With Node.js

Don’t let the demos fool you! Universal JS is hard!

Page 87: Modern UI Development With Node.js

Calling a template with some data to produce HTML is easy

Page 88: Modern UI Development With Node.js

De-hydrating data in Node and re-hydrating client in the browser is

HARD.

Page 89: Modern UI Development With Node.js

Getting your data can be really hard.

Page 90: Modern UI Development With Node.js

Don’t

Page 91: Modern UI Development With Node.js

Do

Page 92: Modern UI Development With Node.js

Use meta data to tell other modules what data the UI needs.

Page 93: Modern UI Development With Node.js

In React, statics are perfect for this.

Page 94: Modern UI Development With Node.js
Page 95: Modern UI Development With Node.js

Bind Falkor paths

Page 96: Modern UI Development With Node.js

Load i18n strings

Page 97: Modern UI Development With Node.js

Webpack & Browserify

Page 98: Modern UI Development With Node.js
Page 99: Modern UI Development With Node.js

Eac

Page 100: Modern UI Development With Node.js

Node code vs Browser code Client code is bundled, node code isn’t.

Page 101: Modern UI Development With Node.js

Why not run bundles in Node? It only takes a few configuration tweaks

http://jlongster.com/Backend-Apps-with-Webpack--Part-I

Page 102: Modern UI Development With Node.js

0) Collect your node_modules

Page 103: Modern UI Development With Node.js
Page 104: Modern UI Development With Node.js

Not a “hot” code path

Page 105: Modern UI Development With Node.js

1) Add another config to webpack.config.js

Page 106: Modern UI Development With Node.js

Export an array

Page 107: Modern UI Development With Node.js

Have multiple targets

Page 108: Modern UI Development With Node.js

2) Tell web pack to ignore your requires for node_modules AND your CSS

Page 109: Modern UI Development With Node.js

No Node node_modules

Page 110: Modern UI Development With Node.js

No css

Page 111: Modern UI Development With Node.js

$> node build/server.js

Page 112: Modern UI Development With Node.js

Next level Stuff

Page 113: Modern UI Development With Node.js

Weback dev server & hot module swapping.

(demo)

Page 114: Modern UI Development With Node.js

Last thoughts…

Page 115: Modern UI Development With Node.js

Start Small When Transitioning There are lots of learnings to be had from a single page

Page 116: Modern UI Development With Node.js

Legacy ServiceServiceService

Routing Layer ( /path match )

Node

Page 117: Modern UI Development With Node.js

Iterate on Modules Modules don’t have to be perfect at first

learn & refactor

Page 118: Modern UI Development With Node.js

Keep your code clean Don’t let bad code infect your repository.

Page 119: Modern UI Development With Node.js

Automate People are lazy. They will do the easy things and

ignore the hard things.

Page 120: Modern UI Development With Node.js

http://webdesign.tutsplus.com/articles/a-brief-history-of-the-world-wide-web--webdesign-8710

http://www.evolutionoftheweb.com/

http://nerds.airbnb.com/isomorphic-javascript-future-web-apps/

http://jlongster.com/Backend-Apps-with-Webpack--Part-I

References

Page 121: Modern UI Development With Node.js

Questions?