stash
This commit is contained in:
parent
2af52c6991
commit
fbbc72feab
4 changed files with 67 additions and 5 deletions
|
@ -88,6 +88,64 @@ export default (config) => {
|
|||
}
|
||||
|
||||
/** may only be called from worker */
|
||||
|
||||
const clone = (obj) => {
|
||||
if (isProxy(obj)) {
|
||||
obj = toRaw(obj);
|
||||
}
|
||||
if (obj === null || typeof obj !== 'object') {
|
||||
return obj;
|
||||
}
|
||||
if (obj.__proto__ === ({}).__proto__) {
|
||||
return Object.assign({}, obj);
|
||||
}
|
||||
if (obj.__proto__ === [].__proto__) {
|
||||
return obj.slice();
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
const deepEqual = (a, b) => {
|
||||
if (a === b) {
|
||||
return true;
|
||||
}
|
||||
if (a === null || b === null) {
|
||||
return false;
|
||||
}
|
||||
if (a.__proto__ === ({}).__proto__ && b.__proto__ === ({}).__proto__) {
|
||||
|
||||
if (Object.keys(a).length !== Object.keys(b).length) {
|
||||
return false;
|
||||
}
|
||||
for (let key in b) {
|
||||
if (!(key in a)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
for (let key in a) {
|
||||
if (!(key in b)) {
|
||||
return false;
|
||||
}
|
||||
if (!deepEqual(a[key], b[key])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (a.__proto__ === [].__proto__ && b.__proto__ === [].__proto__) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
if (!deepEqual(a[i], b[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const worker_fun = function (self, ctx) {
|
||||
/* globals WebSocket, SharedWorker, onconnect, onmessage, postMessage, close, location */
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue