This commit is contained in:
syuilo 2018-04-14 03:40:12 +09:00
parent 04285c9498
commit 10abe03ed7
1 changed files with 9 additions and 5 deletions

View File

@ -441,10 +441,14 @@ export default class MiOS extends EventEmitter {
document.body.appendChild(spinner); document.body.appendChild(spinner);
} }
const onFinally = () => {
if (--pending === 0) spinner.parentNode.removeChild(spinner);
};
// Append a credential // Append a credential
if (this.isSignedIn) (data as any).i = this.i.token; if (this.isSignedIn) (data as any).i = this.i.token;
return new Promise((resolve, reject) => { const promise = new Promise((resolve, reject) => {
const viaStream = this.stream.hasConnection && const viaStream = this.stream.hasConnection &&
(localStorage.getItem('apiViaStream') ? localStorage.getItem('apiViaStream') == 'true' : true); (localStorage.getItem('apiViaStream') ? localStorage.getItem('apiViaStream') == 'true' : true);
@ -453,8 +457,6 @@ export default class MiOS extends EventEmitter {
const id = Math.random().toString(); const id = Math.random().toString();
stream.once(`api-res:${id}`, res => { stream.once(`api-res:${id}`, res => {
if (--pending === 0) spinner.parentNode.removeChild(spinner);
if (res.res) { if (res.res) {
resolve(res.res); resolve(res.res);
} else { } else {
@ -489,8 +491,6 @@ export default class MiOS extends EventEmitter {
credentials: endpoint === 'signin' ? 'include' : 'omit', credentials: endpoint === 'signin' ? 'include' : 'omit',
cache: 'no-cache' cache: 'no-cache'
}).then(async (res) => { }).then(async (res) => {
if (--pending === 0) spinner.parentNode.removeChild(spinner);
const body = res.status === 204 ? null : await res.json(); const body = res.status === 204 ? null : await res.json();
if (this.debug) { if (this.debug) {
@ -508,6 +508,10 @@ export default class MiOS extends EventEmitter {
}).catch(reject); }).catch(reject);
} }
}); });
promise.then(onFinally, onFinally);
return promise;
} }
/** /**