+ All Categories
Home > Technology > MVC In Depth, part 2, Tommy Maintz

MVC In Depth, part 2, Tommy Maintz

Date post: 31-May-2015
Category:
Upload: sencha
View: 4,891 times
Download: 1 times
Share this document with a friend
Description:
A two-part journey through the recommended patterns for building complex, Model-View-Controller-centric applications with both Ext JS 4 and Sencha Touch.Tommy Maintz is the original lead of Sencha Touch. With extensive knowledge of Object Oriented JavaScript and mobile browser idiosyncrasies, he pushes the boundaries of what is possible within mobile browsers. Tommy brings a unique view point and an ambitious philosophy to creating engaging user interfaces. His attention to detail drives his desire to make the perfect framework for developers to enjoy.
Popular Tags:
40
Wednesday, November 2, 11
Transcript
Page 1: MVC In Depth, part 2, Tommy Maintz

Wednesday, November 2, 11

Page 2: MVC In Depth, part 2, Tommy Maintz

Tommy MaintzMVC IN DEPTH, PT2

[email protected] @tmaintz

Wednesday, November 2, 11

Page 3: MVC In Depth, part 2, Tommy Maintz

Benefits of MVCScalabilityMaintainabilityFlexibility

Wednesday, November 2, 11

Page 4: MVC In Depth, part 2, Tommy Maintz

Learned So FarBasic MVC conceptsStarting the applicationDefining viewsSetting up view listenersImplementing basic controller actions

Wednesday, November 2, 11

Page 5: MVC In Depth, part 2, Tommy Maintz

A Progression

Wednesday, November 2, 11

Page 6: MVC In Depth, part 2, Tommy Maintz

Server-Side MVCMulti-pagePage equals to controller actionDispatching

Wednesday, November 2, 11

Page 7: MVC In Depth, part 2, Tommy Maintz

Client-Side MVCSingle pageUser Interactions equal to controller actionMultiple active controllers

Wednesday, November 2, 11

Page 8: MVC In Depth, part 2, Tommy Maintz

EVENTS ARE THE WAY TO GO

Wednesday, November 2, 11

Page 9: MVC In Depth, part 2, Tommy Maintz

Benefits Of EventsDecoupling of views and controllersMultiple controllers can listenFamiliar to web developers

Wednesday, November 2, 11

Page 10: MVC In Depth, part 2, Tommy Maintz

VIEW EVENTS

Wednesday, November 2, 11

Page 11: MVC In Depth, part 2, Tommy Maintz

View - Controller Relation

View Controller ActionEvent

Wednesday, November 2, 11

Page 12: MVC In Depth, part 2, Tommy Maintz

this.listPanel = this.render({ xtype: 'contact-listpanel', listeners: { list: { select: this.show, scope: this }, activate : function(listPanel) { listPanel.list.getSelectionModel() .deselectAll(); } }});

this.listPanel.query('#addButton')[0].on({ tap: this.compose, scope: this});

Wednesday, November 2, 11

Page 13: MVC In Depth, part 2, Tommy Maintz

this.control({ 'contact-listpanel': { activate: this.onListActivate }, 'contact-listpanel > list': { select: this.onListSelect }, 'button[action=addcontact]': { tap: this.onAddButtonTap }});

Wednesday, November 2, 11

Page 14: MVC In Depth, part 2, Tommy Maintz

APPLICATION EVENTS

Wednesday, November 2, 11

Page 15: MVC In Depth, part 2, Tommy Maintz

The Problem:Single page applicationMany controllers

Wednesday, November 2, 11

Page 16: MVC In Depth, part 2, Tommy Maintz

Multiple Dispatches

Dispatch

View

Controlleraction

Controlleraction

Controlleraction

Dispatch

Dispatch

Wednesday, November 2, 11

Page 17: MVC In Depth, part 2, Tommy Maintz

Chained Dispatches

Dispatch

View

Controlleraction

Controlleraction

Controlleraction

DispatchDispatch

Wednesday, November 2, 11

Page 18: MVC In Depth, part 2, Tommy Maintz

Event Bus

Dispatc

h

View

Controlleraction

Controlleraction

Controlleraction

Fire

Event Bus

EventEvent

Wednesday, November 2, 11

Page 19: MVC In Depth, part 2, Tommy Maintz

BEST SOLUTION: EVENT BUS

Wednesday, November 2, 11

Page 20: MVC In Depth, part 2, Tommy Maintz

Controller A

Wednesday, November 2, 11

Page 21: MVC In Depth, part 2, Tommy Maintz

Controller B

Wednesday, November 2, 11

Page 22: MVC In Depth, part 2, Tommy Maintz

REFERENCES

Wednesday, November 2, 11

Page 23: MVC In Depth, part 2, Tommy Maintz

refs: [{ ref : 'deleteButton', selector: 'button[action=deletecontact]' }], onContactSelect: function() { var deleteButton = this.getDeleteButton(); deleteButton.show(); }

refs: [{ ref : 'deleteButton', selector: 'button[action=deletecontact]' }], onContactSelect: function() { var deleteButton = this.getDeleteButton(); if (deleteButton) { deleteButton.show(); } }

Wednesday, November 2, 11

Page 24: MVC In Depth, part 2, Tommy Maintz

refs: [{ ref : 'newContactWindow', selector: 'window[role=newcontact]', autoCreate: true, // Normal component configuration, role: 'newcontact', xtype: 'window', title: 'Create new Contact', ... }], onAddContactButtonTap: function() { this.getNewContactWindow().show(); }

Wednesday, November 2, 11

Page 25: MVC In Depth, part 2, Tommy Maintz

refs: [{ ref : 'blogPostTab', forceCreate: true, // Normal component configuration, xtype: 'panel', title: 'New Tab' ... }], onBlogPostTap: function(blogPost) { var newTab = this.getBlogPostTab(), tabPanel = this.getTabPanel(); newTab.setTitle(blogPost.getTitle()); newTab.setHtml(blogPost.getContent()); tabPanel.add(newTab); tabPanel.setActiveItem(newTab); }

Wednesday, November 2, 11

Page 26: MVC In Depth, part 2, Tommy Maintz

VIEW LOGIC?

Wednesday, November 2, 11

Page 27: MVC In Depth, part 2, Tommy Maintz

Why Extend a ViewCustom view behaviorFiring custom view events

Wednesday, November 2, 11

Page 28: MVC In Depth, part 2, Tommy Maintz

LOADING CONTROLLERS

Wednesday, November 2, 11

Page 29: MVC In Depth, part 2, Tommy Maintz

getController(name)Loads if doesn’t existCalls init()Calls launch()

Wednesday, November 2, 11

Page 30: MVC In Depth, part 2, Tommy Maintz

controller = this.getController(‘MyController’);

Wednesday, November 2, 11

Page 31: MVC In Depth, part 2, Tommy Maintz

INIT VS LAUNCH

Wednesday, November 2, 11

Page 32: MVC In Depth, part 2, Tommy Maintz

this.init.call(this.scope || this);

for (i = 0; i < ln; i++) { controller = this.getController(controllers[i], false); controller.init();}

this.launch.call(this.scope || this);

this.controllers.each(function(controller) { controller.launch(this);}, this);

this.fireEvent('launch', this);

Wednesday, November 2, 11

Page 33: MVC In Depth, part 2, Tommy Maintz

APPLICATION INITGlobal view eventsGlobal navigation eventsGlobal store events

Wednesday, November 2, 11

Page 34: MVC In Depth, part 2, Tommy Maintz

CONTROLLER INITSpecific view eventsSpecific application eventsSpecific store events

Wednesday, November 2, 11

Page 35: MVC In Depth, part 2, Tommy Maintz

APPLICATION LAUNCHCreating the viewportManipulate viewsLoad data into stores

Wednesday, November 2, 11

Page 36: MVC In Depth, part 2, Tommy Maintz

CONTROLLER LAUNCHCreating & adding viewsManipulate viewsLoad data into stores

Wednesday, November 2, 11

Page 37: MVC In Depth, part 2, Tommy Maintz

COMING SOON!

Wednesday, November 2, 11

Page 38: MVC In Depth, part 2, Tommy Maintz

ROUTES &DEEP LINKING

Wednesday, November 2, 11

Page 39: MVC In Depth, part 2, Tommy Maintz

HISTORY SUPPORT

Wednesday, November 2, 11

Page 40: MVC In Depth, part 2, Tommy Maintz

QUESTIONS?

Wednesday, November 2, 11


Recommended