Aligning Ember.js with Web Standards

91
Aligning Ember with Web Standards EmberConf 2015

Transcript of Aligning Ember.js with Web Standards

Page 1: Aligning Ember.js with Web Standards

Aligning Ember withWeb Standards

EmberConf 2015

Page 2: Aligning Ember.js with Web Standards

@mixonic

Matthew Beale

201 Created

Page 3: Aligning Ember.js with Web Standards

The JavaScript standardizationprocess is about to change

#1

Page 4: Aligning Ember.js with Web Standards

STANDARDS PROCESS

Page 5: Aligning Ember.js with Web Standards

WHATWG + W3C

TC39 + Ecma International

Page 6: Aligning Ember.js with Web Standards

WHATWG + W3C

TC39 + Ecma International

DOMHTML Web Components XHR, Fetch

Promises for loops var, let, const classes

Page 7: Aligning Ember.js with Web Standards

WHATWG W3C

TC39 Ecma International

Page 8: Aligning Ember.js with Web Standards

WHATWG W3C

TC39 Ecma International

WORKING

GROUPSSTANDARDS GROUPS

Page 9: Aligning Ember.js with Web Standards

The plan at the time was to finish the specification this year and publish a snapshot of "HTML5" in 2012. However, shortly after that we realized that the demand for new features in HTML remained high, and so we would have to continue maintaining HTML and adding features to it before we could call “HTML5" complete, and as a result we moved to a new development model, where the technology is not versioned and instead we just have a living document that defines the technology as it evolves.

Ian Hickson, 2011

Page 10: Aligning Ember.js with Web Standards

“Living Standard”

Page 11: Aligning Ember.js with Web Standards

ES3

Page 12: Aligning Ember.js with Web Standards

ES4

Page 13: Aligning Ember.js with Web Standards

ES5

Page 14: Aligning Ember.js with Web Standards

ES6

Page 15: Aligning Ember.js with Web Standards

ES6

Page 16: Aligning Ember.js with Web Standards

ES2015

Page 17: Aligning Ember.js with Web Standards

“ES2015” signifies a newstandardization process

Page 18: Aligning Ember.js with Web Standards

github.com/ tc39/ecma262

Page 19: Aligning Ember.js with Web Standards

0. Strawman 1. Proposal 2. Draft 3. Candidate 4. Finished

Page 20: Aligning Ember.js with Web Standards

0. Strawman 1. Proposal -> Polyfills 2. Draft -> Experimental 3. Candidate -> Compliant 4. Finished -> Shipping

Page 21: Aligning Ember.js with Web Standards

a “Living Web”

Page 22: Aligning Ember.js with Web Standards

Aligning with standardsis not a one time event

Page 23: Aligning Ember.js with Web Standards

Aligning with standardsis not free

Page 24: Aligning Ember.js with Web Standards

Why standards?

Page 25: Aligning Ember.js with Web Standards

Productivity

Page 26: Aligning Ember.js with Web Standards

1. are portable 2. reflect best practices 3. endure

Standards…

Page 27: Aligning Ember.js with Web Standards

Participants win

Page 28: Aligning Ember.js with Web Standards

Design

Polyfill, demo

Real world use

Learning

Page 29: Aligning Ember.js with Web Standards

Design

Polyfill, demo

Real world use

Learning

Page 30: Aligning Ember.js with Web Standards

2. Transpilers are here to stay

Page 31: Aligning Ember.js with Web Standards

This is not the first time features have been added to JavaScript

Page 32: Aligning Ember.js with Web Standards

ES3 -> ES5

Page 33: Aligning Ember.js with Web Standards

HTML5

Page 34: Aligning Ember.js with Web Standards

“Polyfill”- Remy Sharp

Page 35: Aligning Ember.js with Web Standards

ES5 -> ES2015

Page 36: Aligning Ember.js with Web Standards

var map = new Map(); map.set('key', 'value'); var value = map.get('key');

Page 37: Aligning Ember.js with Web Standards

var map = new Map(); map.set('key', 'value'); var value = map.get('key');

Page 38: Aligning Ember.js with Web Standards

1 var delayed = new Promise( 2 function(resolve, reject){ 3 setTimeout(resolve, 100); 4 } 5 ); 6 delayed.then(function(){ 7 console.log('HTMLBars'); 8 });

Page 39: Aligning Ember.js with Web Standards

1 var delayed = new Promise( 2 function(resolve, reject){ 3 setTimeout(resolve, 100); 4 } 5 ); 6 delayed.then(function(){ 7 console.log('HTMLBars'); 8 });

Page 40: Aligning Ember.js with Web Standards

1 var loggingObject = new Proxy({}, { 2 get(target, propertyKey, receiver) { 3 console.log('GET '+propertyKey); 4 return target[propertyKey]; 5 } 6 }); 7 8 loggingObject.whatever; // Logs: GET whatever

Page 41: Aligning Ember.js with Web Standards

1 var loggingObject = new Proxy({}, { 2 get(target, propertyKey, receiver) { 3 console.log('GET '+propertyKey); 4 return target[propertyKey]; 5 } 6 }); 7 8 loggingObject.whatever; // Logs: GET whatever

Page 42: Aligning Ember.js with Web Standards

1 var runner = { 2 count: 0, 3 call: function() { 4 setTimeout(() => { 5 console.log(this.count++); 6 }, 100); 7 } 8 }; 9 10 runner.call();

Page 43: Aligning Ember.js with Web Standards

1 var runner = { 2 count: 0, 3 call: function() { 4 setTimeout(() => { 5 console.log(this.count++); 6 }, 100); 7 } 8 }; 9 10 runner.call();

Page 44: Aligning Ember.js with Web Standards
Page 45: Aligning Ember.js with Web Standards

“Babel will turn your ES6+ code into ES5 friendly code, so you can start using it right

now without waiting for browser support.”

Page 46: Aligning Ember.js with Web Standards

1 "use strict"; 2 3 var runner = { 4 count: 0, 5 call: function call() { 6 var _this = this; 7 8 setTimeout(function () { 9 console.log(_this.count++); 10 }, 100); 11 } 12 }; 13 14 runner.call();

1 var runner = { 2 count: 0, 3 call: function() { 4 setTimeout(() => { 5 console.log(this.count++); 6 }, 100); 7 } 8 }; 9 10 runner.call();

Page 47: Aligning Ember.js with Web Standards

1. syntax (fat arrow, let) 2. APIs (Map, Set) 3. not everything

Enables new…

Page 48: Aligning Ember.js with Web Standards

“Not born to die”

- James Kyle

Page 49: Aligning Ember.js with Web Standards

kangax.github.io/compat-table/es6

Page 50: Aligning Ember.js with Web Standards

ES2015 feature: Uint8Array

Page 51: Aligning Ember.js with Web Standards

ES2015 feature: Uint8Array

IE10+

Page 52: Aligning Ember.js with Web Standards

ES2015 feature: Spread Operator

var list = [1,2,3]; Math.max(...list);

Page 53: Aligning Ember.js with Web Standards

ES2015 feature: Spread Operator

var list = [1,2,3]; Math.max(...list);

Firefox only

Page 54: Aligning Ember.js with Web Standards

ES2015 feature: Block-level function scope1 "use strict"; 2 function a(){ return 1; } 3 { 4 function a(){ return 2; } 5 }; 6 7 a() === 1;

Page 55: Aligning Ember.js with Web Standards

ES2015 feature: Block-level function scope

Chrome only

1 "use strict"; 2 function a(){ return 1; } 3 { 4 function a(){ return 2; } 5 }; 6 7 a() === 1;

Page 56: Aligning Ember.js with Web Standards

The target platforms of Babelare inconsistent

Page 57: Aligning Ember.js with Web Standards

Babel

Chrome

Firefox

Page 58: Aligning Ember.js with Web Standards

The platforms your application supports will drive what features are transpiled.

Page 59: Aligning Ember.js with Web Standards

Targeting platforms can be done by tweaking the enabled

features list.

Page 60: Aligning Ember.js with Web Standards

IMO a mapping to platforms would be better.

Page 61: Aligning Ember.js with Web Standards

What you transpile today,you will blacklist in two years

Page 62: Aligning Ember.js with Web Standards

Yes, you will be transpilingin two years

Page 63: Aligning Ember.js with Web Standards

Yes, you will be transpilingin five years

Page 64: Aligning Ember.js with Web Standards

Yes, you will be transpilingin ?!!?!?! years

Page 65: Aligning Ember.js with Web Standards

Transpilers are here to stay

Page 66: Aligning Ember.js with Web Standards

3. Aligning Ember’s object model

Page 67: Aligning Ember.js with Web Standards

1. stable 2. a good pattern 3. implemented correctly 4. implemented performantly

Is this feature:

Page 68: Aligning Ember.js with Web Standards

ES Classes

Page 69: Aligning Ember.js with Web Standards

1. class 2. extend 3. super

Three new tools:

Page 70: Aligning Ember.js with Web Standards

1 class Car { 2 constructor(gearCount){ 3 this.gearCount = gearCount; 4 } 5 6 toString() { 7 return `A car with: ${gearCount} gears`; 8 } 9 } 10 11 var car = new Car(3); 12 car.toString(); // A car with 3 gears

Page 71: Aligning Ember.js with Web Standards

1 class Vehicle { 2 constructor(gearCount){ 3 this.gearCount = gearCount; 4 } 5 } 6 class Car extends Vehicle { 7 toString() { 8 return `A car with: ${this.gearCount} gears`; 9 } 10 } 11 12 var car = new Car(3); 13 car.toString(); // A car with 3 gears

Page 72: Aligning Ember.js with Web Standards

1 class Vehicle { 2 constructor(gearCount){ 3 this.gearCount = gearCount; 4 } 5 toString() { 6 return `${this.gearCount} gears`; 7 } 8 } 9 class Car extends Vehicle { 10 toString() { 11 return `A car with: ${super.toString()}`; 12 } 13 }

Page 73: Aligning Ember.js with Web Standards

1 class Vehicle { 2 constructor(gearCount){ 3 this.gearCount = gearCount; 4 } 5 toString() { 6 return `${this.gearCount} gears`; 7 } 8 } 9 class Car extends Vehicle { 10 constructor(...args) { 11 console.log(`Created with ${args[0]}`); 12 super(args); 13 } 14 toString() { 15 return `A car with: ${super.toString()}`; 16 } 17 }

Page 74: Aligning Ember.js with Web Standards

1. new syntax 2. super semantics change 3. mixins

gotachas:

Page 75: Aligning Ember.js with Web Standards

4. setUnknownProperty 5. merged/concat properties 6. transpiler ouput?!

more gotachas:

Page 76: Aligning Ember.js with Web Standards

7. only halfway there

Page 77: Aligning Ember.js with Web Standards

7. only halfway thereES Decorators

Page 78: Aligning Ember.js with Web Standards

1 class Car { 2 +attr('gearsCount') 3 +attr('wheelsCount') 4 5 constructor(gearsCount) { 6 this.gearsCount = gearsCount; 7 } 8 9 -dependsOn('gearsCount') 10 get isModern() { 11 return this.gearsCount > 3; 12 } 13 } 14 15 var car = new Car(3); 16 car.isModern; // false

Page 79: Aligning Ember.js with Web Standards

Aligning

Page 80: Aligning Ember.js with Web Standards

1. provide legacy wrapper 2. use syntax as a carrot 3. private use can start sooner

strategy:

Page 81: Aligning Ember.js with Web Standards

1 import EmberObject from "ember/object"; 2 import computed from "ember/computed"; 3 4 class Car extends EmberObject.extend({ 5 6 init(gearsCount) { 7 this._super(...arguments); 8 this.set('gearsCount', gearsCount); 9 }, 10 11 isModern: computed('gearsCount', function(){ 12 return this.get('gearsCount') > 3; 13 }) 14 }); 15 16 export default Car;

Page 82: Aligning Ember.js with Web Standards

1 import EmberObject from "ember/object"; 2 3 class Car extends EmberObject { 4 5 constructor(gearsCount) { 6 super(...arguments); 7 this.gearsCount = gearsCount; 8 } 9 10 get isModern() { 11 return this.gearsCount > 3; 12 } 13 } 14 15 export default Car;

Page 83: Aligning Ember.js with Web Standards

1 import Component from "ember/component"; 2 3 class Car extends Component { 4 5 get isModern() { 6 return this.attrs.gearsCount > 3; 7 } 8 } 9 10 export default Car;

Page 84: Aligning Ember.js with Web Standards

This is a story of Ember 2.0 -> 3.0

Page 85: Aligning Ember.js with Web Standards

Reminder: Standards are a two-way street

Page 86: Aligning Ember.js with Web Standards

ONE MORE THING

Page 87: Aligning Ember.js with Web Standards
Page 88: Aligning Ember.js with Web Standards

201-created.com/ember-community-survey-2015

@ClimbingNarc

Page 89: Aligning Ember.js with Web Standards

201-created.com/ember-community-survey-2015

Page 90: Aligning Ember.js with Web Standards

201-created.com/ember-community-survey-2015

Page 91: Aligning Ember.js with Web Standards

Thank you, you wonderful people.

@mixonic