Skip to content
Snippets Groups Projects
Commit ff514368 authored by Patrick Jentsch's avatar Patrick Jentsch
Browse files

Try to avoid requesting user data multiple times

parent 82745629
Branches
No related tags found
No related merge requests found
......@@ -51,8 +51,16 @@ class App {
}
getUserById(userId) {
return new Promise((resolve, reject) => {
if (userId in this.data.users) {resolve(this.users[userId]);}
let promise;
if (userId in this.data.users) {
if (this.data.users[userId] instanceof Promise) {
return this.data.users[userId];
} else {
return new Promise((resolve, reject) => {resolve(userValue);});
}
}
promise = new Promise((resolve, reject) => {
this.socket.emit('users.user.get', userId, response => {
if (response.code === 200) {
this.data.users[userId] = response.payload;
......@@ -62,12 +70,13 @@ class App {
}
});
});
this.data.users[userId] = promise;
return promise;
}
usersPatchHandler(patch) {
let listener;
console.log(patch);
this.data = jsonpatch.apply_patch(this.data, patch);
for (listener of this.eventListeners['users.patch']) {listener(patch);}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment