Skip to content

Discover node.remove capability at runtime #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ const domdiff = (
if (futureSame && currentStart < currentEnd) {
remove(
get,
parentNode,
currentNodes,
currentStart,
currentEnd
Expand Down Expand Up @@ -131,14 +130,12 @@ const domdiff = (
if (-1 < i) {
remove(
get,
parentNode,
currentNodes,
currentStart,
i
);
remove(
get,
parentNode,
currentNodes,
i + futureChanges,
currentEnd
Expand All @@ -161,7 +158,6 @@ const domdiff = (
);
remove(
get,
parentNode,
currentNodes,
currentStart,
currentEnd
Expand Down
29 changes: 10 additions & 19 deletions cjs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ const next = (get, list, i, length, before) => i < length ?
before);
exports.next = next;

const remove = (get, parent, children, start, end) => {
const remove = (get, children, start, end) => {
while (start < end)
removeChild(get(children[start++], -1), parent);
drop(get(children[start++], -1));
};
exports.remove = remove;

Expand Down Expand Up @@ -311,7 +311,6 @@ const applyDiff = (
else
remove(
get,
parentNode,
currentNodes,
currentStart++,
currentStart
Expand Down Expand Up @@ -381,19 +380,11 @@ const smartDiff = (
};
exports.smartDiff = smartDiff;

let removeChild = (child, parentNode) => {
/* istanbul ignore if */
if ('remove' in child) {
removeChild = child => {
child.remove();
};
}
else {
removeChild = (child, parentNode) => {
/* istanbul ignore else */
if (child.parentNode === parentNode)
parentNode.removeChild(child);
};
}
removeChild(child, parentNode);
};
const drop = node => (node.remove || dropChild).call(node);

function dropChild() {
const {parentNode} = this;
/* istanbul ignore else */
if (parentNode)
parentNode.removeChild(this);
}
4 changes: 0 additions & 4 deletions esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ const domdiff = (
if (futureSame && currentStart < currentEnd) {
remove(
get,
parentNode,
currentNodes,
currentStart,
currentEnd
Expand Down Expand Up @@ -132,14 +131,12 @@ const domdiff = (
if (-1 < i) {
remove(
get,
parentNode,
currentNodes,
currentStart,
i
);
remove(
get,
parentNode,
currentNodes,
i + futureChanges,
currentEnd
Expand All @@ -162,7 +159,6 @@ const domdiff = (
);
remove(
get,
parentNode,
currentNodes,
currentStart,
currentEnd
Expand Down
29 changes: 10 additions & 19 deletions esm/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ export const next = (get, list, i, length, before) => i < length ?
get(list[i - 1], -0).nextSibling :
before);

export const remove = (get, parent, children, start, end) => {
export const remove = (get, children, start, end) => {
while (start < end)
removeChild(get(children[start++], -1), parent);
drop(get(children[start++], -1));
};

// - - - - - - - - - - - - - - - - - - -
Expand Down Expand Up @@ -303,7 +303,6 @@ const applyDiff = (
else
remove(
get,
parentNode,
currentNodes,
currentStart++,
currentStart
Expand Down Expand Up @@ -372,19 +371,11 @@ export const smartDiff = (
);
};

let removeChild = (child, parentNode) => {
/* istanbul ignore if */
if ('remove' in child) {
removeChild = child => {
child.remove();
};
}
else {
removeChild = (child, parentNode) => {
/* istanbul ignore else */
if (child.parentNode === parentNode)
parentNode.removeChild(child);
};
}
removeChild(child, parentNode);
};
const drop = node => (node.remove || dropChild).call(node);

function dropChild() {
const {parentNode} = this;
/* istanbul ignore else */
if (parentNode)
parentNode.removeChild(this);
}
36 changes: 16 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ var next = function next(get, list, i, length, before) {
return i < length ? get(list[i], 0) : 0 < i ? get(list[i - 1], -0).nextSibling : before;
};

var remove = function remove(get, parent, children, start, end) {
var remove = function remove(get, children, start, end) {
while (start < end) {
_removeChild(get(children[start++], -1), parent);
drop(get(children[start++], -1));
}
};

Expand Down Expand Up @@ -273,7 +273,7 @@ var applyDiff = function applyDiff(diff, get, parentNode, futureNodes, futureSta
break;
case DELETION:
// TODO: bulk removes for sequential nodes
if (live.has(currentNodes[currentStart])) currentStart++;else remove(get, parentNode, currentNodes, currentStart++, currentStart);
if (live.has(currentNodes[currentStart])) currentStart++;else remove(get, currentNodes, currentStart++, currentStart);
break;
}
}
Expand All @@ -293,21 +293,17 @@ var smartDiff = function smartDiff(get, parentNode, futureNodes, futureStart, fu
applyDiff(OND(futureNodes, futureStart, futureChanges, currentNodes, currentStart, currentChanges, compare) || HS(futureNodes, futureStart, futureEnd, futureChanges, currentNodes, currentStart, currentEnd, currentChanges), get, parentNode, futureNodes, futureStart, currentNodes, currentStart, currentLength, before);
};

var _removeChild = function removeChild(child, parentNode) {
/* istanbul ignore if */
if ('remove' in child) {
_removeChild = function removeChild(child) {
child.remove();
};
} else {
_removeChild = function removeChild(child, parentNode) {
/* istanbul ignore else */
if (child.parentNode === parentNode) parentNode.removeChild(child);
};
}
_removeChild(child, parentNode);
var drop = function drop(node) {
return (node.remove || dropChild).call(node);
};

function dropChild() {
var parentNode = this.parentNode;
/* istanbul ignore else */

if (parentNode) parentNode.removeChild(this);
}

/*! (c) 2018 Andrea Giammarchi (ISC) */

var domdiff = function domdiff(parentNode, // where changes happen
Expand Down Expand Up @@ -357,7 +353,7 @@ options // optional object with one of the following properties

// only stuff to remove
if (futureSame && currentStart < currentEnd) {
remove(get, parentNode, currentNodes, currentStart, currentEnd);
remove(get, currentNodes, currentStart, currentEnd);
return futureNodes;
}

Expand All @@ -380,8 +376,8 @@ options // optional object with one of the following properties
i = indexOf(currentNodes, currentStart, currentEnd, futureNodes, futureStart, futureEnd, compare);
// outer diff
if (-1 < i) {
remove(get, parentNode, currentNodes, currentStart, i);
remove(get, parentNode, currentNodes, i + futureChanges, currentEnd);
remove(get, currentNodes, currentStart, i);
remove(get, currentNodes, i + futureChanges, currentEnd);
return futureNodes;
}
}
Expand All @@ -391,7 +387,7 @@ options // optional object with one of the following properties
/* istanbul ignore else */
if (currentChanges < 2 || futureChanges < 2) {
append(get, parentNode, futureNodes, futureStart, futureEnd, get(currentNodes[currentStart], 0));
remove(get, parentNode, currentNodes, currentStart, currentEnd);
remove(get, currentNodes, currentStart, currentEnd);
return futureNodes;
}

Expand Down
4 changes: 2 additions & 2 deletions min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.