Socket
Socket
Sign inDemoInstall

morphdom

Package Overview
Dependencies
0
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.4 to 0.1.5

test/fixtures/autotest/ids-nested-4/from.html

77

lib/index.js

@@ -31,3 +31,3 @@ var specialAttrHandlers = {

var attrName;
var attrValue;
var foundAttrs = {};

@@ -40,5 +40,8 @@ var tagName = fromNode.tagName;

attrName = attr.name;
var attrValue = attr.value;
attrValue = attr.value;
foundAttrs[attrName] = true;
fromNode.setAttribute(attrName, attrValue);
if (fromNode.getAttribute(attrName) !== attrValue) {
fromNode.setAttribute(attrName, attrValue);
}
invokeSpecialAttrHandler(fromNode, tagName, attrName, attrValue);

@@ -75,3 +78,2 @@ }

function morphdom(fromNode, toNode, options) {
if (!options) {

@@ -83,3 +85,3 @@ options = {};

var unmatchedEls = {};
var onNodeDiscarded = options.onNodeDiscarded || noop; // NOTE: This
var onNodeDiscarded = options.onNodeDiscarded || noop;
var onBeforeMorphEl = options.onBeforeMorphEl || noop;

@@ -110,23 +112,16 @@ var onBeforeMorphElChildren = options.onBeforeMorphElChildren || noop;

function removeNode(node, parentNode, alreadyVisited) {
parentNode.removeChild(node);
if (alreadyVisited) {
walkDiscardedNodes(node);
} else {
removeNodeHelper(node);
}
}
function walkDiscardedNodes(node) {
onNodeDiscarded(node);
function walkDiscardedChildNodes(node) {
if (node.nodeType === 1) {
var curChild = node.firstChild;
while(curChild) {
if (!curChild.id) {
// Stop walking the tree if we found an element with an ID
// since it will be walked separately... we don't want to double
// walk
walkDiscardedNodes(curChild);
// We only want to handle nodes that don't have an ID to avoid double
// walking the same saved element.
onNodeDiscarded(curChild);
// Walk recursively
walkDiscardedChildNodes(curChild);
}

@@ -139,3 +134,22 @@

function removeNode(node, parentNode, alreadyVisited) {
parentNode.removeChild(node);
if (alreadyVisited) {
if (!node.id) {
onNodeDiscarded(node);
walkDiscardedChildNodes(node);
}
} else {
removeNodeHelper(node);
}
}
function morphEl(fromNode, toNode, alreadyVisited) {
if (toNode.id) {
// If an element with an ID is being morphed then it is will be in the final
// DOM so clear it out of the saved elements collection
delete savedEls[toNode.id];
}
if (onBeforeMorphEl(fromNode, toNode) === false) {

@@ -162,16 +176,4 @@ return;

toNextSibling = curToNodeChild.nextSibling;
curToNodeId = curToNodeChild.id;
if (curToNodeId && (savedEl = savedEls[curToNodeId])) {
// We are reusing a "from node" with an ID that matches
// the ID of the current "to node"
delete savedEls[curToNodeId];
fromNode.insertBefore(savedEl, curFromNodeChild);
morphEl(savedEl, curToNodeChild, true);
curToNodeChild = toNextSibling;
continue;
}
while(curFromNodeChild) {

@@ -235,3 +237,2 @@ var curFromNodeId = curFromNodeChild.id;

if ((savedEl = savedEls[curToNodeId])) {
delete savedEls[curToNodeId];
morphEl(savedEl, curToNodeChild, true);

@@ -295,3 +296,3 @@ curToNodeChild = savedEl; // We want to append the saved element instead

morphEl(morphedNode, toNode);
morphEl(morphedNode, toNode, false);

@@ -302,3 +303,5 @@ // Fire the "onNodeDiscarded" event for any saved elements

if (savedEls.hasOwnProperty(savedElId)) {
walkDiscardedNodes(savedEls[savedElId]);
var savedEl = savedEls[savedElId];
onNodeDiscarded(savedEl);
walkDiscardedChildNodes(savedEl);
}

@@ -305,0 +308,0 @@ }

@@ -29,3 +29,3 @@ {

"dependencies": {},
"version": "0.1.4"
"version": "0.1.5"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc