Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented 'destroy()' propagating to all appended agility objects #58

Merged
merged 2 commits into from
Nov 19, 2011
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions agility.js
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,11 @@

// Triggered upon removing self
_destroy: function(event){
// destroy all the children prior to destroying self
this._container.each(function(){
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this._container.empty() do the trick too?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sir! My tests pass.

this.destroy();
});
// destroy self
this.view.$().remove();
},

Expand Down
35 changes: 35 additions & 0 deletions test/public/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,41 @@
equals( ob.view.$( 'span' ).last().html(), 'postHookEventLastLast', 'last postHook event fired last');
});

test("Destroy propagates to children", function() {
var destroyTriggered = false;
var childDestroyTriggered = false;
var grandchildDestroyTriggered = false;
var greatgrandchildDestroyTriggered = false;
var obj = $$({}, '<div/>', {
'destroy': function() {
destroyTriggered = true;
}
});
var child = $$({}, '<div/>', {
'destroy': function() {
childDestroyTriggered = true;
}
});
var grandchild = $$({}, '<div/>', {
'destroy': function() {
grandchildDestroyTriggered = true;
}
});
var greatgrandchild = $$({}, '<div/>', {
'destroy': function() {
greatgrandchildDestroyTriggered = true;
}
});
obj.append( child );
child.append( grandchild );
grandchild.append( greatgrandchild );
obj.destroy();
ok(destroyTriggered, "destroy triggered");
ok(childDestroyTriggered, "child destroy triggered");
ok(grandchildDestroyTriggered, "grandchild destroy triggered");
ok(greatgrandchildDestroyTriggered, "great grandchild destroy triggered");
});

test("Extend controller syntax from four arguments (prototype, model, view, controller object)", function() {
var lbl = $$({}, '<span data-bind="label"/>');
var partial = $$({}, '<div/>', {
Expand Down