From 816555831647a8b26e1968cd6fefdb5b95b3234b Mon Sep 17 00:00:00 2001 From: Tristan Slominski Date: Thu, 17 Nov 2011 09:13:05 -0600 Subject: [PATCH 1/2] Implemented 'destroy()' propagating to all appended agility objects prior to initiating 'destroy' on self --- agility.js | 5 +++++ test/public/core.js | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/agility.js b/agility.js index 0450f1c..62b5e35 100644 --- a/agility.js +++ b/agility.js @@ -660,6 +660,11 @@ // Triggered upon removing self _destroy: function(event){ + // destroy all the children prior to destroying self + this._container.each(function(){ + this.destroy(); + }); + // destroy self this.view.$().remove(); }, diff --git a/test/public/core.js b/test/public/core.js index 47fc305..fadd93d 100644 --- a/test/public/core.js +++ b/test/public/core.js @@ -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 = $$({}, '
', { + 'destroy': function() { + destroyTriggered = true; + } + }); + var child = $$({}, '
', { + 'destroy': function() { + childDestroyTriggered = true; + } + }); + var grandchild = $$({}, '
', { + 'destroy': function() { + grandchildDestroyTriggered = true; + } + }); + var greatgrandchild = $$({}, '
', { + '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 = $$({}, ''); var partial = $$({}, '
', { From 9f9e7524c3f68a75643d008a0aa23c73386c9bab Mon Sep 17 00:00:00 2001 From: Tristan Slominski Date: Sat, 19 Nov 2011 11:05:49 -0600 Subject: [PATCH 2/2] Used this._container.empty() instead of .each() --- agility.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/agility.js b/agility.js index 62b5e35..1f1aedd 100644 --- a/agility.js +++ b/agility.js @@ -660,10 +660,8 @@ // Triggered upon removing self _destroy: function(event){ - // destroy all the children prior to destroying self - this._container.each(function(){ - this.destroy(); - }); + // destroy any appended agility objects + this._container.empty(); // destroy self this.view.$().remove(); },