Permalink
Browse files

Fixed ViewController cleanup issue reported w/Sencha Touch

Deft.mvc.ViewController::onViewDestroyed() is never called on Sencha Touch (due to the differing destruction lifecycle path). Consequently, the cleanup logic implemented there is not executed on that platform.
Moved the clean-up logic to the destroy() method. This will require any subclasses to call `this.callParent()`, but that should be fairly well understood as a standard practice when overriding destroy() method.
Added associated unit tests to help prevent future regression.

Fixes #45
  • Loading branch information...
1 parent a29fb9a commit a5cd77603e48eb36341e13d049c23299e56e67dc @johnyanarella johnyanarella committed Aug 10, 2012
View
@@ -881,6 +881,13 @@ Ext.define('Deft.mvc.ViewController', {
*/
destroy: function() {
+ var id, selector;
+ for (id in this.registeredComponentReferences) {
+ this.removeComponentReference(id);
+ }
+ for (selector in this.registeredComponentSelectors) {
+ this.removeComponentSelector(selector);
+ }
return true;
},
/**
@@ -891,9 +898,6 @@ Ext.define('Deft.mvc.ViewController', {
var config, id, listeners, live, originalViewDestroyFunction, selector, self, _ref;
if (Ext.getVersion('extjs') != null) {
this.getView().on('beforedestroy', this.onViewBeforeDestroy, this);
- this.getView().on('destroy', this.onViewDestroy, this, {
- single: true
- });
} else {
self = this;
originalViewDestroyFunction = this.getView().destroy;
@@ -942,19 +946,6 @@ Ext.define('Deft.mvc.ViewController', {
return false;
},
/**
- @private
- */
-
- onViewDestroy: function() {
- var id, selector;
- for (id in this.registeredComponentReferences) {
- this.removeComponentReference(id);
- }
- for (selector in this.registeredComponentSelectors) {
- this.removeComponentSelector(selector);
- }
- },
- /**
Add a component accessor method the ViewController for the specified view-relative selector.
*/
View

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1538,7 +1538,7 @@ describe( 'Deft.mvc.ViewController', ->
return
)
- it( 'should remove event listeners it attached to a view component referenced implicitly by item id when the associated view (and view controller) is destroyed', ->
+ it( 'should remove event listeners it attached to a view component referenced implicitly by itemId when the associated view (and view controller) is destroyed', ->
Ext.define( 'ExampleViewController',
extend: 'Deft.mvc.ViewController'
@@ -1560,6 +1560,8 @@ describe( 'Deft.mvc.ViewController', ->
component = view.query( '#example' )[ 0 ]
+ expect( viewController.getExample ).not.toBe( null )
+
expect( hasListener( component, 'exampleevent' ) ).toBe( true )
spyOn( viewController, 'destroy' ).andCallThrough()
@@ -1569,6 +1571,7 @@ describe( 'Deft.mvc.ViewController', ->
view.destroy()
expect( viewController.destroy ).toHaveBeenCalled()
+ expect( viewController.getExample ).toBe( null )
expect( isViewDestroyed ).toBe( true )
expect( hasListener( component, 'exampleevent' ) ).toBe( false )
@@ -1610,6 +1613,8 @@ describe( 'Deft.mvc.ViewController', ->
components = view.query( 'example' )
+ expect( viewController.getExample ).not.toBe( null )
+
for component in components
expect( hasListener( component, 'exampleevent' ) ).toBe( true )
@@ -1620,6 +1625,7 @@ describe( 'Deft.mvc.ViewController', ->
view.destroy()
expect( viewController.destroy ).toHaveBeenCalled()
+ expect( viewController.getExample ).toBe( null )
expect( isViewDestroyed ).toBe( true )
for component in components
@@ -1628,7 +1634,7 @@ describe( 'Deft.mvc.ViewController', ->
return
)
- it( 'should remove event listeners it attached to a dynamic view component referenced by a live selector implicitly by item id when the associated view (and view controller) is destroyed', ->
+ it( 'should remove event listeners it attached to a dynamic view component referenced by a live selector implicitly by itemId when the associated view (and view controller) is destroyed', ->
Ext.define( 'ExampleViewController',
extend: 'Deft.mvc.ViewController'
@@ -1656,6 +1662,8 @@ describe( 'Deft.mvc.ViewController', ->
}
)
+ expect( viewController.getDynamicExample ).not.toBe( null )
+
expect( hasListener( component, 'exampleevent' ) ).toBe( true )
spyOn( viewController, 'destroy' ).andCallThrough()
@@ -1665,6 +1673,7 @@ describe( 'Deft.mvc.ViewController', ->
view.destroy()
expect( viewController.destroy ).toHaveBeenCalled()
+ expect( viewController.getDynamicExample ).toBe( null )
expect( isViewDestroyed ).toBe( true )
expect( hasListener( component, 'exampleevent' ) ).toBe( false )
@@ -1708,6 +1717,8 @@ describe( 'Deft.mvc.ViewController', ->
]
)
components = view.query( 'example' )
+
+ expect( viewController.getDynamicExample ).not.toBe( null )
expect( viewController.getDynamicExample() ).toEqual( components )
expect( viewController.getDynamicExample().length ).toEqual( 4 )
@@ -1721,6 +1732,7 @@ describe( 'Deft.mvc.ViewController', ->
view.destroy()
expect( viewController.destroy ).toHaveBeenCalled()
+ expect( viewController.getDynamicExample ).toBe( null )
expect( isViewDestroyed ).toBe( true )
for component in components

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -61,6 +61,10 @@ Ext.define( 'Deft.mvc.ViewController',
Destroy the ViewController
###
destroy: ->
+ for id of @registeredComponentReferences
+ @removeComponentReference( id )
+ for selector of @registeredComponentSelectors
+ @removeComponentSelector( selector )
return true
###*
@@ -70,7 +74,6 @@ Ext.define( 'Deft.mvc.ViewController',
if Ext.getVersion( 'extjs' )?
# Ext JS
@getView().on( 'beforedestroy', @onViewBeforeDestroy, @ )
- @getView().on( 'destroy', @onViewDestroy, @, single: true )
else
# Sencha Touch
self = this
@@ -111,16 +114,6 @@ Ext.define( 'Deft.mvc.ViewController',
return false
###*
- @private
- ###
- onViewDestroy: ->
- for id of @registeredComponentReferences
- @removeComponentReference( id )
- for selector of @registeredComponentSelectors
- @removeComponentSelector( selector )
- return
-
- ###*
Add a component accessor method the ViewController for the specified view-relative selector.
###
addComponentReference: ( id, selector, live = false ) ->

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

0 comments on commit a5cd776

Please sign in to comment.