SlideShare a Scribd company logo
Guidelines and Best
Practices for Sencha
Projects
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
• Performance Guidelines
• General Guidelines
• Documentation Guidelines
• View Models and Data Binding
• Lifecycle Guidelines
- New Operator
- Controllers & Views
• Logging and Tracing
• Form Validation and Submission
• Scope
Agenda
2
Performance Guidelines
3
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
Avoid Using doLayout()/updateLayout():
If at all there is a need, use suspendLayout flag.
• / /Turn the suspendLayout flag on
• containerPanel.suspendLayout: true
• // Trigger a layout.
• containerPanel.resumeLayouts();
• containerPanel.updateLayout();
Copyright © 2008 Walking Tree Consultancy Services . All rights reserved.
F 300 F F
500
suspendLayouts()
height
width
zindex
display
resumeLayouts(flushlayouts true/false)
updateLayout()
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
Effective use of event listeners :
Inefficient use slows down the application performance. For example:
listeners: {
load: {
fn: onFirstLoadData,
single: true
}
}
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
Avoid Over nesting :
It unnecessarily increases DOM Size and might lead to layout issues.
Replace Panels with Containers :
Ext JS Panels are more powerful (and expensive!) than basic containers.
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
Initial Page Load :
• <script src="filename.js"> tags should be placed as late in the body as
possible
• Make use of Ext JS “requires”
• Do not use Ext.require()
Event bubbling is a costly operation :
So handle it carefully.
Copyright © 2008 Walking Tree Consultancy Services . All rights reserved.
1
2
3 Handler for handleParent event. return false.
4
5. this.enableBubble(‘handleparent’);
fireEvent(‘handleparent’);
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
Example:
xtype: 'button',
handler: function() {
this.enableBubble('MoreClicked');
this.fireEvent('MoreClicked', this);
}
Copyright © 2008 Walking Tree Consultancy Services . All rights reserved.
Suspend and Resume events :
While manipulating bulk Dom elements of a component or bulk store records
or bulk array objects, suspend events to avoid multiple event execution,
nested layout executions and recursive DOM manipulation.
For example,
INCORRECT CORRECT
Copyright © 2008 Walking Tree Consultancy Services . All rights reserved.
Performance Factors In Loops :
• Declaration of functions (and for that matter, other re-usable things) inside loops
wastes processing time, memory, and garbage collection cycles
INCORRECT CORRECT
• Calculate array length only once upfront and assign its value to a variable
Copyright © 2008 Walking Tree Consultancy Services . All rights reserved.
Regular Expression:
• Store regular expressions in a variable
• Always add comments
INCORRECT CORRECT
• Cache literal Regular Expressions in a more permanent way
INCORRECT CORRECT
General Guidelines
14
Copyright © 2008 Walking Tree Consultancy Services . All rights reserved.
• Do not use Ext.apply () if recursive merging and cloning without referencing
the original objects / arrays is needed. Use Ext.Object.merge instead.
• Avoid hard coding of id property. Alternatively, use “itemId”.
• Avoid hard coding of height and width.
• If using a storeId, use fully qualified store class name as the storeId (e.g.
storeId : ‘MyApp.store.Businesses’).
• Specify font size as "em" or "%".
Localization and Internationalization:
• All static text should be defined in a separate file by keeping localization in
perspective.
Documentation
Guidelines
16
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
Code documentation must be done using JSDuck annotations. Following are
the minimal documentation requirement:
• Every class must be documented
• Every public and protected property of a class must be documented along
with an example value. Document must indicate whether the property is
mandatory or optional. Default value must be specified for the optional
properties.
• Every public and protected method of a class must be documented
• Events fired by a class must be documented along with the parameters that
will be passed to a listener
JSDuck document must be generated from the documented code.
https://github.com/senchalabs/jsduck/wiki
View Models and Data Binding
18
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
• Preferred syntax for configuring a View Model.
viewModel : {
type: ‘app-main’
}
• Prefer using declarations over procedural calls. For example:
stores: {
businesses: {
model : ‘MyApp.model.Business’,
autoLoad : true
}
}
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
• Preferably, bind properties in the view class declaration itself rather than
binding procedurally
• Don’t create child View Models unless they are actually needed.
• For derived variables, use formulas
• Use formulas instead of repeating binds. For example,
one formula with 3 dependencies and 4 users make 3 + 4 = 7 dependencies
to track in the ViewModel. Compared to 4 users with those 3 dependencies
on themselves we would have 3 * 4 = 12 dependencies. Fewer
dependencies to track means less memory used and time to process them.
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
• Use “deep:true” while binding config with an object / property embedded
inside another object. For example, if this is the object
detail : {
name : ‘Rohit’,
address : {
state : ‘Telangana’,
city: ‘Hyderabad’
}
}
To be notified of changes in the address object, use the following syntax:
bind : {
data : {
bindTo : ‘{detail}’,
deep: true
}
Lifecycle Guide Lines
22
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
New Operator :
• Use {} instead of new Object()
• Use [] instead of new Array()
• For Ext JS objects, you should use the create() method
• For dates related objects, you still require to use new
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
Views and View Controllers:
• Views have the following lifecycle methods:
1. constructor
2. initComponent
• View Controllers have the following 3 lifecycle methods :
1. beforeInit
2. init
3. initViewModel
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
When combined, the view and controller lifecycle methods are executed in
following order
1. constructor of View
2. beforeInit of Controller
3. initComponent of View
4. init of Controller
5. initViewModel of Controller
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
Dom Updates In Component LifeCycle:
• Changing elements after DOM elements are rendered causes reflows,
resulting in slowing down of the application. Write code that avoids DOM
read/writes.
• If required, add CSS classes and set styles in beforerender event handler
rather than afterrender.
• For some code, we may need to acquire the element size. If this is the case,
then consider handling the ‘boxready’ event. For example:
if ( height of element > 100px ) {
//do something
}
Logging & Tracing
27
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
Tracing :
• Use Ext.getDisplayName(). For example:
throw new Error('['+ Ext.getDisplayName(arguments.callee) +'] Some message
here');
• Check call stack.
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
Logging :
• Use Ext.log compared to console.log. If console is present, it will be used. In
other cases, the message is logged to an array:
"Ext.log.out“
An attached debugger can watch this array and view the log. The log buffer is
limited to a maximum of "Ext.log.max" entries (defaults to 250).
• Debugging statements like console.log() and debugger should never be shipped
into standard production environments.
INCORRECT CORRECT
Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd.
• Use the <debug> tag.
• Ext JS 5.x provides “debugHooks” config for a class, through which you can
write debugging statements.
Form Validation & Submission
31
Copyright © 2008 Walking Tree Consultancy Services . All rights reserved.
• Use models for validating and submitting the forms and push the field
validation logic (including custom validations) inside models.
• Use loadRecord method of the FormPanel.
• Instead of using explicit logic to enable / disable a submit button, make use of
“formBind: true”.
Scope
33
Copyright © 2008 Walking Tree Consultancy Services . All rights reserved.
Global Variables:
• Variables declared outside a function are considered in global scope –
irrespective of the usage of “var” keyword.
• These variables are in global “window” namespace. For example, the
following are same:
var gCompanyName = “Walking Tree”;
window.companyName = “Walking Tree”; //more explicit
• If you want to define global variables then use them inside application
namespace. For example:
Ext.define( ‘MyApp.util.Constants’,{
singleton : true,
ANIMATION_Time : 100,
// more variables and methods
});
Copyright © 2008 Walking Tree Consultancy Services . All rights reserved.
• Consider saving the “this” scope into a different (and smaller) name (e.g.
me). For example,
Ext.define(‘MyApp.view.MyPanel’,{
initComponent : function () {
var me=this;
me.add () {
xtype : ‘button’,
handler: function () {
this.getHeight();
me.getTitle();
}
me.callParent( arguments );
}
});
Copyright © 2008 Walking Tree Consultancy Services . All rights reserved.
Upcoming Online Training On Best Practices and Coding
Guidelines on:
28th Nov’, 2015
For details contact:
Ratan Agarwal
cel: +91 95 81400033
Thank You
37

More Related Content

PDF
Introduction to ExtJs 5
PPT
CSS Frameworks: Faster Layout, Consistent Results
PPTX
Sencha ExtJs Learning Part 2 - MVC And MVVM Architecture in ExtJs [ENGLISH]
PPTX
Hari kantin
PPTX
Contents page analysis
 
PDF
LLAMADO PARA ARRENDAMIENTO
PDF
Municipal Perspectives for Renewable Energy Adoption_Barnes
ODP
Pablo valbuena
Introduction to ExtJs 5
CSS Frameworks: Faster Layout, Consistent Results
Sencha ExtJs Learning Part 2 - MVC And MVVM Architecture in ExtJs [ENGLISH]
Hari kantin
Contents page analysis
 
LLAMADO PARA ARRENDAMIENTO
Municipal Perspectives for Renewable Energy Adoption_Barnes
Pablo valbuena

Viewers also liked (14)

PDF
Ts 590 s-usb_audio_settings_manual
PPTX
Analisa sinyal kecil
PDF
Pubudu_Silva_Parallel-Universe-Issue-27
PDF
SANJAY_ALAHAM_Resume_01.08.16
PPTX
Chapter 1 - A Historical Overview
PDF
CARA - Coding Dojo TDD & Open Closed Principle
PPTX
Peptic ulcer
PPTX
Google Traffic Tips, Tactics and Strategies
PDF
LLAMADO PARA ARRENDAMIENTO
PPTX
Possibilities for magazine.
 
PPS
Fsm Operations on Nigeria map
PDF
Presentacion aconcagua saia 2
PPTX
Què és Periscope i com utilitzar-lo?
Ts 590 s-usb_audio_settings_manual
Analisa sinyal kecil
Pubudu_Silva_Parallel-Universe-Issue-27
SANJAY_ALAHAM_Resume_01.08.16
Chapter 1 - A Historical Overview
CARA - Coding Dojo TDD & Open Closed Principle
Peptic ulcer
Google Traffic Tips, Tactics and Strategies
LLAMADO PARA ARRENDAMIENTO
Possibilities for magazine.
 
Fsm Operations on Nigeria map
Presentacion aconcagua saia 2
Què és Periscope i com utilitzar-lo?
Ad

Similar to Guidelines and Best Practices for Sencha Projects (20)

PDF
Sencha Services
PPTX
Extension Javascript
KEY
Debugging Your Ext JS Code
PDF
Building a JavaScript Library
PDF
Ext JS in Action 1st Edition Jesus Garcia
PPTX
Ext JS Architecture Best Practices - Mitchell Simeons
PDF
Javascript: the important bits
PDF
Architecting your app in ext js 4, part 1 learn sencha
PDF
Sencha Roadshow 2017: Sencha Best Practices: Coworkee App
PPTX
Ext JS Introduction
PPTX
Sencha Touch MVC
PPTX
Java script performance tips
PPT
Javascript and Jquery Best practices
PDF
XPages Performance Master Class - Survive in the fast lane on the Autobahn (E...
KEY
Ext js 4 MVC
PDF
AD1279 "Marty, You're Not Thinking Fourth Dimensionally" - Troubleshooting XP...
PDF
Fast mobile web apps
PPT
Practical Ext JS Debugging
PPTX
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
PDF
Maintainable Javascript carsonified
Sencha Services
Extension Javascript
Debugging Your Ext JS Code
Building a JavaScript Library
Ext JS in Action 1st Edition Jesus Garcia
Ext JS Architecture Best Practices - Mitchell Simeons
Javascript: the important bits
Architecting your app in ext js 4, part 1 learn sencha
Sencha Roadshow 2017: Sencha Best Practices: Coworkee App
Ext JS Introduction
Sencha Touch MVC
Java script performance tips
Javascript and Jquery Best practices
XPages Performance Master Class - Survive in the fast lane on the Autobahn (E...
Ext js 4 MVC
AD1279 "Marty, You're Not Thinking Fourth Dimensionally" - Troubleshooting XP...
Fast mobile web apps
Practical Ext JS Debugging
SenchaCon 2016: Building a Faceted Catalog of Video Game Assets Using Ext JS ...
Maintainable Javascript carsonified
Ad

Recently uploaded (20)

PDF
SEVA- Fashion designing-Presentation.pdf
PPTX
rapid fire quiz in your house is your india.pptx
PPTX
6- Architecture design complete (1).pptx
PPTX
AD Bungalow Case studies Sem 2.pptxvwewev
PPTX
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
PDF
BRANDBOOK-Presidential Award Scheme-Kenya-2023
PPTX
YV PROFILE PROJECTS PROFILE PRES. DESIGN
PPT
pump pump is a mechanism that is used to transfer a liquid from one place to ...
PPTX
Fundamental Principles of Visual Graphic Design.pptx
PPTX
Wisp Textiles: Where Comfort Meets Everyday Style
PPT
UNIT I- Yarn, types, explanation, process
PPTX
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
PPTX
HPE Aruba-master-icon-library_052722.pptx
PDF
GREEN BUILDING MATERIALS FOR SUISTAINABLE ARCHITECTURE AND BUILDING STUDY
PPTX
12. Community Pharmacy and How to organize it
PPTX
areprosthodontics and orthodonticsa text.pptx
PPTX
ANATOMY OF ANTERIOR CHAMBER ANGLE AND GONIOSCOPY.pptx
PDF
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
PDF
Interior Structure and Construction A1 NGYANQI
PDF
Emailing DDDX-MBCaEiB.pdf DDD_Europe_2022_Intro_to_Context_Mapping_pdf-165590...
SEVA- Fashion designing-Presentation.pdf
rapid fire quiz in your house is your india.pptx
6- Architecture design complete (1).pptx
AD Bungalow Case studies Sem 2.pptxvwewev
BSCS lesson 3.pptxnbbjbb mnbkjbkbbkbbkjb
BRANDBOOK-Presidential Award Scheme-Kenya-2023
YV PROFILE PROJECTS PROFILE PRES. DESIGN
pump pump is a mechanism that is used to transfer a liquid from one place to ...
Fundamental Principles of Visual Graphic Design.pptx
Wisp Textiles: Where Comfort Meets Everyday Style
UNIT I- Yarn, types, explanation, process
CLASS_11_BUSINESS_STUDIES_PPT_CHAPTER_1_Business_Trade_Commerce.pptx
HPE Aruba-master-icon-library_052722.pptx
GREEN BUILDING MATERIALS FOR SUISTAINABLE ARCHITECTURE AND BUILDING STUDY
12. Community Pharmacy and How to organize it
areprosthodontics and orthodonticsa text.pptx
ANATOMY OF ANTERIOR CHAMBER ANGLE AND GONIOSCOPY.pptx
UNIT 1 Introduction fnfbbfhfhfbdhdbdto Java.pptx.pdf
Interior Structure and Construction A1 NGYANQI
Emailing DDDX-MBCaEiB.pdf DDD_Europe_2022_Intro_to_Context_Mapping_pdf-165590...

Guidelines and Best Practices for Sencha Projects

  • 1. Guidelines and Best Practices for Sencha Projects
  • 2. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. • Performance Guidelines • General Guidelines • Documentation Guidelines • View Models and Data Binding • Lifecycle Guidelines - New Operator - Controllers & Views • Logging and Tracing • Form Validation and Submission • Scope Agenda 2
  • 4. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. Avoid Using doLayout()/updateLayout(): If at all there is a need, use suspendLayout flag. • / /Turn the suspendLayout flag on • containerPanel.suspendLayout: true • // Trigger a layout. • containerPanel.resumeLayouts(); • containerPanel.updateLayout();
  • 5. Copyright © 2008 Walking Tree Consultancy Services . All rights reserved. F 300 F F 500 suspendLayouts() height width zindex display resumeLayouts(flushlayouts true/false) updateLayout()
  • 6. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. Effective use of event listeners : Inefficient use slows down the application performance. For example: listeners: { load: { fn: onFirstLoadData, single: true } }
  • 7. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. Avoid Over nesting : It unnecessarily increases DOM Size and might lead to layout issues. Replace Panels with Containers : Ext JS Panels are more powerful (and expensive!) than basic containers.
  • 8. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. Initial Page Load : • <script src="filename.js"> tags should be placed as late in the body as possible • Make use of Ext JS “requires” • Do not use Ext.require() Event bubbling is a costly operation : So handle it carefully.
  • 9. Copyright © 2008 Walking Tree Consultancy Services . All rights reserved. 1 2 3 Handler for handleParent event. return false. 4 5. this.enableBubble(‘handleparent’); fireEvent(‘handleparent’);
  • 10. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. Example: xtype: 'button', handler: function() { this.enableBubble('MoreClicked'); this.fireEvent('MoreClicked', this); }
  • 11. Copyright © 2008 Walking Tree Consultancy Services . All rights reserved. Suspend and Resume events : While manipulating bulk Dom elements of a component or bulk store records or bulk array objects, suspend events to avoid multiple event execution, nested layout executions and recursive DOM manipulation. For example, INCORRECT CORRECT
  • 12. Copyright © 2008 Walking Tree Consultancy Services . All rights reserved. Performance Factors In Loops : • Declaration of functions (and for that matter, other re-usable things) inside loops wastes processing time, memory, and garbage collection cycles INCORRECT CORRECT • Calculate array length only once upfront and assign its value to a variable
  • 13. Copyright © 2008 Walking Tree Consultancy Services . All rights reserved. Regular Expression: • Store regular expressions in a variable • Always add comments INCORRECT CORRECT • Cache literal Regular Expressions in a more permanent way INCORRECT CORRECT
  • 15. Copyright © 2008 Walking Tree Consultancy Services . All rights reserved. • Do not use Ext.apply () if recursive merging and cloning without referencing the original objects / arrays is needed. Use Ext.Object.merge instead. • Avoid hard coding of id property. Alternatively, use “itemId”. • Avoid hard coding of height and width. • If using a storeId, use fully qualified store class name as the storeId (e.g. storeId : ‘MyApp.store.Businesses’). • Specify font size as "em" or "%". Localization and Internationalization: • All static text should be defined in a separate file by keeping localization in perspective.
  • 17. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. Code documentation must be done using JSDuck annotations. Following are the minimal documentation requirement: • Every class must be documented • Every public and protected property of a class must be documented along with an example value. Document must indicate whether the property is mandatory or optional. Default value must be specified for the optional properties. • Every public and protected method of a class must be documented • Events fired by a class must be documented along with the parameters that will be passed to a listener JSDuck document must be generated from the documented code. https://github.com/senchalabs/jsduck/wiki
  • 18. View Models and Data Binding 18
  • 19. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. • Preferred syntax for configuring a View Model. viewModel : { type: ‘app-main’ } • Prefer using declarations over procedural calls. For example: stores: { businesses: { model : ‘MyApp.model.Business’, autoLoad : true } }
  • 20. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. • Preferably, bind properties in the view class declaration itself rather than binding procedurally • Don’t create child View Models unless they are actually needed. • For derived variables, use formulas • Use formulas instead of repeating binds. For example, one formula with 3 dependencies and 4 users make 3 + 4 = 7 dependencies to track in the ViewModel. Compared to 4 users with those 3 dependencies on themselves we would have 3 * 4 = 12 dependencies. Fewer dependencies to track means less memory used and time to process them.
  • 21. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. • Use “deep:true” while binding config with an object / property embedded inside another object. For example, if this is the object detail : { name : ‘Rohit’, address : { state : ‘Telangana’, city: ‘Hyderabad’ } } To be notified of changes in the address object, use the following syntax: bind : { data : { bindTo : ‘{detail}’, deep: true }
  • 23. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. New Operator : • Use {} instead of new Object() • Use [] instead of new Array() • For Ext JS objects, you should use the create() method • For dates related objects, you still require to use new
  • 24. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. Views and View Controllers: • Views have the following lifecycle methods: 1. constructor 2. initComponent • View Controllers have the following 3 lifecycle methods : 1. beforeInit 2. init 3. initViewModel
  • 25. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. When combined, the view and controller lifecycle methods are executed in following order 1. constructor of View 2. beforeInit of Controller 3. initComponent of View 4. init of Controller 5. initViewModel of Controller
  • 26. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. Dom Updates In Component LifeCycle: • Changing elements after DOM elements are rendered causes reflows, resulting in slowing down of the application. Write code that avoids DOM read/writes. • If required, add CSS classes and set styles in beforerender event handler rather than afterrender. • For some code, we may need to acquire the element size. If this is the case, then consider handling the ‘boxready’ event. For example: if ( height of element > 100px ) { //do something }
  • 28. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. Tracing : • Use Ext.getDisplayName(). For example: throw new Error('['+ Ext.getDisplayName(arguments.callee) +'] Some message here'); • Check call stack.
  • 29. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. Logging : • Use Ext.log compared to console.log. If console is present, it will be used. In other cases, the message is logged to an array: "Ext.log.out“ An attached debugger can watch this array and view the log. The log buffer is limited to a maximum of "Ext.log.max" entries (defaults to 250). • Debugging statements like console.log() and debugger should never be shipped into standard production environments. INCORRECT CORRECT
  • 30. Copyright © Walking Tree Consultancy Services Pvt. Ltd.Copyright © Walking Tree Consultancy Services Pvt. Ltd. • Use the <debug> tag. • Ext JS 5.x provides “debugHooks” config for a class, through which you can write debugging statements.
  • 31. Form Validation & Submission 31
  • 32. Copyright © 2008 Walking Tree Consultancy Services . All rights reserved. • Use models for validating and submitting the forms and push the field validation logic (including custom validations) inside models. • Use loadRecord method of the FormPanel. • Instead of using explicit logic to enable / disable a submit button, make use of “formBind: true”.
  • 34. Copyright © 2008 Walking Tree Consultancy Services . All rights reserved. Global Variables: • Variables declared outside a function are considered in global scope – irrespective of the usage of “var” keyword. • These variables are in global “window” namespace. For example, the following are same: var gCompanyName = “Walking Tree”; window.companyName = “Walking Tree”; //more explicit • If you want to define global variables then use them inside application namespace. For example: Ext.define( ‘MyApp.util.Constants’,{ singleton : true, ANIMATION_Time : 100, // more variables and methods });
  • 35. Copyright © 2008 Walking Tree Consultancy Services . All rights reserved. • Consider saving the “this” scope into a different (and smaller) name (e.g. me). For example, Ext.define(‘MyApp.view.MyPanel’,{ initComponent : function () { var me=this; me.add () { xtype : ‘button’, handler: function () { this.getHeight(); me.getTitle(); } me.callParent( arguments ); } });
  • 36. Copyright © 2008 Walking Tree Consultancy Services . All rights reserved. Upcoming Online Training On Best Practices and Coding Guidelines on: 28th Nov’, 2015 For details contact: Ratan Agarwal cel: +91 95 81400033