Commit f70d7afa authored by Sebastien Chopin's avatar Sebastien Chopin

Fix asynchronous api

parent 200a69da
......@@ -2,7 +2,7 @@
import { createAPI } from 'create-api'
const logRequests = !!process.env.DEBUG_API
let api = {}
let api = null
let _api = createAPI({
version: '/v0',
......@@ -64,8 +64,9 @@ export function fetchUser(id) {
return fetch(`user/${id}`)
}
export function watchList(type, cb) {
export async function watchList(type, cb) {
let first = true
await _api
const ref = api.child(`${type}stories`)
const handler = snapshot => {
if (first) {
......
......@@ -44,12 +44,12 @@ export default {
}
},
beforeMount() {
async beforeMount() {
if (this.$root._isMounted) {
this.loadItems(this.page)
}
// watch the current list for realtime updates
this.unwatchList = watchList(this.type, ids => {
this.unwatchList = await watchList(this.type, ids => {
this.$store.commit('SET_LIST', {type: this.type, ids})
this.$store.dispatch('ENSURE_ACTIVE_ITEMS').then(() => {
this.displayedItems = this.$store.getters.activeItems
......
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