single page application js framework round up

78
SPA frameworks SPA JS FRAMEWORK ROUNDUP

Upload: frank-duan

Post on 04-Aug-2015

96 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Single Page Application JS Framework Round up

SPA frameworks

SPA JS FRAMEWORK ROUNDUP

Page 2: Single Page Application JS Framework Round up

SPA frameworks

Flux

Page 3: Single Page Application JS Framework Round up

SPA frameworks

CONTENT

๏ How to choose

๏ Overview

๏ Under microscope

๏ What to choose

๏ Technologies on the horizon

Page 4: Single Page Application JS Framework Round up

How to Choose

HOW TO CHOOSE

Page 5: Single Page Application JS Framework Round up

How to Choose

SPA FRAMEWORKS

๏ App vs Site

๏ Framework vs toolset

๏ Project context

Page 6: Single Page Application JS Framework Round up

How to Choose

CRITERIA๏ Aims& Philosophies

๏ Abstractions

๏ Learning curve

๏ Build& Dev tools

๏ Testability

๏ Performance

๏ Implementations of modules

๏ models

๏ controllers

๏ views

๏ routes

๏ template

๏ components

Page 7: Single Page Application JS Framework Round up

Overview

OVERVIEW

Page 8: Single Page Application JS Framework Round up

Overview

IN COMMON

๏ Open-sourced

๏ MIT licensed

๏ Mature and widely used

๏ Strong community support

๏ Big player backed

Page 9: Single Page Application JS Framework Round up

Overview

STATS

Metric AngularJSBackbone.js Ember.js React.js

Stars on Github

38k 21k 14k 21k

Third-Party Modules

1384 modules

249 backplugs

947 addons ~100

StackOverflow Questions

110k 20k 22k 6k

GitHub Contributors

1232 256 479 394

Page 10: Single Page Application JS Framework Round up

Overview

PHILOSOPHIES: ANGULAR

Angular is not a framework, it’s an HTML compiler - Misko Hevery, creator of Angular

AngularJS is a toolset for building the framework most suited to your application development -AngularJS Homepage

Page 11: Single Page Application JS Framework Round up

Overview

PHILOSOPHIES: ANGULAR

๏ Provide low level primitives

๏ data-binding on POJO

๏ dependency injection

๏ Declarative HTML

๏ Leave high level abstraction to devs

Page 12: Single Page Application JS Framework Round up

Overview

PHILOSOPHIES: EMBER

Ember.js is a framework for creating ambitious web application - Ember.js Homepage

Page 13: Single Page Application JS Framework Round up

Overview

PHILOSOPHIES: EMBER

๏ Embrace high level abstractions

๏ Framework encapsulation

๏ Conventions over configurations

๏ Framework classes over vanilla primitives

Page 14: Single Page Application JS Framework Round up

Overview

PHILOSOPHIES: BACKBONE

Backbone is an attempt to discover the minimal set of data-structuring and user interface primitives…and a tool that gives you the freedom to design the full experience of your web application.

- Backbone.js Homepage

Page 15: Single Page Application JS Framework Round up

Overview

PHILOSOPHIES: BACKBONE

๏ Toolset than Full-stack Framework

๏ Minimalism

๏ DIY& BYO

Page 16: Single Page Application JS Framework Round up

Overview

PHILOSOPHIES: REACT + FLUX

We built React to solve one problem: building large applications with data that changes over time. -React.js Homepage

Flux is a system architecture that promotes single directional data flow through an application. - Tom Occhino, Engineering Manager at Facebook

Page 17: Single Page Application JS Framework Round up

Overview

PHILOSOPHIES: REACT

๏ UI Responsiveness

๏ Performant rendering

๏ Reusable components

๏ Immutable data

Page 18: Single Page Application JS Framework Round up

Overview

PHILOSOPHIES: FLUX

๏ Unidirectional data flow

๏ feature development scalability

Page 19: Single Page Application JS Framework Round up

Overview

ARCHITECTURE:MVC/ MV*

Page 20: Single Page Application JS Framework Round up

Overview

ARCHITECTURE:FLUX

Page 21: Single Page Application JS Framework Round up

Under Microscope

UNDER MICROSCOPE

Page 22: Single Page Application JS Framework Round up

SPA frameworks

Flux

Page 23: Single Page Application JS Framework Round up

ANGULAR VS EMBER: TO POJO OR NOT TO

POJO

Under Microscope

Page 24: Single Page Application JS Framework Round up

ANGULAR VS EMBER: TO POJO OR NOT TO

POJO

Under Microscope

Page 25: Single Page Application JS Framework Round up

ANGULAR VS EMBER: TO POJO OR NOT TO

POJO

Under Microscope

