SlideShare ist ein Scribd-Unternehmen logo
1 von 46
Downloaden Sie, um offline zu lesen
Wednesday, November 2, 11
The Sencha Class System
                            Jacky Nguyen, Sencha



             jacky@sencha.com                      @nktpro




Wednesday, November 2, 11
Best User Experience

Wednesday, November 2, 11
Better
                   Developer Experience




Wednesday, November 2, 11
Class System

                            Event System

                            Data Package

                            Widgets & Layouts

                            ...




Wednesday, November 2, 11
Prototype-based        Class-based




                                               =
                                                   Predictability
                               Sencha
                            Class System
                                 Flexibility       Programmer
                                                    Familiarity




Wednesday, November 2, 11
✓Consistent
                                      ✓Familiar
                            Learn


                                      ✓DRY
                                      ✓Debuggable
                            Develop   ✓Testable



                                      ✓Automatic dependency resolution
                            Deploy




                 Better Developer Experience
Wednesday, November 2, 11
Coding Convention




Wednesday, November 2, 11
Namespacing & Code Organization

           1. OrganizationName.group[.subgroup].ClassName
           2. One class per file
           3. File name matches class name


           ‣ Ext.chart.Label     -> Ext/chart/Label.js
           ‣ Ext.data.writer.Xml -> Ext/data/writer/Xml.js
           ‣ MyApp.field.Password -> MyApp/field/Password.js




Wednesday, November 2, 11
Class Definition




Wednesday, November 2, 11
The Good Old Ext.extend()
       Ext.ns('My.sample');

       My.sample.Person = Ext.extend(Object, {
         constructor: function(name) {
            this.name = name;
         },

             walk: function(steps) {
               alert(this.name + ' is walking ' + steps + ' steps');
             }
       });




Wednesday, November 2, 11
Introducing Ext.define()
      Ext.define('My.sample.Person', {
          constructor: function(name) {
              this.name = name;
          },

                walk: function(steps) {
                    alert(this.name + ' is walking ' + steps + ' steps');
                }
      });


      var tommy = new My.sample.Developer('Tommy');
      tommy.walk(5); // alerts 'Tommy is walking 5 steps'




Wednesday, November 2, 11
Ext.define() vs Ext.extend()
        Ext.define('My.sample.Person', {
            constructor: function(name) {
                this.name = name;
            },

                 walk: function(steps) {
                     alert(this.name + ' is walking ' + steps + ' steps');
                 }
        });



        ‣Class definition is more than just inheritance
        ‣Automatic namespace allocation
        ‣Classes are now aware of their own names
        ‣Asynchronous vs. synchronous

Wednesday, November 2, 11
Inheritance




Wednesday, November 2, 11
Inheritance
    Ext.define('My.sample.Person', {
        constructor: function(name) {
            this.name = name;
        },
        walk: function(steps) {
            alert(this.name + ' is walking ' + steps + ' steps');
        }
    });

    Ext.define('My.sample.Developer', {
        extend: 'My.sample.Person',
        code: function(language) {
            alert(this.name + ' is coding in ' + language);
        }
    });


    var tommy = new My.sample.Developer('Tommy');
    tommy.walk(5);            // 'Tommy is walking 5 steps
    tommy.code('JavaScript'); // 'Tommy is coding in JavaScript'

Wednesday, November 2, 11
Inheritance
    Ext.define('My.sample.Developer', {
        extend: 'My.sample.Person',
        code: function(language) { /* ... */ },
        walk: function(steps) {
            if (steps > 100) {
                alert('Are you serious? That's too far! I'm lazy...');
            }
            else {
                            My.sample.Developer.superclass.walk.apply(this, arguments);
                            this.callParent(arguments);
                     }
            }
    });



    var tommy = new My.sample.Developer('Tommy');
    tommy.walk(50); // alerts "Tommy is walking 50 steps"
    tommy.walk(101); // alerts "Are you serious? That's too far! I'm
                        lazy..."




Wednesday, November 2, 11
Mixins




Wednesday, November 2, 11
Mixins


                                 Sing                      Performer




                            Play Instruments               Composer




                            Compose Songs               Singer-songwriter




Wednesday, November 2, 11
Mixins
         Ext.define('My.ability.Sing', {
             sing: function(songName) {
                 alert("I'm singing " + songName);
             }
         });


         Ext.define('My.ability.PlayInstruments', {
             play: function(instrument) {
                 alert("I'm playing " + instrument);
             }
         });


         Ext.define('My.ability.ComposeSongs', {
             compose: function(songName) {
                 alert("I'm composing " + songName);
             }
         });



Wednesday, November 2, 11
Mixins
       Ext.define('My.sample.Performer', {
           extend: 'My.sample.Person',
           mixins: {
               canSing: 'My.ability.Sing',
               canPlay: 'My.ability.PlayInstruments'
           }
       });


       Ext.define('My.sample.Composer', {
           extend: 'My.sample.Person',
           mixins: {
               canPlay   : 'My.ability.PlayInstruments',
               canCompose: 'My.ability.ComposeSongs'
           }
       });


       Ext.define('My.sample.SingerSongwriter', {
           extend: 'My.sample.Person',
           mixins: {
               canSing   : 'My.ability.Sing',
               canPlay   : 'My.ability.PlayInstruments',
               canCompose: 'My.ability.ComposeSongs'
           }
       });
Wednesday, November 2, 11
Mixins
    Ext.define('My.sample.Performer', {
        extend: 'My.sample.Person',
        mixins: {                          prototype        of
            canSing: 'My.ability.Sing',
            canPlay: 'My.ability.PlayInstruments'
        },

            sing: function() {
                alert("Here we go!");

                     this.mixins.canSing.sing.call(this);

                     alert("I'm done singing!");
            }
    });


    var jamie = new My.sample.Performer("Jamie");
    jamie.sing("November Rain"); // alerts "Here we go!"
                                 // alerts "I'm singing November Rain"
                                 // alerts "I'm done singing!";


Wednesday, November 2, 11
Dependency
                            Management




Wednesday, November 2, 11
Dependency Management
       <!-- ... -->
       <head>
           <!-- ... -->
                 <script src="ext.js"></script>
                         src="ext-all-debug.js"></script>



                 <script    src="My/sample/Person.js"></script>
                 <script    src="My/ability/PlayInstruments.js"></script>
                            src="My/sample/Location.js"></script>
                 <script    src="My/ability/Sing.js"></script>
                            src="My/sample/Developer.js"></script>
                 <script    src="My/sample/Performer.js"></script>
           <script>
               var tommy = new My.sample.Developer('Tommy'); 'Tommy');
                           Ext.create('My.sample.Developer',
               var jamie = new My.sample.Performer('Jamie'); 'Jamie');
                           Ext.create('My.sample.Performer',
           </script>
       </head>
       <!-- ... -->



Wednesday, November 2, 11
Dependency Management
       <!-- ... -->
       <head>
           <!-- ... -->
           <script src="ext.js"></script>
           <script>
               Ext.require([
                    'My.sample.Developer',
                    'My.sample.Performer'
               ]);

               Ext.onReady(function() {
                    var tommy = new My.sample.Developer('Tommy');
                    var jamie = new My.sample.Performer('Jamie');
               });
           </script>
       </head>
       <!-- ... -->




Wednesday, November 2, 11
Config




Wednesday, November 2, 11
Config
      Ext.define('My.sample.Person', {
          name: 'Anonymous',
          age: 0,
          gender: 'Male',

                constructor: function(config) {
                    config = config || {};

                            Ext.apply(this, config);
                }
      });


      var robert = new My.sample.Person({
          name: 'Robert',
          age: 21
      });




Wednesday, November 2, 11
Config
      Ext.define('My.sample.Person', {
          name: 'Anonymous',
          age: 0,
          gender: 'Male',

               constructor: function(config) {
                   if (Ext.isObject(config)) {
                       if (config.hasOwnProperty('name')) {
                           this.name = config.name;
                       }
                       if (config.hasOwnProperty('age')) {
                           this.age = config.age;
                       }
                       if (config.hasOwnProperty('gender')) {
                           this.gender = config.gender;
                       }
                   }
               }
      });

Wednesday, November 2, 11
Config
      Ext.define('My.sample.Person', {
          name: 'Anonymous',
          age: 0,
          gender: 'Male',

               constructor: function(config) {
                   if (Ext.isObject(config)) {
                       if (config.hasOwnProperty('name')) {
                           this.setName(config.name);
                       }
                       if (config.hasOwnProperty('age')) {
                           this.setAge(config.age);
                       }
                       if (config.hasOwnProperty('gender')) {
                           this.setGender(config.gender);
                       }
                   }
               },
      });

Wednesday, November 2, 11
setName: function(name) {
                    this.name = name;
                    return this;
                },
                getName: function() {
                    return this.name;
                },

                setAge: function(age) {
                    this.age = age;
                    return this;
                },
                getAge: function() {
                    return this.age;
                },

                setGender: function(gender) {
                    this.gender = gender;
                    return this;
                },
                getGender: function() {
                    return this.gender;
                }
Wednesday, November 2, 11
Config
      Ext.define('My.sample.Person', {
          config: {
              name: 'Anonymous',
              age: 0,
              gender: 'Male'
          },

               constructor: function(config) {
                   this.initConfig(config);
               }
      });


      var robert = new My.sample.Person({
          name: 'Robert',
          age: 21
      });

      robert.setName('Rob');
      alert(robert.getAge()); // alerts '21'
      robert.setAge(22);
      alert(robert.getAge()); // alerts '22'
Wednesday, November 2, 11
Config: Deep Merging
    Ext.define('My.sample.Developer', {
        extend: My.sample.Person,
        config: {
            level: 'Junior',
            location: {
                city: 'Unknown', state: 'Unknown', country: 'Unknown'
            }
        }
    });


    var edward = new My.sample.Developer({
        age: 26,
        level: 'Senior',
        location: { city: 'Palo Alto', state: 'CA', country: 'USA' }
    });

    edward.setName('Edward');
    alert(edward.getLocation().city);   // alerts 'Palo Alto'


Wednesday, November 2, 11
Config: Setter’s Process
                                     ✓Validation
                                     ✓Filtering
                            Before   ✓Transformation



                                     ✓Actual assignment
                             Set


                                     ✓Notification
                                     ✓Updating dependencies
                            After




Wednesday, November 2, 11
Config: Magic Methods
          getFoo()
                              return this.foo

          setFoo()

        Before                processedValue = applyFoo(newValue, oldValue)



            Set               this.foo = processedValue



           After              updateFoo(processedValue, oldValue)


Wednesday, November 2, 11
Config
    Ext.define('My.sample.Person', {
        /* ... */
        applyAge: function(age) {
            if (typeof age != 'number' || age < 0) {
                alert("Invalid age, must be a positive number");
                return;
            }
            return age;
        },
        updateAge: function(newAge, oldAge) {
            alert("Age has changed from " + oldAge + " to " + newAge);
        }
    });

    var aaron = new My.sample.Person({
        name: 'Aaron',
        age: -100
    }); // alerts "Invalid age, must be a positive number"

    alert(aaron.getAge());   // alerts 0
    alert(aaron.setAge(35)); // alerts "Age has changed from 0 to 35"
    alert(aaron.getAge());   // alerts 35
Wednesday, November 2, 11
Dependency Injection
                     with Ext.factory()




Wednesday, November 2, 11
Dependency Injection
  Ext.define('My.sample.Location', {
      config: {
          city: 'Unknown',
          state: 'CA',
          country: 'USA'
      }
  });


  var nicolas = new My.sample.Developer({
      location: { city: 'Palo Alto' }
  });

  alert(nicolas.getLocation() instanceof My.sample.Location); //alerts true
  alert(nicolas.getLocation().getCity()); // alerts 'Palo Alto'


  var nicolas = new My.sample.Developer({
      location: new My.sample.Location({ city: 'Austin', state: 'TX' })
  });

  alert(nicolas.getLocation().getState()); // alerts 'TX'

Wednesday, November 2, 11
Dependency Injection
      nicolas.setLocation({
          city: 'Austin'
      }); // nicolas.getLocation().setCity('Austin');

      nicolas.setLocation(new My.sample.Location({
           city: 'Austin',
           state: 'TX'
      }));

      nicolas.setLocation(new My.sample.DetailedLocation({
           longitude: -122.18235,
           latitude: 37.44923
      }));




Wednesday, November 2, 11
Ext.factory()
      Ext.define('My.sample.Developer', {
          extend: 'My.sample.Person',

               config: {
                   level: 'Junior',
                   location: {}
               },

               applyLocation: function(location, currentLocation) {
                   return Ext.factory(
                       location, My.sample.Location, currentLocation
                   );
               }
      });                   given value from setLocation()
                                               default Class   existing instance




Wednesday, November 2, 11
Debugging




Wednesday, November 2, 11
Debugging: Nightmare




Wednesday, November 2, 11
Debugging: Dream Comes True




Wednesday, November 2, 11
Debugging: Dream Comes True




Wednesday, November 2, 11
Deployment




Wednesday, November 2, 11
Deployment

      Ext.Loader.history === [
          'My.sample.Person',
          'My.sample.Location',
          'My.sample.Developer',
          'My.ability.Sing',
          'My.ability.PlayInstruments',
          'My.ability.ComposeSongs',
          'My.sample.Performer',
                                          Concatenate   Minify   app.js
          'My.sample.Composer',
          'My.sample.SingerSongwriter',
          /* ... */
      ];




                   http://www.sencha.com/products/sdk-tools

Wednesday, November 2, 11
Summary




Wednesday, November 2, 11
Thank
                             you!
Wednesday, November 2, 11

Weitere ähnliche Inhalte

Mehr von Sencha

Sencha Roadshow 2017: Modernizing the Ext JS Class System and Tooling
Sencha Roadshow 2017: Modernizing the Ext JS Class System and ToolingSencha Roadshow 2017: Modernizing the Ext JS Class System and Tooling
Sencha Roadshow 2017: Modernizing the Ext JS Class System and ToolingSencha
 
Sencha Roadshow 2017: Sencha Best Practices: Coworkee App
Sencha Roadshow 2017: Sencha Best Practices: Coworkee App Sencha Roadshow 2017: Sencha Best Practices: Coworkee App
Sencha Roadshow 2017: Sencha Best Practices: Coworkee App Sencha
 
Sencha Roadshow 2017: Mobile First or Desktop First
Sencha Roadshow 2017: Mobile First or Desktop FirstSencha Roadshow 2017: Mobile First or Desktop First
Sencha Roadshow 2017: Mobile First or Desktop FirstSencha
 
Sencha Roadshow 2017: Innovations in Ext JS 6.5 and Beyond
Sencha Roadshow 2017: Innovations in Ext JS 6.5 and BeyondSencha Roadshow 2017: Innovations in Ext JS 6.5 and Beyond
Sencha Roadshow 2017: Innovations in Ext JS 6.5 and BeyondSencha
 
Leveraging React and GraphQL to Create a Performant, Scalable Data Grid
Leveraging React and GraphQL to Create a Performant, Scalable Data GridLeveraging React and GraphQL to Create a Performant, Scalable Data Grid
Leveraging React and GraphQL to Create a Performant, Scalable Data GridSencha
 
Learn Key Insights from The State of Web Application Testing Research Report
Learn Key Insights from The State of Web Application Testing Research ReportLearn Key Insights from The State of Web Application Testing Research Report
Learn Key Insights from The State of Web Application Testing Research ReportSencha
 
Introducing ExtReact: Adding Powerful Sencha Components to React Apps
Introducing ExtReact: Adding Powerful Sencha Components to React AppsIntroducing ExtReact: Adding Powerful Sencha Components to React Apps
Introducing ExtReact: Adding Powerful Sencha Components to React AppsSencha
 
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSencha
 
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...Sencha
 
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...Sencha
 
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web AppsSenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web AppsSencha
 
Ext JS Architecture Best Practices - Mitchell Simeons
Ext JS Architecture Best Practices - Mitchell SimeonsExt JS Architecture Best Practices - Mitchell Simeons
Ext JS Architecture Best Practices - Mitchell SimeonsSencha
 
SenchaCon 2016: Mobile First? Desktop First? Or Should you Think Universal Ap...
SenchaCon 2016: Mobile First? Desktop First? Or Should you Think Universal Ap...SenchaCon 2016: Mobile First? Desktop First? Or Should you Think Universal Ap...
SenchaCon 2016: Mobile First? Desktop First? Or Should you Think Universal Ap...Sencha
 
Building Ext JS Using HATEOAS - Jeff Stano
Building Ext JS Using HATEOAS - Jeff StanoBuilding Ext JS Using HATEOAS - Jeff Stano
Building Ext JS Using HATEOAS - Jeff StanoSencha
 
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...Sencha
 
SenchaCon 2016: Developing and Delivering Quality Code, Frequently - Neil Manvar
SenchaCon 2016: Developing and Delivering Quality Code, Frequently - Neil ManvarSenchaCon 2016: Developing and Delivering Quality Code, Frequently - Neil Manvar
SenchaCon 2016: Developing and Delivering Quality Code, Frequently - Neil ManvarSencha
 
SenchaCon 2016: Creating a Flexible and Usable Industry Specific Solution - D...
SenchaCon 2016: Creating a Flexible and Usable Industry Specific Solution - D...SenchaCon 2016: Creating a Flexible and Usable Industry Specific Solution - D...
SenchaCon 2016: Creating a Flexible and Usable Industry Specific Solution - D...Sencha
 
SenchaCon 2016: JavaScript is Great but Stop Writing It - Rory Hardy
SenchaCon 2016: JavaScript is Great but Stop Writing It - Rory HardySenchaCon 2016: JavaScript is Great but Stop Writing It - Rory Hardy
SenchaCon 2016: JavaScript is Great but Stop Writing It - Rory HardySencha
 
SenchaCon 2016: Accessibility, Teamwork & Ext JS: A Customer Success Story - ...
SenchaCon 2016: Accessibility, Teamwork & Ext JS: A Customer Success Story - ...SenchaCon 2016: Accessibility, Teamwork & Ext JS: A Customer Success Story - ...
SenchaCon 2016: Accessibility, Teamwork & Ext JS: A Customer Success Story - ...Sencha
 
SenchaCon 2016: Using Ext JS 6 for Cross-Platform Development on Mobile - And...
SenchaCon 2016: Using Ext JS 6 for Cross-Platform Development on Mobile - And...SenchaCon 2016: Using Ext JS 6 for Cross-Platform Development on Mobile - And...
SenchaCon 2016: Using Ext JS 6 for Cross-Platform Development on Mobile - And...Sencha
 

Mehr von Sencha (20)

Sencha Roadshow 2017: Modernizing the Ext JS Class System and Tooling
Sencha Roadshow 2017: Modernizing the Ext JS Class System and ToolingSencha Roadshow 2017: Modernizing the Ext JS Class System and Tooling
Sencha Roadshow 2017: Modernizing the Ext JS Class System and Tooling
 
Sencha Roadshow 2017: Sencha Best Practices: Coworkee App
Sencha Roadshow 2017: Sencha Best Practices: Coworkee App Sencha Roadshow 2017: Sencha Best Practices: Coworkee App
Sencha Roadshow 2017: Sencha Best Practices: Coworkee App
 
Sencha Roadshow 2017: Mobile First or Desktop First
Sencha Roadshow 2017: Mobile First or Desktop FirstSencha Roadshow 2017: Mobile First or Desktop First
Sencha Roadshow 2017: Mobile First or Desktop First
 
Sencha Roadshow 2017: Innovations in Ext JS 6.5 and Beyond
Sencha Roadshow 2017: Innovations in Ext JS 6.5 and BeyondSencha Roadshow 2017: Innovations in Ext JS 6.5 and Beyond
Sencha Roadshow 2017: Innovations in Ext JS 6.5 and Beyond
 
Leveraging React and GraphQL to Create a Performant, Scalable Data Grid
Leveraging React and GraphQL to Create a Performant, Scalable Data GridLeveraging React and GraphQL to Create a Performant, Scalable Data Grid
Leveraging React and GraphQL to Create a Performant, Scalable Data Grid
 
Learn Key Insights from The State of Web Application Testing Research Report
Learn Key Insights from The State of Web Application Testing Research ReportLearn Key Insights from The State of Web Application Testing Research Report
Learn Key Insights from The State of Web Application Testing Research Report
 
Introducing ExtReact: Adding Powerful Sencha Components to React Apps
Introducing ExtReact: Adding Powerful Sencha Components to React AppsIntroducing ExtReact: Adding Powerful Sencha Components to React Apps
Introducing ExtReact: Adding Powerful Sencha Components to React Apps
 
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
 
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
SenchaCon 2016: Add Magic to Your Ext JS Apps with D3 Visualizations - Vitaly...
 
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...
SenchaCon 2016: LinkRest - Modern RESTful API Framework for Ext JS Apps - Rou...
 
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web AppsSenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
SenchaCon 2016: Expect the Unexpected - Dealing with Errors in Web Apps
 
Ext JS Architecture Best Practices - Mitchell Simeons
Ext JS Architecture Best Practices - Mitchell SimeonsExt JS Architecture Best Practices - Mitchell Simeons
Ext JS Architecture Best Practices - Mitchell Simeons
 
SenchaCon 2016: Mobile First? Desktop First? Or Should you Think Universal Ap...
SenchaCon 2016: Mobile First? Desktop First? Or Should you Think Universal Ap...SenchaCon 2016: Mobile First? Desktop First? Or Should you Think Universal Ap...
SenchaCon 2016: Mobile First? Desktop First? Or Should you Think Universal Ap...
 
Building Ext JS Using HATEOAS - Jeff Stano
Building Ext JS Using HATEOAS - Jeff StanoBuilding Ext JS Using HATEOAS - Jeff Stano
Building Ext JS Using HATEOAS - Jeff Stano
 
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
SenchaCon 2016: Improve Workflow Driven Applications with Ext JS Draw Package...
 
SenchaCon 2016: Developing and Delivering Quality Code, Frequently - Neil Manvar
SenchaCon 2016: Developing and Delivering Quality Code, Frequently - Neil ManvarSenchaCon 2016: Developing and Delivering Quality Code, Frequently - Neil Manvar
SenchaCon 2016: Developing and Delivering Quality Code, Frequently - Neil Manvar
 
SenchaCon 2016: Creating a Flexible and Usable Industry Specific Solution - D...
SenchaCon 2016: Creating a Flexible and Usable Industry Specific Solution - D...SenchaCon 2016: Creating a Flexible and Usable Industry Specific Solution - D...
SenchaCon 2016: Creating a Flexible and Usable Industry Specific Solution - D...
 
SenchaCon 2016: JavaScript is Great but Stop Writing It - Rory Hardy
SenchaCon 2016: JavaScript is Great but Stop Writing It - Rory HardySenchaCon 2016: JavaScript is Great but Stop Writing It - Rory Hardy
SenchaCon 2016: JavaScript is Great but Stop Writing It - Rory Hardy
 
SenchaCon 2016: Accessibility, Teamwork & Ext JS: A Customer Success Story - ...
SenchaCon 2016: Accessibility, Teamwork & Ext JS: A Customer Success Story - ...SenchaCon 2016: Accessibility, Teamwork & Ext JS: A Customer Success Story - ...
SenchaCon 2016: Accessibility, Teamwork & Ext JS: A Customer Success Story - ...
 
SenchaCon 2016: Using Ext JS 6 for Cross-Platform Development on Mobile - And...
SenchaCon 2016: Using Ext JS 6 for Cross-Platform Development on Mobile - And...SenchaCon 2016: Using Ext JS 6 for Cross-Platform Development on Mobile - And...
SenchaCon 2016: Using Ext JS 6 for Cross-Platform Development on Mobile - And...
 

Kürzlich hochgeladen

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024The Digital Insurer
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024SynarionITSolutions
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 

Kürzlich hochgeladen (20)

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

Sencha Class System, Jacky Nguyen

  • 2. The Sencha Class System Jacky Nguyen, Sencha jacky@sencha.com @nktpro Wednesday, November 2, 11
  • 4. Better Developer Experience Wednesday, November 2, 11
  • 5. Class System Event System Data Package Widgets & Layouts ... Wednesday, November 2, 11
  • 6. Prototype-based Class-based = Predictability Sencha Class System Flexibility Programmer Familiarity Wednesday, November 2, 11
  • 7. ✓Consistent ✓Familiar Learn ✓DRY ✓Debuggable Develop ✓Testable ✓Automatic dependency resolution Deploy Better Developer Experience Wednesday, November 2, 11
  • 9. Namespacing & Code Organization 1. OrganizationName.group[.subgroup].ClassName 2. One class per file 3. File name matches class name ‣ Ext.chart.Label -> Ext/chart/Label.js ‣ Ext.data.writer.Xml -> Ext/data/writer/Xml.js ‣ MyApp.field.Password -> MyApp/field/Password.js Wednesday, November 2, 11
  • 11. The Good Old Ext.extend() Ext.ns('My.sample'); My.sample.Person = Ext.extend(Object, { constructor: function(name) { this.name = name; }, walk: function(steps) { alert(this.name + ' is walking ' + steps + ' steps'); } }); Wednesday, November 2, 11
  • 12. Introducing Ext.define() Ext.define('My.sample.Person', { constructor: function(name) { this.name = name; }, walk: function(steps) { alert(this.name + ' is walking ' + steps + ' steps'); } }); var tommy = new My.sample.Developer('Tommy'); tommy.walk(5); // alerts 'Tommy is walking 5 steps' Wednesday, November 2, 11
  • 13. Ext.define() vs Ext.extend() Ext.define('My.sample.Person', { constructor: function(name) { this.name = name; }, walk: function(steps) { alert(this.name + ' is walking ' + steps + ' steps'); } }); ‣Class definition is more than just inheritance ‣Automatic namespace allocation ‣Classes are now aware of their own names ‣Asynchronous vs. synchronous Wednesday, November 2, 11
  • 15. Inheritance Ext.define('My.sample.Person', { constructor: function(name) { this.name = name; }, walk: function(steps) { alert(this.name + ' is walking ' + steps + ' steps'); } }); Ext.define('My.sample.Developer', { extend: 'My.sample.Person', code: function(language) { alert(this.name + ' is coding in ' + language); } }); var tommy = new My.sample.Developer('Tommy'); tommy.walk(5); // 'Tommy is walking 5 steps tommy.code('JavaScript'); // 'Tommy is coding in JavaScript' Wednesday, November 2, 11
  • 16. Inheritance Ext.define('My.sample.Developer', { extend: 'My.sample.Person', code: function(language) { /* ... */ }, walk: function(steps) { if (steps > 100) { alert('Are you serious? That's too far! I'm lazy...'); } else { My.sample.Developer.superclass.walk.apply(this, arguments); this.callParent(arguments); } } }); var tommy = new My.sample.Developer('Tommy'); tommy.walk(50); // alerts "Tommy is walking 50 steps" tommy.walk(101); // alerts "Are you serious? That's too far! I'm lazy..." Wednesday, November 2, 11
  • 18. Mixins Sing Performer Play Instruments Composer Compose Songs Singer-songwriter Wednesday, November 2, 11
  • 19. Mixins Ext.define('My.ability.Sing', { sing: function(songName) { alert("I'm singing " + songName); } }); Ext.define('My.ability.PlayInstruments', { play: function(instrument) { alert("I'm playing " + instrument); } }); Ext.define('My.ability.ComposeSongs', { compose: function(songName) { alert("I'm composing " + songName); } }); Wednesday, November 2, 11
  • 20. Mixins Ext.define('My.sample.Performer', { extend: 'My.sample.Person', mixins: { canSing: 'My.ability.Sing', canPlay: 'My.ability.PlayInstruments' } }); Ext.define('My.sample.Composer', { extend: 'My.sample.Person', mixins: { canPlay : 'My.ability.PlayInstruments', canCompose: 'My.ability.ComposeSongs' } }); Ext.define('My.sample.SingerSongwriter', { extend: 'My.sample.Person', mixins: { canSing : 'My.ability.Sing', canPlay : 'My.ability.PlayInstruments', canCompose: 'My.ability.ComposeSongs' } }); Wednesday, November 2, 11
  • 21. Mixins Ext.define('My.sample.Performer', { extend: 'My.sample.Person', mixins: { prototype of canSing: 'My.ability.Sing', canPlay: 'My.ability.PlayInstruments' }, sing: function() { alert("Here we go!"); this.mixins.canSing.sing.call(this); alert("I'm done singing!"); } }); var jamie = new My.sample.Performer("Jamie"); jamie.sing("November Rain"); // alerts "Here we go!" // alerts "I'm singing November Rain" // alerts "I'm done singing!"; Wednesday, November 2, 11
  • 22. Dependency Management Wednesday, November 2, 11
  • 23. Dependency Management <!-- ... --> <head> <!-- ... --> <script src="ext.js"></script> src="ext-all-debug.js"></script> <script src="My/sample/Person.js"></script> <script src="My/ability/PlayInstruments.js"></script> src="My/sample/Location.js"></script> <script src="My/ability/Sing.js"></script> src="My/sample/Developer.js"></script> <script src="My/sample/Performer.js"></script> <script> var tommy = new My.sample.Developer('Tommy'); 'Tommy'); Ext.create('My.sample.Developer', var jamie = new My.sample.Performer('Jamie'); 'Jamie'); Ext.create('My.sample.Performer', </script> </head> <!-- ... --> Wednesday, November 2, 11
  • 24. Dependency Management <!-- ... --> <head> <!-- ... --> <script src="ext.js"></script> <script> Ext.require([ 'My.sample.Developer', 'My.sample.Performer' ]); Ext.onReady(function() { var tommy = new My.sample.Developer('Tommy'); var jamie = new My.sample.Performer('Jamie'); }); </script> </head> <!-- ... --> Wednesday, November 2, 11
  • 26. Config Ext.define('My.sample.Person', { name: 'Anonymous', age: 0, gender: 'Male', constructor: function(config) { config = config || {}; Ext.apply(this, config); } }); var robert = new My.sample.Person({ name: 'Robert', age: 21 }); Wednesday, November 2, 11
  • 27. Config Ext.define('My.sample.Person', { name: 'Anonymous', age: 0, gender: 'Male', constructor: function(config) { if (Ext.isObject(config)) { if (config.hasOwnProperty('name')) { this.name = config.name; } if (config.hasOwnProperty('age')) { this.age = config.age; } if (config.hasOwnProperty('gender')) { this.gender = config.gender; } } } }); Wednesday, November 2, 11
  • 28. Config Ext.define('My.sample.Person', { name: 'Anonymous', age: 0, gender: 'Male', constructor: function(config) { if (Ext.isObject(config)) { if (config.hasOwnProperty('name')) { this.setName(config.name); } if (config.hasOwnProperty('age')) { this.setAge(config.age); } if (config.hasOwnProperty('gender')) { this.setGender(config.gender); } } }, }); Wednesday, November 2, 11
  • 29. setName: function(name) { this.name = name; return this; }, getName: function() { return this.name; }, setAge: function(age) { this.age = age; return this; }, getAge: function() { return this.age; }, setGender: function(gender) { this.gender = gender; return this; }, getGender: function() { return this.gender; } Wednesday, November 2, 11
  • 30. Config Ext.define('My.sample.Person', { config: { name: 'Anonymous', age: 0, gender: 'Male' }, constructor: function(config) { this.initConfig(config); } }); var robert = new My.sample.Person({ name: 'Robert', age: 21 }); robert.setName('Rob'); alert(robert.getAge()); // alerts '21' robert.setAge(22); alert(robert.getAge()); // alerts '22' Wednesday, November 2, 11
  • 31. Config: Deep Merging Ext.define('My.sample.Developer', { extend: My.sample.Person, config: { level: 'Junior', location: { city: 'Unknown', state: 'Unknown', country: 'Unknown' } } }); var edward = new My.sample.Developer({ age: 26, level: 'Senior', location: { city: 'Palo Alto', state: 'CA', country: 'USA' } }); edward.setName('Edward'); alert(edward.getLocation().city); // alerts 'Palo Alto' Wednesday, November 2, 11
  • 32. Config: Setter’s Process ✓Validation ✓Filtering Before ✓Transformation ✓Actual assignment Set ✓Notification ✓Updating dependencies After Wednesday, November 2, 11
  • 33. Config: Magic Methods getFoo() return this.foo setFoo() Before processedValue = applyFoo(newValue, oldValue) Set this.foo = processedValue After updateFoo(processedValue, oldValue) Wednesday, November 2, 11
  • 34. Config Ext.define('My.sample.Person', { /* ... */ applyAge: function(age) { if (typeof age != 'number' || age < 0) { alert("Invalid age, must be a positive number"); return; } return age; }, updateAge: function(newAge, oldAge) { alert("Age has changed from " + oldAge + " to " + newAge); } }); var aaron = new My.sample.Person({ name: 'Aaron', age: -100 }); // alerts "Invalid age, must be a positive number" alert(aaron.getAge()); // alerts 0 alert(aaron.setAge(35)); // alerts "Age has changed from 0 to 35" alert(aaron.getAge()); // alerts 35 Wednesday, November 2, 11
  • 35. Dependency Injection with Ext.factory() Wednesday, November 2, 11
  • 36. Dependency Injection Ext.define('My.sample.Location', { config: { city: 'Unknown', state: 'CA', country: 'USA' } }); var nicolas = new My.sample.Developer({ location: { city: 'Palo Alto' } }); alert(nicolas.getLocation() instanceof My.sample.Location); //alerts true alert(nicolas.getLocation().getCity()); // alerts 'Palo Alto' var nicolas = new My.sample.Developer({ location: new My.sample.Location({ city: 'Austin', state: 'TX' }) }); alert(nicolas.getLocation().getState()); // alerts 'TX' Wednesday, November 2, 11
  • 37. Dependency Injection nicolas.setLocation({ city: 'Austin' }); // nicolas.getLocation().setCity('Austin'); nicolas.setLocation(new My.sample.Location({ city: 'Austin', state: 'TX' })); nicolas.setLocation(new My.sample.DetailedLocation({ longitude: -122.18235, latitude: 37.44923 })); Wednesday, November 2, 11
  • 38. Ext.factory() Ext.define('My.sample.Developer', { extend: 'My.sample.Person', config: { level: 'Junior', location: {} }, applyLocation: function(location, currentLocation) { return Ext.factory( location, My.sample.Location, currentLocation ); } }); given value from setLocation() default Class existing instance Wednesday, November 2, 11
  • 41. Debugging: Dream Comes True Wednesday, November 2, 11
  • 42. Debugging: Dream Comes True Wednesday, November 2, 11
  • 44. Deployment Ext.Loader.history === [ 'My.sample.Person', 'My.sample.Location', 'My.sample.Developer', 'My.ability.Sing', 'My.ability.PlayInstruments', 'My.ability.ComposeSongs', 'My.sample.Performer', Concatenate Minify app.js 'My.sample.Composer', 'My.sample.SingerSongwriter', /* ... */ ]; http://www.sencha.com/products/sdk-tools Wednesday, November 2, 11
  • 46. Thank you! Wednesday, November 2, 11