Commit 4723b2ea authored by Bryce Johnson's avatar Bryce Johnson

Ensure approvals store is only initialized once.

parent e33a5bee
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
}, },
}, },
beforeCreate() { beforeCreate() {
return gl.ApprovalsStore.fetch().then(); return gl.ApprovalsStore.initStoreOnce();
}, },
template: ` template: `
<div> <div>
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
}, },
}, },
beforeCreate() { beforeCreate() {
return gl.ApprovalsStore.fetch(); return gl.ApprovalsStore.initStoreOnce();
}, },
template: ` template: `
<div v-if='hasApprovers' class='mr-widget-footer approved-by-users approvals-footer clearfix'> <div v-if='hasApprovers' class='mr-widget-footer approved-by-users approvals-footer clearfix'>
......
...@@ -15,12 +15,32 @@ ...@@ -15,12 +15,32 @@
init(rootStore) { init(rootStore) {
this.rootStore = rootStore; this.rootStore = rootStore;
this.api = new gl.ApprovalsApi(rootStore.dataset.endpoint); this.api = new gl.ApprovalsApi(rootStore.dataset.endpoint);
this.state = {
loading: false,
loaded: false,
};
} }
assignToRootStore(data) { assignToRootStore(data) {
return this.rootStore.assignToData('approvals', data); return this.rootStore.assignToData('approvals', data);
} }
initStoreOnce() {
const state = this.state;
if (state.loading || state.loaded) {
state.loading = true;
this.fetch()
.then(() => {
state.loading = false;
state.loaded = true;
})
.catch((err) => {
console.error(`Failed to initialize approvals store: ${err}`);
});
}
return this.fetch();
}
fetch() { fetch() {
return this.api.fetchApprovals() return this.api.fetchApprovals()
.then(res => this.assignToRootStore(res.data)); .then(res => this.assignToRootStore(res.data));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment