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) {
|
||||
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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue