Skip to content

Commit

Permalink
inlined structuredClone (#231)
Browse files Browse the repository at this point in the history
removed the polyfill detection for structuredClone and instead used our polyfill always
  • Loading branch information
CommanderStorm authored Oct 20, 2022
1 parent 842bd27 commit 57dd4a0
Showing 1 changed file with 21 additions and 28 deletions.
49 changes: 21 additions & 28 deletions webclient/src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,35 +71,28 @@ const cachedFetch = (() => ({

// the following is a poor implementation of a structuredClone(item) polyfill
// (read: this is not the full implementation browsers follow, but a simplified version)
// TODO: remove this, once Samsung Internet implements this. See https://caniuse.com/mdn-api_structuredclone

console.debug({scType:typeof structuredClone})
if (typeof structuredClone === "undefined") {
console.warn("You are using an out of date browser. Please consider upgrading it.")
// eslint-disable-next-line no-inner-declarations, no-unused-vars
function structuredClone(item) {
// cf. StackOverflow: https://stackoverflow.com/questions/728360/how-do-i-correctly-clone-a-javascript-object
// item has to be serializable!
if (item == null || typeof item !== "object") return item;
// Arrays are currently not cloned (TODO: is this required?)
if (item instanceof Array) {
return item;
}
if (!(item instanceof Object))
console.error(
`Items of type ${typeof item} (${item}) cant be structuredClone'd`
);

const copy = {};
Object.keys(item).forEach((key) => {
if (
key !== "__ob__" && // stuff by vue, recursive!
Object.prototype.hasOwnProperty.call(item, key) // google no-prototype-builtins for an explanation of this line
)
copy[key] = structuredClone(item[key]);
});
return copy;
function structuredClone(item) {
// cf. StackOverflow: https://stackoverflow.com/questions/728360/how-do-i-correctly-clone-a-javascript-object
// item has to be serializable!
if (item == null || typeof item !== "object") return item;
// Arrays are currently not cloned (TODO: is this required?)
if (item instanceof Array) {
return item;
}
if (!(item instanceof Object))
console.error(
`Items of type ${typeof item} (${item}) cant be structuredClone'd`
);

const copy = {};
Object.keys(item).forEach((key) => {
if (
key !== "__ob__" && // stuff by vue, recursive!
Object.prototype.hasOwnProperty.call(item, key) // google no-prototype-builtins for an explanation of this line
)
copy[key] = structuredClone(item[key]);
});
return copy;
}

navigatum = (() => {
Expand Down

0 comments on commit 57dd4a0

Please sign in to comment.