From 89f5b77b6e9929c21c5cf4edf6184bf8cdf489d5 Mon Sep 17 00:00:00 2001 From: jedi Date: Wed, 31 Jan 2024 22:51:01 +0100 Subject: [PATCH] stash --- web/src/shared-state-plugin/index.js | 58 ++++++++++++++++++++++++++++ web/src/store.js | 3 ++ web/src/utils.js | 2 +- 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/web/src/shared-state-plugin/index.js b/web/src/shared-state-plugin/index.js index 67397d0..57ae3b8 100644 --- a/web/src/shared-state-plugin/index.js +++ b/web/src/shared-state-plugin/index.js @@ -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 */ diff --git a/web/src/store.js b/web/src/store.js index a2d1434..88d7368 100644 --- a/web/src/store.js +++ b/web/src/store.js @@ -215,6 +215,9 @@ const store = createStore({ setThumbnail(state, {url, data}) { state.thumbnailCache[url] = data; }, + setThumbnail(state, {url, data}) { + state.thumbnailCache[url] = data; + }, setShippingVouchers(state, codes) { state.shippingVouchers = codes; state.fetchedData = {...state.fetchedData, shippingVouchers: Date.now()}; diff --git a/web/src/utils.js b/web/src/utils.js index 6e9d8e4..21b2e97 100644 --- a/web/src/utils.js +++ b/web/src/utils.js @@ -47,7 +47,7 @@ const http = { method: 'POST', headers: { "Content-Type": "application/json", - "Authorization": `Token ${token}`, + "Authorization": `Token ${data.token}`, }, body: JSON.stringify(data), });