Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
0f10aebfd2 | |||
1af23ac544 |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.20.0",
|
"version": "0.20.2",
|
||||||
"description": "Utility library",
|
"description": "Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -95,7 +95,7 @@ export class Cache<K extends string | number | symbol, T> {
|
|||||||
delete(key: K) {
|
delete(key: K) {
|
||||||
delete this.store[key];
|
delete this.store[key];
|
||||||
if(this.options.storageKey && this.options.storage)
|
if(this.options.storageKey && this.options.storage)
|
||||||
this.options.storage.setItem(this.options.storageKey, JSON.stringify(this.cache));
|
this.options.storage.setItem(this.options.storageKey, JSON.stringify(this.store));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -144,7 +144,7 @@ export class Cache<K extends string | number | symbol, T> {
|
|||||||
set(key: K, value: T, ttl = this.options.ttl): this {
|
set(key: K, value: T, ttl = this.options.ttl): this {
|
||||||
this.store[key] = value;
|
this.store[key] = value;
|
||||||
if(this.options.storageKey && this.options.storage)
|
if(this.options.storageKey && this.options.storage)
|
||||||
this.options.storage.setItem(this.options.storageKey, JSON.stringify(this.cache));
|
this.options.storage.setItem(this.options.storageKey, JSON.stringify(this.store));
|
||||||
if(ttl) setTimeout(() => {
|
if(ttl) setTimeout(() => {
|
||||||
this.complete = false;
|
this.complete = false;
|
||||||
this.delete(key);
|
this.delete(key);
|
||||||
|
@ -75,6 +75,7 @@ export class Http {
|
|||||||
|
|
||||||
// Send request
|
// Send request
|
||||||
return new PromiseProgress((res, rej, prog) => {
|
return new PromiseProgress((res, rej, prog) => {
|
||||||
|
try {
|
||||||
fetch(url, {
|
fetch(url, {
|
||||||
headers,
|
headers,
|
||||||
method: opts.method || (opts.body ? 'POST' : 'GET'),
|
method: opts.method || (opts.body ? 'POST' : 'GET'),
|
||||||
@ -100,6 +101,7 @@ export class Http {
|
|||||||
push();
|
push();
|
||||||
}).catch((error: any) => controller.error(error));
|
}).catch((error: any) => controller.error(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
push();
|
push();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -115,7 +117,10 @@ export class Http {
|
|||||||
|
|
||||||
if(resp.ok) res(resp);
|
if(resp.ok) res(resp);
|
||||||
else rej(resp);
|
else rej(resp);
|
||||||
})
|
}).catch(err => rej(err));
|
||||||
|
} catch(err) {
|
||||||
|
rej(err);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user