SlideShare a Scribd company logo
Sencha ExtJs Learning[part 2]
MVC And MVVM Architecture in ExtJs
by Irfan Maulana
MVC & MVVM
MVC (Model-View-Controller) is used by ExtJs 4.x.x or below version.
MVVM (Model-View-ViewModel) is used by ExtJs from version 5.
The key of different is ViewModel that used for data binding system.
MODEL
Model is like structure of table in Databases.
Model represent data-index and type of data will be shown.
Model normally used in store to provide data.
// sample usage
Ext.define('User', {
extend: 'Ext.data.Model',
fields: [
{name: 'name', type: 'string'},
{name: 'age', type: 'int'},
{name: 'phone', type: 'string'},
{name: 'alive', type: 'boolean'}
]
});
STORE
The Store class encapsulates a client side cache of Model objects.
Stores load data via a Proxy, and also provide functions for sorting, filtering
and querying the model instances contained within it.
// sample usage
var myStore = Ext.create('Ext.data.Store', {
model: 'User',
autoLoad: true,
proxy: {
type: 'ajax',
url: '/users.json',
reader: {
type: 'json',
root: 'users'
}
},
});
MODEL AND STORE
One instance of model can be used by many store as you need.
This will not affect to your data.
But when you use one store for many component, this will affect to your data.
When data store changed, will be affected to all component that used it.
But for some reason you will need this behavior, do as you need.
VIEW
View is component that will be shown to user.
View can be some container or component like grid, panel, combo, window, etc.
// sample usage
Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{ text: 'Name', dataIndex: 'name' },
{ text: 'Email', dataIndex: 'email', flex: 1 },
{ text: 'Phone', dataIndex: 'phone' }
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});
CONTROLLER
Controller is application controller.
Include Global Model, Global Store, and Global View registration here.
for private Model, Store and View use requires.
this will only loaded when needed.
Controller is listen for events (usually from views) and take some action (in
ExtJs 5 move to ViewController).
// sample usage
Ext.define('MyApp.controller.Users', {
extend: 'Ext.app.Controller',
init: function() {
}
});
VIEW CONTROLLER
Only for ExtJs 5 above.
Every view has single controller that listen even from view.
This will be more modular and manageable view.
// sample usage
Ext.define('MyApp.view.foo.FooController', {
extend: 'Ext.app.ViewController',
alias: 'controller.foo',
onBarChange: function (barTextField) {
// called by 'change' event
}
});
VIEW MODEL
The ViewModel is a class that manages data specific to the View.
It allows interested components to bind to it and be updated whenever this
data changes.
// sample usage
Ext.define('MyApp.view.TestViewModel2', {
extend: 'Ext.app.ViewModel',
alias: 'viewmodel.test2',
formulas: {
x2: function (get) {
return get('x') * 2;
}
}
});
CONFIG CLASS
Config class is used for avoid too much global variable usage.
It's give you getter-setter behavior like Java done.
// sample usage
Ext.define('TEST.config.GlobalVariable',{
singleton : true,
config : {
isNewDashlite : true,
dashliteObject : null,
},
constructor : function(config){
this.initConfig(config);
}
});
HOW YOUR ARCHITECTURE WORK ?
+ Fisrt app.js will call Application.js (when use senchaCmd: config here).
+ in Application.js you defined mainController and mainView can be launch
here.
// sample Application.js
Ext.define('TNMD.Application', {
extend: 'Ext.app.Application',
name: 'TNMD',
requires : ['TNMD.config.GlobalVariable'], // this is our cofig class. please see my example config.class
controllers: [ 'AppController'], // this is our mainController
launch: function () {
Ext.create('Ext.container.Viewport', {
layout: 'fit',
items: [{ xtype: 'mainView' }] // this is our mainView
});
}
});
HOW YOUR ARCHITECTURE WORK ?
+ Make your controller to load mainView. (just one view, other view using
requires)
+ You can include model and store here, but dont use autoload:true for your
store.
+ Using manual load is more safety, except data for combo.
// sample controller
Ext.define('TNMD.controller.AppController', {
extend: 'Ext.app.Controller',
models: [], //global model
stores: [],
views : ['TNMD.view.MainView' ], // this is our mainView. when you include here will autoload.
init: function() {
this.control({
});
}
});
HOW YOUR ARCHITECTURE WORK ?
+ Make your controller to load mainView. (just one view, other view using
requires)
+ You can include model and store here, but dont use autoload:true for your
store.
+ Using manual load is more safety, except data for combo.
// sample mainView
Ext.define('TNMD.view.MainView', {
extend: 'Ext.container.Container',
xtype: 'mainView',
itemId: 'mainView',
requires: [ 'TNMD.viewController.MainController', 'TNMD.view.FilterPanel', 'TNMD.view.ContentPanel'],
controller: 'mainController', //this is our view Controller
layout : 'border',
listeners:{afterrender: ‘onAfterRender’} //call event in ViewController
items:[{xtype : 'filterPanel', region : 'west', width : 250,},
{xtype : 'contentPanel', region : 'center',}]
});
HOW YOUR ARCHITECTURE WORK ?
+ Listing all event from view in viewController.
// sample of mainViewController
Ext.define('TNMD.viewController.MainController', {
extend: 'Ext.app.ViewController',
alias: 'controller.mainController',
onAfterRender: function(){
alert(“call after render”);
}
});
Contact me on :
Email : mazipanneh@gmail.com
Blog : mazipanneh.wordpress.com
Thanks for your attention.
Presented by : Irfan Maulana

