Past, Present and Future • Transpilers & Sourcemaps • Ext JS 7 Class system content - Modules - Classes & Mixins - Life-cycle - Goals for language and tools • The Road Ahead
Compatibility Ext.define works as before Existing code organization is supported Ext.require works as before callParent must be available Ext namespace is globally available ES2015 Class syntax can derive from any class Module-based structure import and export syntax is supported super calls must work (strict mode) Ext is scoped to its module
actually a superset of ECMAScript. Browsers and Node.js add more functionality through additional objects and methods, but the core of the language remains as defined in ECMAScript. ES2015/ES6: The Present!
go beyond “polyfills” by providing missing language syntax! • Transpilers are currently the only platforms that accept imports, exports and decorators • Transpilers allow us to future-proof our code (unblocking the language adoption curve) - No more “I have to develop code for the worst supported browsers” • (though, not everything can be fixed by tools) .babelrc! {! "presets": ["latest"]! }! How I can use tomorrow’s JavaScript today!
be compiled! • Superset of ES6/7/8! • Visibility! • Decorators! • Compile-time type checking! • Strong types => better code completion in IDEs, find usages! • Easier to maintain and refactor! • The preferred choice for Angular 2 apps, also works for React! • Some libraries “play well”, some don’t!
the original source code… - …not the ugly transpiler output! • Source Maps have been around since 2012 - This is great because they are widely supported • Source Maps are supported by: - Chrome, Firefox, Edge, Safari - IE11 (with Windows 8.1 Update) See: https://www.html5rocks.com/en/tutorials/developertools/sourcemaps/
export var abc = 'abc'; export default class Bar { // ... } New: ES2015/ES6 Modules • Modules are files • Modules execute in a private scope (not global) • Modules publish values using export • Modules can have one, unnamed “default” export value • Modules use import to acquire values exported by other modules • Modules are imported by path or name ./path/file.js import { abc } from '../path/file'; import Bar from '../path/file.js'; import Ext from '@extjs/kernel'; import { define } from '@extjs/kernel'; ./other/thing.js
hbox } from '@extjs/modern/layout'; import { Ext_Button } from '@extjs/modern'; New: Importing Components • Classes are exported in several ways: - By xtype - By alias family - By class name • These would be used where strings might be used today • These exports can be generated by the new build tool
T => { T.define(className, body); }; } @define('App.some.Thing', { alias: 'thing', text: 'Hello' }) class Thing extends Bar { } define('App.some.Thing', { alias: 'thing', text: 'Hello' })(Thing); New: Decorators • Decorators are functions that manipulate classes (or methods) • Decorators can accept arguments… - But must return a function to call as if no arguments were provided • The @decorator syntax is just a different way to call these functions • Decorators are currently a Stage 2 proposal (not yet standardized) https://github.com/tc39/proposals
this.x = 42; } } new Foo(42); let obj = {}; Foo.call(obj, 42); ES2015: Restrictions on constructor • A constructor can only be called with the new operator. • Calling a constructor with call() or apply() throws a TypeError.
from 'app/foo'; class Mixable extends Ext.Base { method (x) { return x * 42; } } @define({ mixins: [ Mixable ] }) class Thing extends Bar { method (x) { return 10 * this.mixins.mixable.method.call(this, x); } } @define({ extend: [ Mixable ] }) class OtherThing extends Bar { method (x) { return 10 * super.method(x); } } ES2015: Mixins • Mixins are classes (that extend Ext.Base) • Use @define to mix in the mixin(s) • Mixins will be able to act more like a true base - The extend directive accepts mixins - Calls to overlapping methods are handled in the super call
operator new - or Ext.create() or other factory • The native constructor is available to ES2015 classes - Not recommended in most cases • The construct method is available to all classes - The new name for the old constructor
Uses Google Closure Compiler • Supports much of the ES2015 syntax (http://kangax.github.io/compat-table/es6/) • Provides polyfills as well • Transpiling is optional • New compressor (replaces YUI) can process native ES2015 code