mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-15 04:39:58 +00:00
api/cookie: update cookies value-by-value in manager
This commit is contained in:
parent
f098da870c
commit
42ec28a642
2 changed files with 21 additions and 7 deletions
|
@ -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) {
|
||||||
|
|
|
@ -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) {
|
||||||
|
|
Loading…
Reference in a new issue