More Related Content

PPTX
Clean Code
PPTX
Component interface
PDF
Dinero y sistema bancario
PDF
Psi-mod-13
PPTX
Banco de Dados - Sistemas de Gerenciamento de Banco de Dados
PDF
Kata: Hexagonal Architecture / Ports and Adapters
PDF
Introduction To Angular's reactive forms
PDF
[TECHCON 2019: MOBILE - Android]3.안드로이드 개발자 로드맵
Clean Code
Component interface
Dinero y sistema bancario
Psi-mod-13
Banco de Dados - Sistemas de Gerenciamento de Banco de Dados
Kata: Hexagonal Architecture / Ports and Adapters
Introduction To Angular's reactive forms
[TECHCON 2019: MOBILE - Android]3.안드로이드 개발자 로드맵

Viewers also liked (18)

PPTX
Sencha ExtJs Learning Part 1 - Layout And Container in Sencha ExtJs - By Irfa...
PPTX
Php Indonesia x Bliblidotcom - Architecting Scalable CSS
PDF
CP 值很高的 Gulp
PDF
Introduction to ExtJs 5
PPTX
Ext JS Presentation
PPTX
Ext Js introduction and new features in Ext Js 6
PPT
CSS Frameworks: Faster Layout, Consistent Results
PDF
Ext js 6
PPTX
Journey To The Front End World - Part2 - The Cosmetic
PDF
conjoon - The Open Source Webmail Client
PPTX
Bliblidotcom - SASS Introduction
PPTX
Basics of Ext JS
PPTX
Journey To The Front End World - Part3 - The Machine
PPS
email clients and webmail (presentation)
PPTX
Journey To The Front End World - Part1 - The Skeleton
PPTX
Guidelines and Best Practices for Sencha Projects
Sencha ExtJs Learning Part 1 - Layout And Container in Sencha ExtJs - By Irfa...
Php Indonesia x Bliblidotcom - Architecting Scalable CSS
CP 值很高的 Gulp
Introduction to ExtJs 5
Ext JS Presentation
Ext Js introduction and new features in Ext Js 6
CSS Frameworks: Faster Layout, Consistent Results
Ext js 6
Journey To The Front End World - Part2 - The Cosmetic
conjoon - The Open Source Webmail Client
Bliblidotcom - SASS Introduction
Basics of Ext JS
Journey To The Front End World - Part3 - The Machine
email clients and webmail (presentation)
Journey To The Front End World - Part1 - The Skeleton
Guidelines and Best Practices for Sencha Projects
Ad

Similar to Sencha ExtJs Learning Part 2 - MVC And MVVM Architecture in ExtJs [ENGLISH] (20)

PPTX
Ext JS Introduction
PPTX
Sencha Touch - Introduction
ODP
ExtJS framework
PPTX
MVC In Sencha Touch
PPTX
Ext JS Architecture Best Practices - Mitchell Simeons
PPTX
Sencha / ExtJS : Object Oriented JavaScript
KEY
Ext js 4 MVC
PPTX
SenchaCon 2016: Handle Real-World Data with Confidence - Fredric Berling
PDF
Aprimorando sua Aplicação com Ext JS 4 - BrazilJS
PDF
Building a Mobile App with Sencha Touch
PPTX
Building Rich Internet Applications with Ext JS
PDF
Create a mobile web app with Sencha Touch
PDF
Sencha touch application v2.00
PDF
A mobile web app for Android in 75 minutes
PDF
Architecting your app in ext js 4, part 1 learn sencha
PDF
The City Bars App with Sencha Touch 2
PPTX
SenchaCon 2016: The Once and Future Grid - Nige White
PDF
What's Coming Next in Sencha Frameworks
PPT
ExtjsPart1
PDF
Ext JS in Action 1st Edition Jesus Garcia
Ext JS Introduction
Sencha Touch - Introduction
ExtJS framework
MVC In Sencha Touch
Ext JS Architecture Best Practices - Mitchell Simeons
Sencha / ExtJS : Object Oriented JavaScript
Ext js 4 MVC
SenchaCon 2016: Handle Real-World Data with Confidence - Fredric Berling
Aprimorando sua Aplicação com Ext JS 4 - BrazilJS
Building a Mobile App with Sencha Touch
Building Rich Internet Applications with Ext JS
Create a mobile web app with Sencha Touch
Sencha touch application v2.00
A mobile web app for Android in 75 minutes
Architecting your app in ext js 4, part 1 learn sencha
The City Bars App with Sencha Touch 2
SenchaCon 2016: The Once and Future Grid - Nige White
What's Coming Next in Sencha Frameworks
ExtjsPart1
Ext JS in Action 1st Edition Jesus Garcia
Ad

More from Irfan Maulana (16)

PPTX
Modern Web - an Introduction
PDF
Unit Testing for Frontend Code at Blibli.com
PPTX
Programmer In Startup Era
PPTX
Bliblidotcom - Evolusi Frontend Development di Bliblidotcom
PPTX
Bliblidotcom - Tech In Asia PDC 2017 Takeaway
PPTX
Bliblidotcom - AMP And PWA
PPTX
Angular - The Return of The King
PPTX
How to Become Rockstar Programmer
PPTX
Bliblidotcom - AngularJS Introduction
PPTX
Bliblidotcom - Reintroduction BEM CSS
PPTX
PHP Indonesia - Understanding UI UX from Developer Side
PPTX
JakartaJS - How I Learn Javascript From Basic
PPTX
PHP Indonesia - Nodejs Web Development
PPTX
[Blibli Brown Bag] Nodejs - The Other Side of Javascript
PPTX
Create Rest API in Nodejs
PPTX
Irfan Maulana - Career Journey
Modern Web - an Introduction
Unit Testing for Frontend Code at Blibli.com
Programmer In Startup Era
Bliblidotcom - Evolusi Frontend Development di Bliblidotcom
Bliblidotcom - Tech In Asia PDC 2017 Takeaway
Bliblidotcom - AMP And PWA
Angular - The Return of The King
How to Become Rockstar Programmer
Bliblidotcom - AngularJS Introduction
Bliblidotcom - Reintroduction BEM CSS
PHP Indonesia - Understanding UI UX from Developer Side
JakartaJS - How I Learn Javascript From Basic
PHP Indonesia - Nodejs Web Development
[Blibli Brown Bag] Nodejs - The Other Side of Javascript
Create Rest API in Nodejs
Irfan Maulana - Career Journey

Recently uploaded (20)

PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Machine learning based COVID-19 study performance prediction
PPTX
Big Data Technologies - Introduction.pptx
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
Encapsulation_ Review paper, used for researhc scholars
The Rise and Fall of 3GPP – Time for a Sabbatical?
Spectral efficient network and resource selection model in 5G networks
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Unlocking AI with Model Context Protocol (MCP)
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Network Security Unit 5.pdf for BCA BBA.
MYSQL Presentation for SQL database connectivity
Machine learning based COVID-19 study performance prediction
Big Data Technologies - Introduction.pptx
sap open course for s4hana steps from ECC to s4
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Review of recent advances in non-invasive hemoglobin estimation
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm

Sencha ExtJs Learning Part 2 - MVC And MVVM Architecture in ExtJs [ENGLISH]

  • 1. Sencha ExtJs Learning[part 2] MVC And MVVM Architecture in ExtJs by Irfan Maulana
  • 2. MVC & MVVM MVC (Model-View-Controller) is used by ExtJs 4.x.x or below version. MVVM (Model-View-ViewModel) is used by ExtJs from version 5. The key of different is ViewModel that used for data binding system.
  • 3. MODEL Model is like structure of table in Databases. Model represent data-index and type of data will be shown. Model normally used in store to provide data. // sample usage Ext.define('User', { extend: 'Ext.data.Model', fields: [ {name: 'name', type: 'string'}, {name: 'age', type: 'int'}, {name: 'phone', type: 'string'}, {name: 'alive', type: 'boolean'} ] });
  • 4. STORE The Store class encapsulates a client side cache of Model objects. Stores load data via a Proxy, and also provide functions for sorting, filtering and querying the model instances contained within it. // sample usage var myStore = Ext.create('Ext.data.Store', { model: 'User', autoLoad: true, proxy: { type: 'ajax', url: '/users.json', reader: { type: 'json', root: 'users' } }, });
  • 5. MODEL AND STORE One instance of model can be used by many store as you need. This will not affect to your data. But when you use one store for many component, this will affect to your data. When data store changed, will be affected to all component that used it. But for some reason you will need this behavior, do as you need.
  • 6. VIEW View is component that will be shown to user. View can be some container or component like grid, panel, combo, window, etc. // sample usage Ext.create('Ext.grid.Panel', { title: 'Simpsons', store: Ext.data.StoreManager.lookup('simpsonsStore'), columns: [ { text: 'Name', dataIndex: 'name' }, { text: 'Email', dataIndex: 'email', flex: 1 }, { text: 'Phone', dataIndex: 'phone' } ], height: 200, width: 400, renderTo: Ext.getBody() });
  • 7. CONTROLLER Controller is application controller. Include Global Model, Global Store, and Global View registration here. for private Model, Store and View use requires. this will only loaded when needed. Controller is listen for events (usually from views) and take some action (in ExtJs 5 move to ViewController). // sample usage Ext.define('MyApp.controller.Users', { extend: 'Ext.app.Controller', init: function() { } });
  • 8. VIEW CONTROLLER Only for ExtJs 5 above. Every view has single controller that listen even from view. This will be more modular and manageable view. // sample usage Ext.define('MyApp.view.foo.FooController', { extend: 'Ext.app.ViewController', alias: 'controller.foo', onBarChange: function (barTextField) { // called by 'change' event } });
  • 9. VIEW MODEL The ViewModel is a class that manages data specific to the View. It allows interested components to bind to it and be updated whenever this data changes. // sample usage Ext.define('MyApp.view.TestViewModel2', { extend: 'Ext.app.ViewModel', alias: 'viewmodel.test2', formulas: { x2: function (get) { return get('x') * 2; } } });
  • 10. CONFIG CLASS Config class is used for avoid too much global variable usage. It's give you getter-setter behavior like Java done. // sample usage Ext.define('TEST.config.GlobalVariable',{ singleton : true, config : { isNewDashlite : true, dashliteObject : null, }, constructor : function(config){ this.initConfig(config); } });
  • 11. HOW YOUR ARCHITECTURE WORK ? + Fisrt app.js will call Application.js (when use senchaCmd: config here). + in Application.js you defined mainController and mainView can be launch here. // sample Application.js Ext.define('TNMD.Application', { extend: 'Ext.app.Application', name: 'TNMD', requires : ['TNMD.config.GlobalVariable'], // this is our cofig class. please see my example config.class controllers: [ 'AppController'], // this is our mainController launch: function () { Ext.create('Ext.container.Viewport', { layout: 'fit', items: [{ xtype: 'mainView' }] // this is our mainView }); } });
  • 12. HOW YOUR ARCHITECTURE WORK ? + Make your controller to load mainView. (just one view, other view using requires) + You can include model and store here, but dont use autoload:true for your store. + Using manual load is more safety, except data for combo. // sample controller Ext.define('TNMD.controller.AppController', { extend: 'Ext.app.Controller', models: [], //global model stores: [], views : ['TNMD.view.MainView' ], // this is our mainView. when you include here will autoload. init: function() { this.control({ }); } });
  • 13. HOW YOUR ARCHITECTURE WORK ? + Make your controller to load mainView. (just one view, other view using requires) + You can include model and store here, but dont use autoload:true for your store. + Using manual load is more safety, except data for combo. // sample mainView Ext.define('TNMD.view.MainView', { extend: 'Ext.container.Container', xtype: 'mainView', itemId: 'mainView', requires: [ 'TNMD.viewController.MainController', 'TNMD.view.FilterPanel', 'TNMD.view.ContentPanel'], controller: 'mainController', //this is our view Controller layout : 'border', listeners:{afterrender: ‘onAfterRender’} //call event in ViewController items:[{xtype : 'filterPanel', region : 'west', width : 250,}, {xtype : 'contentPanel', region : 'center',}] });
  • 14. HOW YOUR ARCHITECTURE WORK ? + Listing all event from view in viewController. // sample of mainViewController Ext.define('TNMD.viewController.MainController', { extend: 'Ext.app.ViewController', alias: 'controller.mainController', onAfterRender: function(){ alert(“call after render”); } });
  • 15. Contact me on : Email : mazipanneh@gmail.com Blog : mazipanneh.wordpress.com Thanks for your attention. Presented by : Irfan Maulana