aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShpuld Shpuldson <shp@cock.li>2020-09-04 11:19:53 +0300
committerShpuld Shpuldson <shp@cock.li>2020-09-04 11:19:53 +0300
commit3fb35e8123d3a8cd151571b315b7ec4d7e0875c7 (patch)
treee473ffedfea68b8a3a5f661182e2e23928877510
parent5b403ba7d13eaf851ae43e814c583ceb018e2d20 (diff)
rename to promiseInterval
-rw-r--r--src/components/chat/chat.js4
-rw-r--r--src/modules/api.js2
-rw-r--r--src/modules/chats.js4
-rw-r--r--src/services/follow_request_fetcher/follow_request_fetcher.service.js4
-rw-r--r--src/services/notifications_fetcher/notifications_fetcher.service.js4
-rw-r--r--src/services/promise_interval/promise_interval.js (renamed from src/services/fetcher/fetcher.js)8
-rw-r--r--src/services/timeline_fetcher/timeline_fetcher.service.js4
7 files changed, 15 insertions, 15 deletions
diff --git a/src/components/chat/chat.js b/src/components/chat/chat.js
index 2062643d..15123885 100644
--- a/src/components/chat/chat.js
+++ b/src/components/chat/chat.js
@@ -5,7 +5,7 @@ import ChatMessage from '../chat_message/chat_message.vue'
import PostStatusForm from '../post_status_form/post_status_form.vue'
import ChatTitle from '../chat_title/chat_title.vue'
import chatService from '../../services/chat_service/chat_service.js'
-import { makeFetcher } from '../../services/fetcher/fetcher.js'
+import { promiseInterval } from '../../services/promise_interval/promise_interval.js'
import { getScrollPosition, getNewTopPosition, isBottomedOut, scrollableContainerHeight } from './chat_layout_utils.js'
const BOTTOMED_OUT_OFFSET = 10
@@ -288,7 +288,7 @@ const Chat = {
},
doStartFetching () {
this.$store.dispatch('startFetchingCurrentChat', {
- fetcher: () => makeFetcher(() => this.fetchChat({ fetchLatest: true }), 5000)
+ fetcher: () => promiseInterval(() => this.fetchChat({ fetchLatest: true }), 5000)
})
this.fetchChat({ isFirstFetch: true })
},
diff --git a/src/modules/api.js b/src/modules/api.js
index 7ddd8dde..73511442 100644
--- a/src/modules/api.js
+++ b/src/modules/api.js
@@ -20,7 +20,7 @@ const api = {
state.fetchers[fetcherName] = fetcher
},
removeFetcher (state, { fetcherName, fetcher }) {
- state.fetchers[fetcherName]()
+ state.fetchers[fetcherName].stop()
delete state.fetchers[fetcherName]
},
setWsToken (state, token) {
diff --git a/src/modules/chats.js b/src/modules/chats.js
index 45e4bdcc..60273a44 100644
--- a/src/modules/chats.js
+++ b/src/modules/chats.js
@@ -3,7 +3,7 @@ import { find, omitBy, orderBy, sumBy } from 'lodash'
import chatService from '../services/chat_service/chat_service.js'
import { parseChat, parseChatMessage } from '../services/entity_normalizer/entity_normalizer.service.js'
import { maybeShowChatNotification } from '../services/chat_utils/chat_utils.js'
-import { makeFetcher } from '../services/fetcher/fetcher.js'
+import { promiseInterval } from '../services/promise_interval/promise_interval.js'
const emptyChatList = () => ({
data: [],
@@ -46,7 +46,7 @@ const chats = {
const fetcher = () => dispatch('fetchChats', { latest: true })
fetcher()
commit('setChatListFetcher', {
- fetcher: () => makeFetcher(fetcher, 5000)
+ fetcher: () => promiseInterval(fetcher, 5000)
})
},
stopFetchingChats ({ commit }) {
diff --git a/src/services/follow_request_fetcher/follow_request_fetcher.service.js b/src/services/follow_request_fetcher/follow_request_fetcher.service.js
index bec434aa..74af4081 100644
--- a/src/services/follow_request_fetcher/follow_request_fetcher.service.js
+++ b/src/services/follow_request_fetcher/follow_request_fetcher.service.js
@@ -1,5 +1,5 @@
import apiService from '../api/api.service.js'
-import { makeFetcher } from '../fetcher/fetcher.js'
+import { promiseInterval } from '../promise_interval/promise_interval.js'
const fetchAndUpdate = ({ store, credentials }) => {
return apiService.fetchFollowRequests({ credentials })
@@ -13,7 +13,7 @@ const fetchAndUpdate = ({ store, credentials }) => {
const startFetching = ({ credentials, store }) => {
const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store })
boundFetchAndUpdate()
- return makeFetcher(boundFetchAndUpdate, 10000)
+ return promiseInterval(boundFetchAndUpdate, 10000)
}
const followRequestFetcher = {
diff --git a/src/services/notifications_fetcher/notifications_fetcher.service.js b/src/services/notifications_fetcher/notifications_fetcher.service.js
index 90988fc4..c908b644 100644
--- a/src/services/notifications_fetcher/notifications_fetcher.service.js
+++ b/src/services/notifications_fetcher/notifications_fetcher.service.js
@@ -1,5 +1,5 @@
import apiService from '../api/api.service.js'
-import { makeFetcher } from '../fetcher/fetcher.js'
+import { promiseInterval } from '../promise_interval/promise_interval.js'
const update = ({ store, notifications, older }) => {
store.dispatch('setNotificationsError', { value: false })
@@ -61,7 +61,7 @@ const startFetching = ({ credentials, store }) => {
setTimeout(() => store.dispatch('setNotificationsSilence', false), 10000)
const boundFetchAndUpdate = () => fetchAndUpdate({ credentials, store })
boundFetchAndUpdate()
- return makeFetcher(boundFetchAndUpdate, 10000)
+ return promiseInterval(boundFetchAndUpdate, 10000)
}
const notificationsFetcher = {
diff --git a/src/services/fetcher/fetcher.js b/src/services/promise_interval/promise_interval.js
index aae1c2cc..ee46a236 100644
--- a/src/services/fetcher/fetcher.js
+++ b/src/services/promise_interval/promise_interval.js
@@ -1,11 +1,11 @@
-// makeFetcher - replacement for setInterval for fetching, starts counting
-// the interval only after a request is done instead of immediately.
+// promiseInterval - replacement for setInterval for promises, starts counting
+// the interval only after a promise is done instead of immediately.
// - promiseCall is a function that returns a promise, it's called the first
// time after the first interval.
// - interval is the interval delay in ms.
-export const makeFetcher = (promiseCall, interval) => {
+export const promiseInterval = (promiseCall, interval) => {
let stopped = false
let timeout = null
let func = () => {}
@@ -24,5 +24,5 @@ export const makeFetcher = (promiseCall, interval) => {
timeout = window.setTimeout(func, interval)
- return stopFetcher
+ return { stop: stopFetcher }
}
diff --git a/src/services/timeline_fetcher/timeline_fetcher.service.js b/src/services/timeline_fetcher/timeline_fetcher.service.js
index 9f585f68..72ea4890 100644
--- a/src/services/timeline_fetcher/timeline_fetcher.service.js
+++ b/src/services/timeline_fetcher/timeline_fetcher.service.js
@@ -1,7 +1,7 @@
import { camelCase } from 'lodash'
import apiService from '../api/api.service.js'
-import { makeFetcher } from '../fetcher/fetcher.js'
+import { promiseInterval } from '../promise_interval/promise_interval.js'
const update = ({ store, statuses, timeline, showImmediately, userId, pagination }) => {
const ccTimeline = camelCase(timeline)
@@ -74,7 +74,7 @@ const startFetching = ({ timeline = 'friends', credentials, store, userId = fals
fetchAndUpdate({ timeline, credentials, store, showImmediately, userId, tag })
const boundFetchAndUpdate = () =>
fetchAndUpdate({ timeline, credentials, store, userId, tag })
- return makeFetcher(boundFetchAndUpdate, 10000)
+ return promiseInterval(boundFetchAndUpdate, 10000)
}
const timelineFetcher = {
fetchAndUpdate,