web: fix /users/me/ endpoint being called multiple times
This commit is contained in:
parent
e0bc4f1da5
commit
58497bb63f
|
@ -1,6 +1,6 @@
|
||||||
import { DefaultClient, PBResponse } from "./client";
|
import { DefaultClient, PBResponse } from "./client";
|
||||||
|
|
||||||
let me: User;
|
let _globalMePromise: Promise<User>;
|
||||||
|
|
||||||
export class User {
|
export class User {
|
||||||
pk: number;
|
pk: number;
|
||||||
|
@ -15,10 +15,10 @@ export class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
static me(): Promise<User> {
|
static me(): Promise<User> {
|
||||||
if (me) {
|
if (!_globalMePromise) {
|
||||||
return Promise.resolve<User>(me);
|
_globalMePromise = DefaultClient.fetch<User>(["core", "users", "me"]);
|
||||||
}
|
}
|
||||||
return DefaultClient.fetch<User>(["core", "users", "me"]).then(u => me = u);
|
return _globalMePromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
static count(): Promise<number> {
|
static count(): Promise<number> {
|
||||||
|
|
Reference in New Issue