From 584329a98962ca4305f718f137397bde5b6ae042 Mon Sep 17 00:00:00 2001 From: Corin Langosch Date: Fri, 28 Jul 2023 21:00:24 +0000 Subject: [PATCH 1/2] Add onBeforeElAttrsUpdated which allows to skip updating an element itself but still process its children --- src/morphdom.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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); From 6d07ab49edbd3ecd13cf0164fb06f003526b0168 Mon Sep 17 00:00:00 2001 From: Corin Langosch Date: Fri, 28 Jul 2023 21:07:18 +0000 Subject: [PATCH 2/2] Updates readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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.