diff --git a/README.md b/README.md index 5ed537f..d52683e 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,8 @@ Supported options (all optional): - **addChild** (`Function(parentNode, childNode)`) - Called when adding a new child to a parent. By default, `parentNode.appendChild(childNode)` is invoked. Use this callback to customize how a new child is added. - **onBeforeNodeAdded** (`Function(node)`) - Called before a `Node` in the `to` tree is added to the `from` tree. If this function returns `false` then the node will not be added. Should return the node to be added. - **onNodeAdded** (`Function(node)`) - Called after a `Node` in the `to` tree has been added to the `from` tree. -- **onBeforeElUpdated** (`Function(fromEl, toEl)`) - Called before a `HTMLElement` in the `from` tree is updated. If this function returns `false` then the element will not be updated. +- **onBeforeElUpdated** (`Function(fromEl, toEl)`) - Called before a `HTMLElement` in the `from` tree is updated. If this function returns `false` then the element will not be updated. Also its children won't be processed. +- **onBeforeElAttrsUpdated** (`Function(fromEl, toEl)`) - Called before a `HTMLElement` in the `from` tree is updated. If this function returns `false` then the element will not be updated. Its children will still be processed. - **onElUpdated** (`Function(el)`) - Called after a `HTMLElement` in the `from` tree has been updated. - **onBeforeNodeDiscarded** (`Function(node)`) - Called before a `Node` in the `from` tree is discarded. If this function returns `false` then the node will not be discarded. - **onNodeDiscarded** (`Function(node)`) - Called after a `Node` in the `from` tree has been discarded. diff --git a/src/morphdom.js b/src/morphdom.js index 19c80d6..1d284b0 100644 --- a/src/morphdom.js +++ b/src/morphdom.js @@ -39,6 +39,7 @@ export default function morphdomFactory(morphAttrs) { var onBeforeNodeAdded = options.onBeforeNodeAdded || noop; var onNodeAdded = options.onNodeAdded || noop; var onBeforeElUpdated = options.onBeforeElUpdated || noop; + var onBeforeElAttrsUpdated = options.onBeforeElAttrsUpdated || noop; var onElUpdated = options.onElUpdated || noop; var onBeforeNodeDiscarded = options.onBeforeNodeDiscarded || noop; var onNodeDiscarded = options.onNodeDiscarded || noop; @@ -211,8 +212,11 @@ export default function morphdomFactory(morphAttrs) { return; } - // update attributes on original DOM element first - morphAttrs(fromEl, toEl); + if (onBeforeElAttrsUpdated(fromEl, toEl) !== false) { + // update attributes on original DOM element first + morphAttrs(fromEl, toEl); + } + // optional onElUpdated(fromEl);