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) { constructor(input) {
assert(typeof input === 'object'); assert(typeof input === 'object');
this._values = {}; this._values = {};
this.set(input)
for (const [ k, v ] of Object.entries(input))
this.set(k, v);
} }
set(values) { set(key, value) {
Object.entries(values).forEach( const old = this._values[key];
([ key, value ]) => this._values[key] = value if (old === value)
) return false;
this._values[key] = value;
return true;
} }
unset(keys) { unset(keys) {

View file

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