Skip to content

Commit 55122ca

Browse files
committed
wip
1 parent abe0093 commit 55122ca

File tree

4 files changed

+16
-14
lines changed

4 files changed

+16
-14
lines changed

src/components/NewsItem.vue

+5
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ export default {
88
props: ['item']
99
}
1010
</script>
11+
12+
<style lang="stylus">
13+
.news-item
14+
background-color #fff
15+
</style>

src/components/NewsList.vue

+9-4
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,14 @@ export default {
4141
},
4242
4343
data () {
44+
const isInitialRender = !this.$root._isMounted
4445
return {
4546
loading: false,
4647
transition: 'slide-left',
47-
displayedPage: Number(this.$store.state.route.params.page) || 1,
48-
displayedItems: this.$store.getters.activeItems
48+
// if this is the initial render, directly render with the store state
49+
// otherwise this is a page switch, start with blank and wait for data load
50+
displayedPage: isInitialRender ? Number(this.$store.state.route.params.page) || 1 : -1,
51+
displayedItems: isInitialRender ? this.$store.getters.activeItems : []
4952
}
5053
},
5154
@@ -63,7 +66,9 @@ export default {
6366
},
6467
6568
mounted () {
66-
this.loadItems(this.page, -1)
69+
if (this.$root._isMounted) {
70+
this.loadItems(this.page)
71+
}
6772
},
6873
6974
watch: {
@@ -73,7 +78,7 @@ export default {
7378
},
7479
7580
methods: {
76-
loadItems (to, from) {
81+
loadItems (to = this.page, from = -1) {
7782
this.loading = true
7883
this.$store.dispatch('FETCH_DATA_FOR_TYPE', {
7984
type: this.type

src/store/api.js

+1-9
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function createServerSideAPI () {
3333
})
3434
})
3535

36-
// warm the cache every 15 min, since the front page changes quite often
36+
// warm the front page cache every 15 min
3737
warmCache()
3838
function warmCache () {
3939
fetchItems((api.__ids__.top || []).slice(0, 30))
@@ -57,14 +57,6 @@ export function fetchIdsByType (type) {
5757
: fetch(`${type}stories`)
5858
}
5959

60-
export function watchTopIds (cb) {
61-
api.child(`topstories`).on('value', snapshot => {
62-
const ids = snapshot.val()
63-
api.__ids__ && (api.__ids__.top = ids)
64-
cb(ids)
65-
})
66-
}
67-
6860
export function fetchItem (id, forceRefresh) {
6961
if (!forceRefresh && cache.get(id)) {
7062
return Promise.resolve(cache.get(id))

src/store/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Vue from 'vue'
22
import Vuex from 'vuex'
3-
import { watchTopIds, fetchIdsByType, fetchItems } from './api'
3+
import { fetchIdsByType, fetchItems } from './api'
44

55
Vue.use(Vuex)
66

0 commit comments

Comments
 (0)