summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFatih Acet <acetfatih@gmail.com>2017-07-13 14:32:09 +0300
committerFatih Acet <acetfatih@gmail.com>2017-07-21 22:35:26 +0300
commitd9928d1a7c8d9ea08759b26b49a874d4ad0138f1 (patch)
treee8f59a42dc5beb425c76d6d434d40d53fc99de77
parent820c0d6dd120f1bf137a985bba8abf5a8ca97ac0 (diff)
downloadgitlab-ce-d9928d1a7c8d9ea08759b26b49a874d4ad0138f1.tar.gz
IssueNotesRefactor: Decouple poll from main component to increase reusability.
-rw-r--r--app/assets/javascripts/notes/components/issue_notes.vue11
-rw-r--r--app/assets/javascripts/notes/stores/issue_notes_store.js8
2 files changed, 10 insertions, 9 deletions
diff --git a/app/assets/javascripts/notes/components/issue_notes.vue b/app/assets/javascripts/notes/components/issue_notes.vue
index a0c951df822..95ab4a5e254 100644
--- a/app/assets/javascripts/notes/components/issue_notes.vue
+++ b/app/assets/javascripts/notes/components/issue_notes.vue
@@ -61,17 +61,14 @@ export default {
});
},
initPolling() {
- const { notesPath, lastFetchedAt } = this.$el.parentNode.dataset;
- const options = {
- endpoint: `${notesPath}?full_data=1`,
- lastFetchedAt,
- };
+ const { lastFetchedAt } = $('.js-notes-wrapper')[0].dataset;
+ this.$store.commit('setLastFetchedAt', lastFetchedAt);
// FIXME: @fatihacet Implement real polling mechanism
setInterval(() => {
- this.$store.dispatch('poll', options)
+ this.$store.dispatch('poll')
.then((res) => {
- options.lastFetchedAt = res.last_fetched_at;
+ this.$store.commit('setLastFetchedAt', res.lastFetchedAt);
})
.catch(() => {
new Flash('Something went wrong while fetching latest comments.'); // eslint-disable-line
diff --git a/app/assets/javascripts/notes/stores/issue_notes_store.js b/app/assets/javascripts/notes/stores/issue_notes_store.js
index a5811515fc4..ef5bb8dce3d 100644
--- a/app/assets/javascripts/notes/stores/issue_notes_store.js
+++ b/app/assets/javascripts/notes/stores/issue_notes_store.js
@@ -7,6 +7,7 @@ const findNoteObjectById = (notes, id) => notes.filter(n => n.id === id)[0];
const state = {
notes: [],
targetNoteHash: null,
+ lastFetchedAt: null,
};
const getters = {
@@ -104,6 +105,9 @@ const mutations = {
});
}
},
+ setLastFetchedAt(storeState, fetchedAt) {
+ storeState.lastFetchedAt = fetchedAt;
+ },
};
const actions = {
@@ -156,10 +160,10 @@ const actions = {
});
},
poll(context, data) {
- const { endpoint, lastFetchedAt } = data;
+ const { notesPath } = $('.js-notes-wrapper')[0].dataset;
return service
- .poll(endpoint, lastFetchedAt)
+ .poll(`${notesPath}?full_data=1`, context.state.lastFetchedAt)
.then(res => res.json())
.then((res) => {
if (res.notes.length) {