Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Creating Reusable UI Components with Ext JS

Mats Bryntse
December 13, 2017

Creating Reusable UI Components with Ext JS

My presentation at Sencha RAD Mix in Tokyo December 13, 2017

Mats Bryntse

December 13, 2017
Tweet

More Decks by Mats Bryntse

Other Decks in Programming

Transcript

  1. Intro | About me •Mats Bryntse, from Stockholm Sweden !

    •First saw Ext JS in 2007, fell in love with the grid ❤ •In 2009, I started Bryntum •We make UI components and dev tools
  2. Intro | Agenda Ext JS intro Architecture Error monitoring •

    Ext JS class system • Extending a class • Component model • Life cycle, constructor, destructor • Choose base class • Architecture • Mixins, plugins • Writing testable code • How to detect bugs in production • Recording session video • RootCause
  3. Intro | Background One of the great strengths of Ext

    JS: Mature reusable UI components.
  4. Class system | Ext classes •Legacy JS lacked real classes

    •Ext JS has its own class system •Dynamic loading •Classes defined as a String + properties
  5. Class system | Ext.define Ext.define("MyApp.FilterField", {
 extend : "Ext.form.TextField", requires

    : ["Ext.other.Class"],
 width : 150,
 … }); Before a class is defined, all dependencies are loaded
  6. Class system | Component template methods Ext.define(“My.app.FilterField", {
 extend :

    "Ext.form.TextField",
 
 initComponent : function() { … }, onRender : function() { … }, onDestroy : function() { … } });
  7. Component Architecture | Choosing a base class Non-UI classes should

    extend Ext.Base or Ext.util.Observable Ext.define("MyApp.SomeClass", {
 extend : “Ext.Base” // Or omit this });
  8. Component Architecture | Choosing a base class For custom UI

    classes, you have more choices: Ext.Component Ext.Panel Ext.Container <div> Foo </div>
  9. Component Architecture | Abstractions Use the right Ext JS abstraction

    level Native DOM Ext JS “DOM Core” Ext.Component HtmlElement, doc.getElementById JS API, Ext.Element, Ext.get Sizing, life cycle Ext.Container Layout, contain other components Ext.Panel Title, toolbars, buttons
  10. •If you’re building a complex UI component: •Break it down

    into smaller sub-components •Combine pieces to form a powerful component Component Architecture | Break down big components into pieces
  11. Choosing framework | Ext JS Classic Classic: * supports IE

    >=8 * more widgets * more mature (10+ yrs) * heavier DOM * slower than Modern
  12. Choosing framework | Ext JS Modern or… Modern: * supports

    IE >=11 * Uses modern CSS * Less DOM footprint * Faster than Classic * Touch friendly * Less widgets than classic
  13. Mixins & Plugins | Mixins •Mixins are just simple objects

    •Mixins make code reusable for classes •We use them extensively
  14. Mixins & Plugins | Mixins •Very simple to use! Ext.define(“My.Mixin”,

    {
 foo : “bar” });
 Ext.define(“My.awesome.Class”, {
 mixins : [“My.Mixin”] });

  15. Mixins & Plugins | Plugins •Works for any Ext.Component •Easy

    way to enable extra functionality for instances •Avoids class bloat, Ext grid is a great example •Ext JS grid has tons of “optional” features
  16. Mixins & Plugins | Plugins Row expander, cell editing, row

    editing, header drag drop, header resize, row drag drop…
  17. Mixins & Plugins | Plugins •By using mixins, the core

    part of the Grid stays manageable •If you don’t use feature X, Sencha Cmd will not include it
  18. Mixins & Plugins | Plugins Ext.define(“My.Plugin”, { extend : “Ext.AbstractPlugin”,


    init : function(component) {…} });
 new My.awesome.Class({
 plugins : [new My.Plugin()] });
 Definition: Usage:
  19. Tips & tricks | Best practices Stay on top of

    the public Ext JS API as much as possible Upgrade pains to be expected otherwise If you must override a private Ext JS method, document it At Bryntum, we detect private overrides through tests
  20. Tips & tricks | Containers are awesome Since Containers can

    Components: 
 You can put any Component into a tooltip!
  21. Tips & tricks | Testing Writing testable code Models &

    Stores are pure JS, not tied to DOM Very easy to test. Very fast. Views & controllers are much harder
  22. Finding production bugs | Not always easy Errors in production

    are sometimes logged, Often ignored or logs forgotten With huge JS code bases, we cannot ignore production errors
  23. Rounding up •Break your application into reusable Components •Test big

    components individually •Monitor application errors •Don’t rely on users reporting bugs