Skip to content

Commit

Permalink
Remove async/await from CookieStore
Browse files Browse the repository at this point in the history
  • Loading branch information
j0k3r committed Sep 6, 2023
1 parent d326fbc commit a1b8fd0
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions packages/cookie-store/src/CookieStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ export class CookieStore extends EventTarget {
this.cookieMap = parse(cookieString);
}

async get(
init?: CookieStoreGetOptions['name'] | CookieStoreGetOptions,
): Promise<Cookie | undefined> {
get(init?: CookieStoreGetOptions['name'] | CookieStoreGetOptions): Cookie | undefined {
if (init == null) {
throw new TypeError('CookieStoreGetOptions must not be empty');
} else if (init instanceof Object && !Object.keys(init).length) {
throw new TypeError('CookieStoreGetOptions must not be empty');
}
return (await this.getAll(init))[0];
return this.getAll(init)[0];
}

async set(init: CookieListItem | string, possibleValue?: string): Promise<void> {
set(init: CookieListItem | string, possibleValue?: string): void {
const item: CookieListItem = {
name: '',
value: '',
Expand Down Expand Up @@ -79,14 +77,14 @@ export class CookieStore extends EventTarget {
if (item.name && item.name.startsWith('__Host')) {
item.secure = true;
}
const previousCookie = await this.get(item.name);
const previousCookie = this.get(item.name);
this.cookieMap.set(item.name || '', item as Cookie);

if (this.onchange) {
const changed = [];
const deleted = [];

if (previousCookie && !(await this.get(item))) {
if (previousCookie && !this.get(item)) {
deleted.push({ ...item, value: undefined });
} else {
changed.push(item);
Expand All @@ -96,7 +94,7 @@ export class CookieStore extends EventTarget {
}
}

async getAll(init?: CookieStoreGetOptions['name'] | CookieStoreGetOptions): Promise<Cookie[]> {
getAll(init?: CookieStoreGetOptions['name'] | CookieStoreGetOptions): Cookie[] {
const cookies = Array.from(this.cookieMap.values());
if (init == null || Object.keys(init).length === 0) {
return cookies;
Expand All @@ -110,7 +108,7 @@ export class CookieStore extends EventTarget {
return cookies.filter(cookie => cookie.name === name);
}

async delete(init: CookieStoreDeleteOptions['name'] | CookieStoreDeleteOptions): Promise<void> {
delete(init: CookieStoreDeleteOptions['name'] | CookieStoreDeleteOptions): void {
const item: CookieListItem = {
name: '',
value: '',
Expand All @@ -129,6 +127,6 @@ export class CookieStore extends EventTarget {

item.expires = 0;

await this.set(item);
this.set(item);
}
}

0 comments on commit a1b8fd0

Please sign in to comment.