api/cookie: update cookies value-by-value in manager

This commit is contained in:
jj 2024-11-01 14:58:04 +00:00
parent f098da870c
commit 42ec28a642
No known key found for this signature in database
2 changed files with 21 additions and 7 deletions

View file

@ -4,13 +4,18 @@ export default class Cookie {
constructor(input) {
assert(typeof input === 'object');
this._values = {};
this.set(input)
for (const [ k, v ] of Object.entries(input))
this.set(k, v);
}
set(values) {
Object.entries(values).forEach(
([ key, value ]) => this._values[key] = value
)
set(key, value) {
const old = this._values[key];
if (old === value)
return false;
this._values[key] = value;
return true;
}
unset(keys) {

View file

@ -42,8 +42,17 @@ export function getCookie(service) {
}
export function updateCookieValues(cookie, values) {
cookie.set(values);
if (Object.keys(values).length) dirty = true
let changed = false;
for (const [ key, value ] of Object.entries(values)) {
changed ||= cookie.set(key, value);
}
if (changed) {
dirty = true;
}
return changed;
}
export function updateCookie(cookie, headers) {