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

inlined structuredClone #231

Merged
merged 1 commit into from
Oct 20, 2022
Merged
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
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