Permalink
Browse files

Add a few more instances of view.disappear events.

  • Loading branch information...
1 parent 8456776 commit 97af8eef4361f571e42172576bebb9af9ad02967 @nickjs nickjs committed Mar 14, 2012
Showing with 21 additions and 5 deletions.
  1. +10 −4 lib/batman.js
  2. +11 −1 src/batman.coffee
View
14 lib/batman.js
@@ -7398,7 +7398,9 @@
return true;
},
unbindNode: $unbindNode = function(node) {
- var bindings, eventListeners, eventName, listeners;
+ var bindings, eventListeners, eventName, listeners, view;
+ view = Batman.data(node, 'view');
+ if (view != null) view.fire('beforeDisappear', node);
if (bindings = Batman._data(node, 'bindings')) {
bindings.forEach(function(binding) {
return binding.die();
@@ -7413,7 +7415,8 @@
}
}
Batman.removeData(node);
- return Batman.removeData(node, void 0, true);
+ Batman.removeData(node, void 0, true);
+ return view != null ? view.fire('disappear', node) : void 0;
},
unbindTree: $unbindTree = function(node, unbindRoot) {
var child, _j, _len2, _ref2, _results;
@@ -7446,9 +7449,12 @@
}
},
removeNode: $removeNode = function(node) {
- var _ref2;
+ var view, _ref2;
+ view = Batman.data(node, 'view');
+ if (view != null) view.fire('beforeDisappear', node);
if ((_ref2 = node.parentNode) != null) _ref2.removeChild(node);
- return Batman.DOM.didRemoveNode(node);
+ Batman.DOM.didRemoveNode(node);
+ return view != null ? view.fire('disappear', node) : void 0;
},
appendChild: $appendChild = function() {
var args, child, parent, view, _ref2;
View
12 src/batman.coffee
@@ -985,7 +985,7 @@ class BatmanObject extends Object
@accessor: -> @classAccessor.apply @prototype, arguments
# Support adding accessors to instances after creation
accessor: @classAccessor
-
+
wrapSingleAccessor = (core, wrapper) ->
wrapper = wrapper?(core) or wrapper
for k, v of core
@@ -4508,6 +4508,9 @@ Batman.DOM = {
# Removes listeners and bindings tied to `node`, allowing it to be cleared
# or removed without leaking memory
unbindNode: $unbindNode = (node) ->
+ view = Batman.data(node, 'view')
+ view?.fire 'beforeDisappear', node
+
# break down all bindings
if bindings = Batman._data node, 'bindings'
bindings.forEach (binding) -> binding.die()
@@ -4522,6 +4525,8 @@ Batman.DOM = {
Batman.removeData node # external data (Batman.data)
Batman.removeData node, undefined, true # internal data (Batman._data)
+ view?.fire 'disappear', node
+
# Unbinds the tree rooted at `node`.
# When set to `false`, `unbindRoot` skips the `node` before unbinding all of its children.
unbindTree: $unbindTree = (node, unbindRoot = true) ->
@@ -4542,9 +4547,14 @@ Batman.DOM = {
# Memory-safe removal of a node from the DOM
removeNode: $removeNode = (node) ->
+ view = Batman.data(node, 'view')
+ view?.fire 'beforeDisappear', node
+
node.parentNode?.removeChild node
Batman.DOM.didRemoveNode(node)
+ view?.fire 'disappear', node
+
appendChild: $appendChild = (parent, child, args...) ->
view = Batman.data(child, 'view')
view?.fire 'beforeAppear', child

0 comments on commit 97af8ee

Please sign in to comment.