SlideShare una empresa de Scribd logo
1 de 21
Ext JS Architecture
Best Practices
Mitchell Simoens
Senior Software Engineer, Sencha
mitch@sencha.com
@LikelyMitch
Let’s Start Coding!
So excited to start coding the new project! Wait!!!!
Planning
• Feature list you get is a high level list.
- As a developer, you have to create a technical list.
• Plan your namespaces.
- Features are a great namespace outline.
- Sections may be namespacable.
- Don’t be afraid to subclass.
• Use view controllers instead of global controllers, where possible.
• Don’t forget about the router!
3
Namespacing
Sample Portal Namespaces
Portal.view.main.Main (Cmd generated)
Portal.view.main.Center
Portal.view.header.Container
Portal.view.user.login.Form
Sample Fiddle Namespaces
Fiddle.view.main.Main (Cmd generated)
Fiddle.view.main.Center
Fiddle.view.main.Menu
Fiddle.view.header.Container
Fiddle.view.header.Title
Fiddle.view.header.Framework
Fiddle.view.user.login.Form
Fiddle.view.user.login.Window
Fiddle.view.user.Header
Fiddle.view.user.Menu
Fiddle.view.user.Settings
Fiddle.view.file.Tree
Fiddle.view.file.Menu
Fiddle.view.editor.Container
Fiddle.view.editor.item.Item
Fiddle.view.editor.item.Data
Fiddle.view.editor.item.Direct
Fiddle.view.search.Container
Fiddle.view.search.Form
Fiddle.view.search.Results
Code Reuse
Means of Code Reuse
• Subclassing/Abstracts
- Great for common UIs (think grids).
• Plugin
- Share common functionality with different components. Methods/configs not on class prototype.
• Mixin
- Not used much in apps. Like plugins but applies methods/configs onto the class prototype.
• Singleton
- Great for logic extraction.
• Cmd Package
- Share among many apps, can have any of the above.
MVC vs MVVM
MVC vs MVVM
Which to use and why?
• Debate is only on which controller to use really.
• Debate is really not a valid debate.
• Use them both! Depends on the need.
- Ext.app.Controller is global.
• Since ViewController was created, Controller shouldn’t listen to user interactions.
- Ext.app.ViewController is local.
• Think views as widgets.
• Shouldn’t know about anything other than the view it’s attached to.
Controller/ViewController Communication
// don’t do this
var controller = MyApp.app.getController(‘Foo’);
controller.doSomething();
----------
// do this instead
this.fireEvent(‘didsomething’, this);
// in other controller
listen : {
controller : {
‘*’ : {
didsomething : ‘doSomething’
}
}
}
// or use global events
Ext.fireEvent(‘didsomething’, this);
// in other controller
listen : {
global : {
didsomething : ‘doSomething’
}
}
// or
Ext.on(‘didsomething’, function() {});
Router
Router
Plan to use it before it’s too late!
• Allows the browser’s back/forward button to navigate in your app.
- Do not undervalue this!
• Allows deep linkage into your app.
- Do not undervalue this!
- Bookmark or email a link.
• Let routes do the work, not the view listeners.
- Become route centric!
• Can be hard to refactor at the end to support routes. Support it at the beginning.
onItemDblClick : function(gridview, record) {
this.redirectTo(‘user/’ + record.getId());
}
routes : {
’user:id’ : {
action : ‘onUser’,
conditions : {
//make id optional but only digits
‘:id’ : ‘(?:(?:/){1}(d+))?’
}
}
},
onUser : function(id) {
if (!this.hasUserGrid()) {
this.showUserGrid();
}
if (id) {
this.showUserForm(id);
} else if (this.hasUserForm()) {
this.destroyUserForm();
}
}
Route Centricity
• Use redirectTo more instead of doing
the thing in the event listener.
• Requires a change of thought.
• Reaction to a user interaction is more
async.
To Config or Not To Config
config : {
userId : null
},
applyUserId : function(id) {
return parseInt(id);
},
updateUserId : function(id) {
Ext.Ajax.request({
url : ‘/user’,
params : {
id : id
},
scope : this,
success : this.onUserLoad,
failure : this.onUserFail
});
}
Configs
• Use the getter and setter, not the
actual property
• Use applier to transform and sanitize
the value *if needed
• Use updater to react to value changes
- Use this to make your class dynamic
Route Reaction
onUser : function(id) {
if (!this.hasUserGrid()) {
this.showUserGrid();
}
if (id) {
this.showUserForm(id);
} else if (this.hasUserForm()) {
this.destroyUserForm();
}
}
showUserForm : function(id) {
var form = this.getUserForm();
if (form) {
form.setUserId(id);
} else {
this.createUserForm(id);
}
}
When to use a config
Should everything be a config?
• Sure
• There is a cost to generating the getter/setter
• There is a cost when initConfig is called
• Weigh the need with the cost
- Your class can be more dynamic and reactive
• Remember to clean up!
- Unless you are using Ext JS 6.2.0+ (thank you reaper!)
Ext JS Architecture Best Practices - Mitchell Simeons

Más contenido relacionado

La actualidad más candente

Inside vacuum - 第一回PostgreSQLプレ勉強会
Inside vacuum - 第一回PostgreSQLプレ勉強会Inside vacuum - 第一回PostgreSQLプレ勉強会
Inside vacuum - 第一回PostgreSQLプレ勉強会
Masahiko Sawada
 

La actualidad más candente (20)

PostgreSQLクエリ実行の基礎知識 ~Explainを読み解こう~
PostgreSQLクエリ実行の基礎知識 ~Explainを読み解こう~PostgreSQLクエリ実行の基礎知識 ~Explainを読み解こう~
PostgreSQLクエリ実行の基礎知識 ~Explainを読み解こう~
 
PostgreSQL16新機能紹介 - libpq接続ロード・バランシング(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)
PostgreSQL16新機能紹介 - libpq接続ロード・バランシング(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)PostgreSQL16新機能紹介 - libpq接続ロード・バランシング(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)
PostgreSQL16新機能紹介 - libpq接続ロード・バランシング(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)
 
PostgreSQLアンチパターン
PostgreSQLアンチパターンPostgreSQLアンチパターン
PostgreSQLアンチパターン
 
Rest ful api設計入門
Rest ful api設計入門Rest ful api設計入門
Rest ful api設計入門
 
Vue入門
Vue入門Vue入門
Vue入門
 
Kinesis Firehoseを使ってみた
Kinesis Firehoseを使ってみたKinesis Firehoseを使ってみた
Kinesis Firehoseを使ってみた
 
まずやっとくPostgreSQLチューニング
まずやっとくPostgreSQLチューニングまずやっとくPostgreSQLチューニング
まずやっとくPostgreSQLチューニング
 
NTT DATA と PostgreSQL が挑んだ総力戦
NTT DATA と PostgreSQL が挑んだ総力戦NTT DATA と PostgreSQL が挑んだ総力戦
NTT DATA と PostgreSQL が挑んだ総力戦
 
V$SQLとその周辺でER図を描いてみよう!
V$SQLとその周辺でER図を描いてみよう!V$SQLとその周辺でER図を描いてみよう!
V$SQLとその周辺でER図を描いてみよう!
 
MySQL・PostgreSQLだけで作る高速あいまい全文検索システム
MySQL・PostgreSQLだけで作る高速あいまい全文検索システムMySQL・PostgreSQLだけで作る高速あいまい全文検索システム
MySQL・PostgreSQLだけで作る高速あいまい全文検索システム
 
祝!PostgreSQLレプリケーション10周年!徹底紹介!!
祝!PostgreSQLレプリケーション10周年!徹底紹介!!祝!PostgreSQLレプリケーション10周年!徹底紹介!!
祝!PostgreSQLレプリケーション10周年!徹底紹介!!
 
PostgreSQLの統計情報について(第26回PostgreSQLアンカンファレンス@オンライン 発表資料)
PostgreSQLの統計情報について(第26回PostgreSQLアンカンファレンス@オンライン 発表資料)PostgreSQLの統計情報について(第26回PostgreSQLアンカンファレンス@オンライン 発表資料)
PostgreSQLの統計情報について(第26回PostgreSQLアンカンファレンス@オンライン 発表資料)
 
DBスキーマもバージョン管理したい!
DBスキーマもバージョン管理したい!DBスキーマもバージョン管理したい!
DBスキーマもバージョン管理したい!
 
Bambooによる継続的デリバリー
Bambooによる継続的デリバリーBambooによる継続的デリバリー
Bambooによる継続的デリバリー
 
PostgreSQL SQLチューニング入門 実践編(pgcon14j)
PostgreSQL SQLチューニング入門 実践編(pgcon14j)PostgreSQL SQLチューニング入門 実践編(pgcon14j)
PostgreSQL SQLチューニング入門 実践編(pgcon14j)
 
2016/12/15 SQLチューニングと対戦格闘ゲームの類似性について語る。 JPOUG Advent Calendar 2016 Day 15
2016/12/15 SQLチューニングと対戦格闘ゲームの類似性について語る。 JPOUG Advent Calendar 2016 Day 152016/12/15 SQLチューニングと対戦格闘ゲームの類似性について語る。 JPOUG Advent Calendar 2016 Day 15
2016/12/15 SQLチューニングと対戦格闘ゲームの類似性について語る。 JPOUG Advent Calendar 2016 Day 15
 
いまさら聞けないDocker - 第5回コンテナ型仮想化の情報交換会@大阪
いまさら聞けないDocker - 第5回コンテナ型仮想化の情報交換会@大阪いまさら聞けないDocker - 第5回コンテナ型仮想化の情報交換会@大阪
いまさら聞けないDocker - 第5回コンテナ型仮想化の情報交換会@大阪
 
設計品質とアーキテクチャ
設計品質とアーキテクチャ設計品質とアーキテクチャ
設計品質とアーキテクチャ
 
Redisの特徴と活用方法について
Redisの特徴と活用方法についてRedisの特徴と活用方法について
Redisの特徴と活用方法について
 
Inside vacuum - 第一回PostgreSQLプレ勉強会
Inside vacuum - 第一回PostgreSQLプレ勉強会Inside vacuum - 第一回PostgreSQLプレ勉強会
Inside vacuum - 第一回PostgreSQLプレ勉強会
 

Destacado

Destacado (19)

Sencha Roadshow 2017: What's New in Sencha Test
Sencha Roadshow 2017: What's New in Sencha TestSencha Roadshow 2017: What's New in Sencha Test
Sencha Roadshow 2017: What's New in Sencha Test
 
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
 
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...
 
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
 
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
 
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
 
Sencha Roadshow 2017: Sencha Upgrades - The Good. The Bad. The Ugly - Eva Luc...
Sencha Roadshow 2017: Sencha Upgrades - The Good. The Bad. The Ugly - Eva Luc...Sencha Roadshow 2017: Sencha Upgrades - The Good. The Bad. The Ugly - Eva Luc...
Sencha Roadshow 2017: Sencha Upgrades - The Good. The Bad. The Ugly - Eva Luc...
 
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: 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
 
Sencha Roadshow 2017: Best Practices for Implementing Continuous Web App Testing
Sencha Roadshow 2017: Best Practices for Implementing Continuous Web App TestingSencha Roadshow 2017: Best Practices for Implementing Continuous Web App Testing
Sencha Roadshow 2017: Best Practices for Implementing Continuous Web App Testing
 
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: 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: 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 Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd
Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd
Sencha Roadshow 2017: Build Progressive Web Apps with Ext JS and Cmd
 
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
 
Sencha Roadshow 2017: BufferedStore Internals featuring eyeworkers interactiv...
Sencha Roadshow 2017: BufferedStore Internals featuring eyeworkers interactiv...Sencha Roadshow 2017: BufferedStore Internals featuring eyeworkers interactiv...
Sencha Roadshow 2017: BufferedStore Internals featuring eyeworkers interactiv...
 
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...
 
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
 

Similar a Ext JS Architecture Best Practices - Mitchell Simeons

Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
funkatron
 
Android | Busy Java Developers Guide to Android: UI | Ted Neward
Android | Busy Java Developers Guide to Android: UI | Ted NewardAndroid | Busy Java Developers Guide to Android: UI | Ted Neward
Android | Busy Java Developers Guide to Android: UI | Ted Neward
JAX London
 

Similar a Ext JS Architecture Best Practices - Mitchell Simeons (20)

Ext JS Introduction
Ext JS IntroductionExt JS Introduction
Ext JS Introduction
 
Solid And Sustainable Development in Scala
Solid And Sustainable Development in ScalaSolid And Sustainable Development in Scala
Solid And Sustainable Development in Scala
 
Solid and Sustainable Development in Scala
Solid and Sustainable Development in ScalaSolid and Sustainable Development in Scala
Solid and Sustainable Development in Scala
 
Developing Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptxDeveloping Lightning Components for Communities.pptx
Developing Lightning Components for Communities.pptx
 
Build tons of multi-device JavaScript applications - Part 1 : Boilerplate, de...
Build tons of multi-device JavaScript applications - Part 1 : Boilerplate, de...Build tons of multi-device JavaScript applications - Part 1 : Boilerplate, de...
Build tons of multi-device JavaScript applications - Part 1 : Boilerplate, de...
 
Sinatra and JSONQuery Web Service
Sinatra and JSONQuery Web ServiceSinatra and JSONQuery Web Service
Sinatra and JSONQuery Web Service
 
Does my DIV look big in this?
Does my DIV look big in this?Does my DIV look big in this?
Does my DIV look big in this?
 
Renegades Guide to Hacking Rails Internals
Renegades Guide to Hacking Rails InternalsRenegades Guide to Hacking Rails Internals
Renegades Guide to Hacking Rails Internals
 
Intro To Mvc Development In Php
Intro To Mvc Development In PhpIntro To Mvc Development In Php
Intro To Mvc Development In Php
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
 
Drupal 8 - Core and API Changes
Drupal 8 - Core and API ChangesDrupal 8 - Core and API Changes
Drupal 8 - Core and API Changes
 
Android | Busy Java Developers Guide to Android: UI | Ted Neward
Android | Busy Java Developers Guide to Android: UI | Ted NewardAndroid | Busy Java Developers Guide to Android: UI | Ted Neward
Android | Busy Java Developers Guide to Android: UI | Ted Neward
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
 
Advanced RESTful Rails
Advanced RESTful RailsAdvanced RESTful Rails
Advanced RESTful Rails
 
BluePrint Mobile Framework
BluePrint Mobile FrameworkBluePrint Mobile Framework
BluePrint Mobile Framework
 
Yahoo Mobile Widgets
Yahoo Mobile WidgetsYahoo Mobile Widgets
Yahoo Mobile Widgets
 
Introduction to Swagger
Introduction to SwaggerIntroduction to Swagger
Introduction to Swagger
 
Responsive Design from problem to production
Responsive Design from problem to productionResponsive Design from problem to production
Responsive Design from problem to production
 
Staying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHPStaying Sane with Drupal NEPHP
Staying Sane with Drupal NEPHP
 

Más de Sencha

Más de Sencha (11)

Breathe New Life into Your Existing JavaScript Applications with Web Components
Breathe New Life into Your Existing JavaScript Applications with Web ComponentsBreathe New Life into Your Existing JavaScript Applications with Web Components
Breathe New Life into Your Existing JavaScript Applications with Web Components
 
Ext JS 6.6 Highlights
Ext JS 6.6 HighlightsExt JS 6.6 Highlights
Ext JS 6.6 Highlights
 
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...
 
SenchaCon 2016: Handling Undo-Redo in Sencha Applications - Nickolay Platonov
SenchaCon 2016: Handling Undo-Redo in Sencha Applications - Nickolay PlatonovSenchaCon 2016: Handling Undo-Redo in Sencha Applications - Nickolay Platonov
SenchaCon 2016: Handling Undo-Redo in Sencha Applications - Nickolay Platonov
 
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
SenchaCon 2016: How to Auto Generate a Back-end in Minutes - Per Minborg, Emi...
 
SenchaCon 2016: Turbocharge your Ext JS App - Per Minborg, Anselm McClain, Jo...
SenchaCon 2016: Turbocharge your Ext JS App - Per Minborg, Anselm McClain, Jo...SenchaCon 2016: Turbocharge your Ext JS App - Per Minborg, Anselm McClain, Jo...
SenchaCon 2016: Turbocharge your Ext JS App - Per Minborg, Anselm McClain, Jo...
 
SenchaCon 2016: Integrating Geospatial Maps & Big Data Using CartoDB via Ext ...
SenchaCon 2016: Integrating Geospatial Maps & Big Data Using CartoDB via Ext ...SenchaCon 2016: Integrating Geospatial Maps & Big Data Using CartoDB via Ext ...
SenchaCon 2016: Integrating Geospatial Maps & Big Data Using CartoDB via Ext ...
 

Último

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 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
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 

Ext JS Architecture Best Practices - Mitchell Simeons

  • 1. Ext JS Architecture Best Practices Mitchell Simoens Senior Software Engineer, Sencha mitch@sencha.com @LikelyMitch
  • 2. Let’s Start Coding! So excited to start coding the new project! Wait!!!!
  • 3. Planning • Feature list you get is a high level list. - As a developer, you have to create a technical list. • Plan your namespaces. - Features are a great namespace outline. - Sections may be namespacable. - Don’t be afraid to subclass. • Use view controllers instead of global controllers, where possible. • Don’t forget about the router! 3
  • 5.
  • 6. Sample Portal Namespaces Portal.view.main.Main (Cmd generated) Portal.view.main.Center Portal.view.header.Container Portal.view.user.login.Form
  • 7.
  • 8. Sample Fiddle Namespaces Fiddle.view.main.Main (Cmd generated) Fiddle.view.main.Center Fiddle.view.main.Menu Fiddle.view.header.Container Fiddle.view.header.Title Fiddle.view.header.Framework Fiddle.view.user.login.Form Fiddle.view.user.login.Window Fiddle.view.user.Header Fiddle.view.user.Menu Fiddle.view.user.Settings Fiddle.view.file.Tree Fiddle.view.file.Menu Fiddle.view.editor.Container Fiddle.view.editor.item.Item Fiddle.view.editor.item.Data Fiddle.view.editor.item.Direct Fiddle.view.search.Container Fiddle.view.search.Form Fiddle.view.search.Results
  • 10. Means of Code Reuse • Subclassing/Abstracts - Great for common UIs (think grids). • Plugin - Share common functionality with different components. Methods/configs not on class prototype. • Mixin - Not used much in apps. Like plugins but applies methods/configs onto the class prototype. • Singleton - Great for logic extraction. • Cmd Package - Share among many apps, can have any of the above.
  • 12. MVC vs MVVM Which to use and why? • Debate is only on which controller to use really. • Debate is really not a valid debate. • Use them both! Depends on the need. - Ext.app.Controller is global. • Since ViewController was created, Controller shouldn’t listen to user interactions. - Ext.app.ViewController is local. • Think views as widgets. • Shouldn’t know about anything other than the view it’s attached to.
  • 13. Controller/ViewController Communication // don’t do this var controller = MyApp.app.getController(‘Foo’); controller.doSomething(); ---------- // do this instead this.fireEvent(‘didsomething’, this); // in other controller listen : { controller : { ‘*’ : { didsomething : ‘doSomething’ } } } // or use global events Ext.fireEvent(‘didsomething’, this); // in other controller listen : { global : { didsomething : ‘doSomething’ } } // or Ext.on(‘didsomething’, function() {});
  • 15. Router Plan to use it before it’s too late! • Allows the browser’s back/forward button to navigate in your app. - Do not undervalue this! • Allows deep linkage into your app. - Do not undervalue this! - Bookmark or email a link. • Let routes do the work, not the view listeners. - Become route centric! • Can be hard to refactor at the end to support routes. Support it at the beginning.
  • 16. onItemDblClick : function(gridview, record) { this.redirectTo(‘user/’ + record.getId()); } routes : { ’user:id’ : { action : ‘onUser’, conditions : { //make id optional but only digits ‘:id’ : ‘(?:(?:/){1}(d+))?’ } } }, onUser : function(id) { if (!this.hasUserGrid()) { this.showUserGrid(); } if (id) { this.showUserForm(id); } else if (this.hasUserForm()) { this.destroyUserForm(); } } Route Centricity • Use redirectTo more instead of doing the thing in the event listener. • Requires a change of thought. • Reaction to a user interaction is more async.
  • 17. To Config or Not To Config
  • 18. config : { userId : null }, applyUserId : function(id) { return parseInt(id); }, updateUserId : function(id) { Ext.Ajax.request({ url : ‘/user’, params : { id : id }, scope : this, success : this.onUserLoad, failure : this.onUserFail }); } Configs • Use the getter and setter, not the actual property • Use applier to transform and sanitize the value *if needed • Use updater to react to value changes - Use this to make your class dynamic
  • 19. Route Reaction onUser : function(id) { if (!this.hasUserGrid()) { this.showUserGrid(); } if (id) { this.showUserForm(id); } else if (this.hasUserForm()) { this.destroyUserForm(); } } showUserForm : function(id) { var form = this.getUserForm(); if (form) { form.setUserId(id); } else { this.createUserForm(id); } }
  • 20. When to use a config Should everything be a config? • Sure • There is a cost to generating the getter/setter • There is a cost when initConfig is called • Weigh the need with the cost - Your class can be more dynamic and reactive • Remember to clean up! - Unless you are using Ext JS 6.2.0+ (thank you reaper!)

Notas del editor

  1. Creating an initial plan on the classes you will need based on the features and design is important. It’s like a database; you would just start creating tables without some thought on what columns you need in certain tables and what tables are going to be joined together. An initial plan doesn’t have to be a final plan but it’s at least something to start on.
  2. May be hard to see but the entire page is wrapped in a red border, this region is the “main” region. You may also call it the viewport but that can mean other things so I like to stick with main. A common UI is a header up top with a company’s logo and maybe the company name or other information. On a login screen like this, likely to be blank but depends on your app. Under the header you have the rest of the app, I call this the center region. I name it this way as I use border layout a lot so it fits with that layout’s terminology. So now you have two main sections of your UI. You can now start to break them down more. In this view, the header doesn’t have anything else but the center has a login section. You are now breaking the UI up into individual modules or widgets.
  3. From the last slide, here are some namespaces I can go with. Very simplistic on that slide so we need to look at something a bit more complex like the screen you see after you login.
  4. This is Sencha Fiddle 2 and it may be very hard to see but I’ve started to draw boxes around sections of the application. This allows me to visually start to see the separate sections in a way that I can plan my namespacing. However, namespacing doesn’t necessarily need to follow the sections. For example, in the top right there is a section for the user info where you can click to login or if already logged in shows the username and when clicked will show a user menu. This is in the header but there is likely other user features such as a settings form. I have to decide if the namespace should go under the header section namespace or the user feature namespace. I tend to favor namespacing by feature than section if there is a conflict but nothing wrong with having that user section under the header namespace.
  5. A bit more thought out namespacing scheme. More classes will no doubt be needed but you can start seeing certain namespaces will encapsulate certain things.
  6. This one is important. Ext JS’ class system allows great extensibility which gives you flexibility into your code designs. One thought is the more code you can reuse the better.
  7. There are many ways to reuse code and there really isn’t a silver bullet answer; this will depend on the independent thing at hand.
  8. I get asked this question a lot, “Should I use MVC or MVVM?” Well, since I’m sure you have already started to think out what classes you’ll need, you tell me!
  9. You see, the question really isn’t which one should you use, it’s really which controller should you use and it’s not a valid debate. Why not use both if your application needs to? I primarily use view controllers as it allows me to think in smaller pieces, my views become widgets. However, there are certain global aspects of applications so a global controller still has it’s uses. Let me give you an example. Sencha Fiddle has many views such as a file tree and an editor tab panel. When you interact with those, a view controller can react and do things. But if you have an editor focused and you press control + s (meaning save the fiddle), that save is a global thing. So I have local and global needs in Fiddle so I use both MVC and MVVM, it’s not black or white.
  10. However, when you use both controllers you can get trapped into tightly coupling logic to the current state of your application. So what if down the development line you have to change something or the name of a controller no longer fits what it does so you want to rename it. If you are looking up individual controllers, you now have to go through your app looking for these lookups and update that code which will eventually bite you and cause regressions. Instead, use events either on the controller event domain or Ext JS’ global event system so your controller (or whatever) fires an event and doesn’t care about anything else. Other controller can then listen to these events and react for their uses. Now, your code execution is much more flexible and fluid.
  11. Ever since Ext JS 5 we have had a router and it’s an often overlooked feature. I’m the kind of web developer that I’ll watch people use their browser. I still see lots of people using the browser’s back and forward buttons and they expect whatever they are on to work as they expect. A web application should and can work like a normal multipage site.
  12. Say you have a grid and when a user double clicks on a grid row you want to open a form to edit that row or you want to see details about it. You’ll still add an itemdblclick listener but instead of that listener opening the view, it simply calls redirectTo to change the hash in the browser’s address bar. It’s like I discussed with controllers, it does one thing and doesn’t know about anything that happens after. You then setup a route to listen to this hash and the route then takes care of opening that view. Here’s the tricky part about it, you have to think about when someone is first loading the application with that route. Depending on your application, you may want to still show the grid and the view so you have to see if the grid is instantiated and if not then show the grid. And then handle if there was an id passed.