Takeaways from

Kevin C Chen @ Product Development Group

What is takes to building a Modern Web App...

Toolchain

Frameworks
&
Libraries

UI / UX

Platforms

SOA

Performance

Browsers

Testing

i18n

Security

Existing Code

There is got to be a better way...

Why?

  • Complement our existing UI/UX expertise with the fast evolving "front-end" technology stack
     
  • Learn the best practices & experience of early adopters
     
  • Become capable of building modern Web App products

Days

52 Sessions

~10 Sponsor Booths

(<$100 conf pass, no swag, dinner or party...opps...)

Sessions & Domains

  • ECMA 2015: aka ES 6 
  • Service
  • Tooling / Workflow
  • JavaScript
  • React
  • Websocket -  real-time app & IoT
  • i18n
  • Data Visualization
  • Security
  • CSS 

ECMAScript 2015

  • a.k.a: ES 6
     
  • Latest standard / spec of JavaScript
    • Finalized in June of 2015
    • The "Current" version of JavaScript

ECMAScript 2015

  • Enables you to
     
    • Write maintanable/shorter code 
       
    • Avoid common JavaScript pitfalls
       
    • Leverage latest browser features
var a = 1; 
function foo() {
    var b = 0
    
    if (a) {
	var a = 2;
        var b = a + 2;      
        console.log(b);                        
    }    
    console.log(a);
       
    console.log(b);
}
console.log(a);  
foo();

Quiz: What is logged to the console?

1

undefined

0

let a = 1; 
function foo() {
    let b = 0
    
    if (a) {
	let a = 2;
        let b = a + 2;      
        console.log( b );                        
    }    
    console.log( a );    
   
    console.log( b );
}
console.log( a );  
foo();

ECMAScript 2015: Use Let

1

4

0

1

Back to the Future...

  • New version of ECMAScript annually
    • ​ECMAScript 2016, 2017...etc
       
  • Features would appear in modern browsers quickly 
     
  • How to innovate continuously in front-end world by taking advantage of these new browser enhancement ... 

    But not worrying about the old browser?

Transpiler

  • Generated code is small, fast, readable, and compatible
     
  • Has hit maturity, transpilation trade-offs well-studied
     
  • Have to follow some guideline
     
  • Sound engineering decision to start using Babel + ECMAScript 2015
class Rectangle extends Shape {
    constructor (id, x, y, width, height) {
        super(id, x, y)
        this.width  = width
        this.height = height
    }
}
class Circle extends Shape {
    constructor (id, x, y, radius) {
        super(id, x, y)
        this.radius = radius
    }
}

WRITE ECMAScript 2015 CODE LIKE THIS

"use strict";

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _inherits(subClass, superClass) { 
    if (typeof superClass !== "function" && superClass !== null) {throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);} 

    subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); 

if (superClass) 
    Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; 
}

var Rectangle = (function (_Shape) {
    _inherits(Rectangle, _Shape);

    function Rectangle(id, x, y, width, height) {
        _classCallCheck(this, Rectangle);

        _Shape.call(this, id, x, y);
        this.width = width;
        this.height = height;
    }

    return Rectangle;
})(Shape);

var Circle = (function (_Shape2) {
    _inherits(Circle, _Shape2);

    function Circle(id, x, y, radius) {
        _classCallCheck(this, Circle);

        _Shape2.call(this, id, x, y);
        this.radius = radius;
    }

    return Circle;
})(Shape);

BABEL TRANSPILES YOUR CODE INTO THIS:

Browser

Standard

Transpiler

The Need for SOA

Frontend Scaling @ Yelp

  • Monolith architecture does not scale with the growth of the application & team
     
  • Ability to quickly ship code - maintaining iteration speed
     
  • Quality degrades as branch number increases 

Frontend Service with Styleguide

  • Yelp Styleguide  - a pre-established UI pattern documentation
     
  • Visual consistency across Yelp
     
  • Reduce technical debt with modular, reusable markup and styles  
     
  • Focus on designing and building engaging UI
     

  • Useful for cross-browser testing
     

  • Alive and always up-to-date

Frontend Service with Styleguide

  • SCSS
     
  • JavaScript
     
  • Images/Icon
     
  • Tests/Jenkins
     
  • Use bower to define dependencies  

i18n @ Coursera

Give your JavaScript the ability to speak many languages

i18n Automation Pipeline

1. Choose a library

2. Configure It

3. Extract strings from JavaScript

4. Find Translator

5. Determine the user's language

6. Broadcast language support

i18n Automation Pipeline

  • Challenges in Combating i18n pitfalls
     
  • Need the right tools for i18n automation
    • FormatJS + React Intl
    • i18n collaboration process with Transifex
    • pseudolocalization with pseudoloc
    • Jenkins
    • Grunt or Gulp
    • webpack module bundler
    • ESLint
       
  • Developer Education

Do amazing things with the right abstraction

Challenges

  • Building UI
     
    • JSP/PHP are template abstraction for Server Side rendering
       
    • Templates abstraction may not make sense for the view on Client Side

Let's Compare with AngularJS 1.x

<div ng-repeat="model in collection">
    {{model.name}}