Page 26: Single Page Application JS Framework Round up

PROS& CONS OF POJO

Under Microscope

๏ Gentler Learning curve at start

๏ Shallower stack trace

๏ Dirty check for data-binding work for all POJO

Page 27: Single Page Application JS Framework Round up

PROS& CONS OF POJO

Under Microscope

๏ Solid skills on JS, familiar with native gotchas

๏ Dirty check performance on massive list

๏ Steeper learning curve afterward

Page 28: Single Page Application JS Framework Round up

PROS& CONS OF ENHANCED CLASS

Under Microscope

๏ OO pattern

๏ Uniform Access Principle with accessor

๏ accessor enable proxy pattern

Page 29: Single Page Application JS Framework Round up

Under Microscope

๏ Steeper Learning curve at start

๏ Big Framework code base

๏ Extra stack trace

PROS& CONS OF ENHANCED CLASS

Page 30: Single Page Application JS Framework Round up

LEARNING CURVE MATTERS

Under Microscope

Page 31: Single Page Application JS Framework Round up

ANGULAR VS EMBER:DOM MANIPULATION

Under Microscope

Page 32: Single Page Application JS Framework Round up

Under Microscope

๏ Angular directive gives you maximal, granular control over behavioural configuration of DOM manipulation.

๏ {restrict: ‘E/A’ , replace: true, scope: {foo: ‘bar’}} ng-transclustion

๏ http://jsfiddle.net/qy7Bt/247/

ANGULAR VS EMBER:DOM MANIPULATION

Page 33: Single Page Application JS Framework Round up

Under Microscope

๏ Ember components, Ember.Component is an element-restricted, isolate-scoped, transcluded directive.

๏ A component is a subclass of view for composability, share ability, reusability

๏ http://jsbin.com/dotowereda/2/edit?html,js,output

ANGULAR VS EMBER:DOM MANIPULATION

Page 34: Single Page Application JS Framework Round up

ANGULAR VS EMBER: ROUTING

Under Microscope

Page 35: Single Page Application JS Framework Round up

Under Microscope

๏ Transitions between different states in the app.

๏ Finite state machines & hierarchical state machines

ANGULAR VS EMBER: ROUTING

Page 36: Single Page Application JS Framework Round up

Under Microscope

ANGULAR VS EMBER: ROUTING

Page 37: Single Page Application JS Framework Round up

Under Microscope

ANGULAR VS EMBER: ROUTING

Page 38: Single Page Application JS Framework Round up

Under Microscope

ANGULAR VS EMBER: ROUTING

Page 39: Single Page Application JS Framework Round up

ANGULAR VS EMBER: TEMPLATING

Under Microscope

Page 40: Single Page Application JS Framework Round up

Under Microscope

ANGULAR VS EMBER: TEMPLATING

๏ Declarative HTML

๏ Directives

๏ Expressions

Page 41: Single Page Application JS Framework Round up

Under Microscope

ANGULAR VS EMBER: TEMPLATING

๏ Handlebar template

๏ Helper

๏ No expression in template

{{highlight name}}// this helper generates the following<span class=“highlight">Peter</span>

Page 42: Single Page Application JS Framework Round up

WITH GREAT POWER COMES GREAT

RESPONSIBILITY.

Under Microscope

Page 43: Single Page Application JS Framework Round up

ANGULAR VS EMBER: TESTABILITY

Under Microscope

Page 44: Single Page Application JS Framework Round up

Under Microscope

ANGULAR VS EMBER: TESTABILITY

Page 45: Single Page Application JS Framework Round up

Under Microscope

ANGULAR VS EMBER: TESTABILITY

Page 46: Single Page Application JS Framework Round up

ANGULAR VS EMBER: PERFORMANCE

Under Microscope

Page 47: Single Page Application JS Framework Round up

Under Microscope

ANGULAR VS EMBER: PERFORMANCE

๏ minified gzipped js asset

๏ Bootstrapping and overhead

๏ List rendering

๏ Dirty check on massive POJO

Page 48: Single Page Application JS Framework Round up

Under Microscope

Page 49: Single Page Application JS Framework Round up

BACKBONE.JS๏ Minimal

Toolset

๏ Underscore.js & jQuery

๏ Modules

๏ events

๏ models

๏ collections

๏ router

๏ views

Under Microscope

Page 50: Single Page Application JS Framework Round up

Under Microscope

Page 51: Single Page Application JS Framework Round up

REACT.JS

๏ DOM rendering performance

๏ Reusable component

๏ re-thinking on web presentation

๏ State management is hard

๏ Data changing over time is the root of all evil

Under Microscope

Page 52: Single Page Application JS Framework Round up

REACT.JS

๏ Separate state change and immutable data

๏ Re-render the whole component when state changes

Under Microscope

Page 53: Single Page Application JS Framework Round up

HOW RE-RENDERING EVERYTHING CAN BE

PERFORMANT?

Under Microscope

Page 54: Single Page Application JS Framework Round up

VIRTUAL DOM TO RESCUE.

Under Microscope

Page 55: Single Page Application JS Framework Round up

REACT.JS

๏ Javascript is Fast, native DOM is slow

๏ Construct virtual DOMs and diff

๏ Perform minimal changes on native DOM

๏ Beyond HTML DOM

Under Microscope

Page 56: Single Page Application JS Framework Round up

Under Microscope

Flux

Page 57: Single Page Application JS Framework Round up

FLUX: 2-WAY BINDING IS EVIL

๏ Cascading updates

๏ Unpredictable view presentations

Under Microscope

Page 58: Single Page Application JS Framework Round up

FLUX: UNIDIRECTIONAL

DATA FLOW๏ Use explicit data instead of

derived data

๏ Separate data from view state

๏ Avoid cascading effects by preventing nested updates

Under Microscope

Page 59: Single Page Application JS Framework Round up

FLUX: UNIDIRECTIONAL

DATA FLOW

Under Microscope

Page 60: Single Page Application JS Framework Round up

FLUX: DISPATCHER

๏ Action receiver

๏ Traffic control

๏ Store registries

๏ Store dependencies

Under Microscope

Page 61: Single Page Application JS Framework Round up

FLUX: STORES

๏ Manage states of a particular domain

๏ state of a domain, not of one model or collection

๏ Broadcast state changes

๏ Provide view explicit data

Under Microscope

Page 62: Single Page Application JS Framework Round up

FLUX: VIEWS

๏ Hierarchical structure

๏ Data flow down the chain

๏ Trigger actions from user interaction

Under Microscope

Page 63: Single Page Application JS Framework Round up

WHAT TO CHOOSE

What to Choose

Page 64: Single Page Application JS Framework Round up

๏ Mature dev team with solid skill

๏ Build your own framework

๏ Abstractions on domain

๏ Vanilla primitive lover

๏ Gentler learning curve at start

What to Choose

Page 65: Single Page Application JS Framework Round up

๏ Best practice& conventions

๏ Enhanced classes

๏ Steeper learning curve at start

๏ Familiar with Rails conventions

๏ Restful backend API (e.g. Rails)

What to Choose

Page 66: Single Page Application JS Framework Round up

๏ Understand the project growth boundary

๏ DIY for fun, BYO from scratch

๏ Learn from backbone + underscore codebase

What to Choose

Page 67: Single Page Application JS Framework Round up

๏ React for high performant component

๏ Flux for sophisticated presentation logic

๏ Devs live on the edge

What to Choose

Flux

Page 68: Single Page Application JS Framework Round up

ON THE HORIZON

On the Horizon

Page 69: Single Page Application JS Framework Round up

WEB COMPONENT๏ Composability Encapsulation

Reusability

๏ Techniques:

๏ Custom Elements

๏ HTML Templates

๏ Shadow DOM

๏ HTML import

On the Horizon

Page 70: Single Page Application JS Framework Round up

VIRTUAL DOM

๏ Implementations inspired by React

๏ Ember employs simple-dom for `FastBoot`

On the Horizon

Page 71: Single Page Application JS Framework Round up

SERVER-SIDE RENDERING

๏ Overhead for large app

๏ Render depends on devises

๏ Render for crawler, cURL, or non-JS env

๏ Virtual DOM requires no Browser Runtime

๏ Browser runtime in Node.js

On the Horizon

Page 72: Single Page Application JS Framework Round up

ES6 PROMISE๏ Represents the result of an async

operation.

๏ Pending/ Fulfilled/ Rejected/ Settled

On the Horizon

Page 73: Single Page Application JS Framework Round up

ES6 PROMISE

On the Horizon

Page 74: Single Page Application JS Framework Round up

ES6 PROMISE

๏ Ember’s RSVP.js is an implementation of Promise

๏ Angular’s $q conform to Promise spec

๏ Flux encourage use Promise

On the Horizon

Page 75: Single Page Application JS Framework Round up

ES7 OBJECT.OBSERVE()

On the Horizon

Page 76: Single Page Application JS Framework Round up

ES7 OBJECT.OBSERVE()

๏ No drity checking for data-binding

๏ Performance guaranteed by Native runtime

๏ Angular receives a great performance boost

๏ Ember& Backbone can utilise native support

On the Horizon

Page 77: Single Page Application JS Framework Round up

Q& A

SPA frameworks

Page 78: Single Page Application JS Framework Round up

THANKS!

SPA frameworks