Skip to content
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

Polyfill replaceChildren #81

Merged
merged 3 commits into from
Nov 23, 2021
Merged
Changes from 1 commit
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
22 changes: 21 additions & 1 deletion util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ const transform = require('gl-vec3/transformMat4');

const SVG_NS = 'http://www.w3.org/2000/svg';

// Taken from https://github.com/yuzhe-han/ParentNode-replaceChildren
// This is to support browsers that do not yet support `replaceChildren`
const replaceChildrenPolyfill = function (...addNodes) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: since this isn't being attached to Node.prototype.replaceChildren, it might be more correct to call this a "ponyfill".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 1b0a00b

while (this.lastChild) {
this.removeChild(this.lastChild);
}

if (addNodes !== undefined) {
danjm marked this conversation as resolved.
Show resolved Hide resolved
this.append(...addNodes);
}
};

module.exports = {
calculateSizingOptions,
createLogoViewer,
Expand Down Expand Up @@ -497,7 +509,15 @@ function createFaceUpdater(container, polygons, transformed) {
const newPolygons = toDraw.map((poly) => poly.svg);
const defs = container.getElementsByTagName('defs');
const maskChildren = container.getElementsByTagName('mask');
container.replaceChildren(...defs, ...maskChildren, ...newPolygons);
if (container.replaceChildren) {
container.replaceChildren(...defs, ...maskChildren, ...newPolygons);
} else {
replaceChildrenPolyfill.bind(container)(
...defs,
...maskChildren,
...newPolygons,
);
}
};
}

Expand Down