Skip to content

Commit

Permalink
Fixed missing animation hooks in more cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitar committed Dec 31, 2015
1 parent 145b233 commit 0f2f64c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
2 changes: 2 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## vNEXT

* Fixed missing animation hooks in more cases.

## v0.16.1, 2015-Dec-31

* Blaze Components can now process `<body>` tags in the server side templates, and ignore
Expand Down
22 changes: 20 additions & 2 deletions client.coffee
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
propagateUIHooks = (parent, node) ->
return if not parent._uihooks or node._uihooks

node._uihooks = _.extend {}, parent._uihooks, parentNode: node

return unless node.hasChildNodes()

for childNode in node.childNodes when childNode.nodeType is Node.ELEMENT_NODE
propagateUIHooks node, childNode

# To optimize.
return

originalInsertNodeWithHooks = Blaze._DOMRange._insertNodeWithHooks
Blaze._DOMRange._insertNodeWithHooks = (node, parent, next) ->
node._uihooks = _.extend {}, parent._uihooks, parentNode: node unless node._uihooks
propagateUIHooks parent, node
originalInsertNodeWithHooks node, parent, next

originalMoveNodeWithHooks = Blaze._DOMRange._moveNodeWithHooks
Blaze._DOMRange._moveNodeWithHooks = (node, parent, next) ->
node._uihooks = _.extend {}, parent._uihooks, parentNode: node unless node._uihooks
propagateUIHooks parent, node
originalMoveNodeWithHooks node, parent, next

createUIHooks = (component, parentNode) ->
Expand All @@ -26,6 +39,11 @@ Blaze._DOMRange::attach = (parentElement, nextNode, _isMove, _isReplace) ->
for member in @members when member not instanceof Blaze._DOMRange
member._uihooks = createUIHooks component, member

continue unless member.hasChildNodes()

for childNode in member.childNodes when childNode.nodeType is Node.ELEMENT_NODE
propagateUIHooks member, childNode

oldUIHooks = parentElement._uihooks
try
parentElement._uihooks = createUIHooks component, parentElement
Expand Down
2 changes: 1 addition & 1 deletion tests/tests.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -1248,7 +1248,7 @@ class BasicTestCase extends ClassyTestCase
AnimatedListComponent.calls = []

expectedCalls = [
['insertDOMElement', 'AnimatedListComponent', '<div class="animationTestTemplate"></div>', '<ul><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul>', '']
['insertDOMElement', 'AnimatedListComponent', '<div class="animationTestTemplate"></div>', '<div><ul><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul></div>', '']
['removeDOMElement', 'AnimatedListComponent', '<ul><li>1</li><li>2</li><li>3</li><li>4</li><li>5</li></ul>', '<li>1</li>']
['moveDOMElement', 'AnimatedListComponent', '<ul><li>2</li><li>3</li><li>4</li><li>5</li></ul>', '<li>5</li>', '']
['insertDOMElement', 'AnimatedListComponent', '<ul><li>5</li><li>2</li><li>3</li><li>4</li></ul>', '<li>6</li>', '']
Expand Down
17 changes: 11 additions & 6 deletions tests/tests.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,17 @@
</template>

<template name="AnimatedListComponent">
<ul>
{{> DummyComponent}}
{{#each list}}
<li>{{_id}}</li>
{{/each}}
</ul>
<div>
{{#if false}}
{{else}}
<ul>
{{> DummyComponent}}
{{#each list}}
<li>{{_id}}</li>
{{/each}}
</ul>
{{/if}}
</div>
</template>

<template name="DummyComponent">
Expand Down

0 comments on commit 0f2f64c

Please sign in to comment.