</div>
collection.map(model => (
    <div>{model.name}</div>
))
<select name="month">
    <option>(01) January</option>
    <option>(02) February</option>
    ...
</select>
<select name="month">
    <option ng-repeat="month in months">
        ({{$index | padMonth}}) {{month}}
    </option>  
</select>
<select>
    {months.map((month, index) => (
        <option>({padMonth(index)}) {month}</option>
    ))}
</select>
Java Script Templates
Use vars in function scope Guess where vars come from
Use JavaScript methods like Array#map Invent our own DSL
Carry knowledge to next project Describe ourselves as
"X developers"

Challenges

  • Managing State
     
    • How do you go and reflect changes on the view?
       
    • Communicate that change to your app?
       
    • KVO (Object.oberve) is hard

Let's Compare with EmberJS 2.x

Person = Ember.Object.extend({
  // these will be supplied by `create`
  firstName: null,
  lastName: null,

  fullName: Ember.computed('firstName', 'lastName', function() {
    return `${this.get('firstName')} ${this.get('lastName')}`;
  }),

  fullNameChanged: Ember.observer('fullName', function() {
    // deal with the change
  })
});

var person = Person.create({
  firstName: 'Yehuda',
  lastName: 'Katz'
});

person.set('firstName', 'Brohuda'); // observer will fire
setState KVO
One object contains state Many objects contain state
Imperative, intent is obvious Behaviour depends on side effects
Easy to grasp Difficult to grasp

Challenges

  • Updating UI
     
    • Manage the update manually?
       
    • Manipulate DOM
       
    • Performance?

Let React manage the DOM update

Virtual DOM DOM
Describe what UI looks like Actually manipulate DOM
Framework handles optimization Optimize by hand
Easy to introduce new render targets Difficult to render to new targets

Reusable DataViz
with
React & D3

  • Data-Driven Documents :  A JavaScript library for manipulating documents based on data 
     

  • Bring data to life using HTML, SVG, and CSS. 
     

  • Modern way of building visulization

D3

Fine Print: 
BUT a month later, can't understand the code already...

elegant + sleek + awesome!

  • D3 is hard
     

  • Challeng to deal with the State

    • enter, update, exist

    • with too many dataset
       

  • A team of people working on ONE data visualization

D3

  • Turn every frame/state of visualization into function of data
     

  • Better than recalculating vectors before/after
     
  • Just draw the parts that was changed

Solution: Change Data Redraw

  • React: redraw for Web

    • Have render method with SVG and components
    • Let React perform the diff algorithm and redraw
    • Leverage FLUX architecture
    • Respond to state changes
    • Easy to understand

Solution: D3 + React

  • D3

    • Calculation / math / position

    • Define behaviours
       

  • Play Together

    • D3 generates layout and let React render with giving positions through property

    • Reuse component anywhere with different data

Solution: D3 + React

React Vs. MVC

  • Library Vs. Full Fledged Framework
     

  • React does not help you with

    • Application routing

    • Communicating with a server

    • Validating models

    • Injecting dependencies
       

  • Logic and markup are inextricably linked together VS. Template being the view in MVC

Summary

Area of Interests

  • SOA

  • i18n

  • Automation

  • Visualisation with D3

Summary

What People Use

  • ECMAScript 2015

  • Babel

  • Web Component building / testing

  • React advocates

    • Angular?

References

  • A lot of materials of the slides are consist of the content of the following talks:
    • David Greenspan's talk from "Upgrade your JavaScript to ES2015 (ES6)"
    • Leith's Sharing from How Coursera does i18n
    • Ken Struys's talk about "Scaling Engineering Teams with Frontend Services"
    • Michael Jackson's talk about React–Not Just Hype!
    • Swizec's talk about "REUSABLE DATAVIZ WITH
      REACT AND D3.JS"

Questions?

Appendicies

i18n Automation Pipeline

1. Choose a library

 

  • Polyglot.js
  • requirejs.i18n
  • homebrew

2. Configure it

 

  • Set the language and produce the build with Webpack

i18n Automation Pipeline

3. Extract strings from JavaScript

  • With each commit master branch
  • Automatically generate JSON files with strings extracted from JavaScript
    • React Intl (Format.js React integration)
    • yahoo/babel-plugin-react-intl
    • homebrew
> cat ./app/components/hello.js

let React = require('react');

module.exports = React.createClass({
  render() {
    return (
      <div>hello world</div>
    )
  }
})
> cat ./app/components/hello.js

let React = require('react');
// i18n! is a plugin connect _t to translations
let _t = require('i18n!app/i10n/hello');

module.exports = React.createClass({
  render() {
    return (
      // wrap string with _t()
      <div>{_t('hello wrold')}</div>
    )
  }
> cat ./app/l10n/jp/hello.js

{
  "hello world": "こんにちは世界"
}

i18n Automation Pipeline

4. Find Translator

5. Determine the user's language

  • selection - ask user to choose it
  • use "accept-language" header
  • geo IP lookup
  • Involve all of above to get it right

6. Broadcast language support

 

  • <html lang='en'>
  • Routing considerations
  • Use metadata for crawlers
Made with Slides.com