File tree 4 files changed +16
-14
lines changed
4 files changed +16
-14
lines changed Original file line number Diff line number Diff line change @@ -8,3 +8,8 @@ export default {
8
8
props: [' item' ]
9
9
}
10
10
</script >
11
+
12
+ <style lang="stylus">
13
+ .news-item
14
+ background-color #f f f
15
+ </style >
Original file line number Diff line number Diff line change @@ -41,11 +41,14 @@ export default {
41
41
},
42
42
43
43
data () {
44
+ const isInitialRender = ! this .$root ._isMounted
44
45
return {
45
46
loading: false ,
46
47
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 : []
49
52
}
50
53
},
51
54
@@ -63,7 +66,9 @@ export default {
63
66
},
64
67
65
68
mounted () {
66
- this .loadItems (this .page , - 1 )
69
+ if (this .$root ._isMounted ) {
70
+ this .loadItems (this .page )
71
+ }
67
72
},
68
73
69
74
watch: {
@@ -73,7 +78,7 @@ export default {
73
78
},
74
79
75
80
methods: {
76
- loadItems (to , from ) {
81
+ loadItems (to = this . page , from = - 1 ) {
77
82
this .loading = true
78
83
this .$store .dispatch (' FETCH_DATA_FOR_TYPE' , {
79
84
type: this .type
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ function createServerSideAPI () {
33
33
} )
34
34
} )
35
35
36
- // warm the cache every 15 min, since the front page changes quite often
36
+ // warm the front page cache every 15 min
37
37
warmCache ( )
38
38
function warmCache ( ) {
39
39
fetchItems ( ( api . __ids__ . top || [ ] ) . slice ( 0 , 30 ) )
@@ -57,14 +57,6 @@ export function fetchIdsByType (type) {
57
57
: fetch ( `${ type } stories` )
58
58
}
59
59
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
-
68
60
export function fetchItem ( id , forceRefresh ) {
69
61
if ( ! forceRefresh && cache . get ( id ) ) {
70
62
return Promise . resolve ( cache . get ( id ) )
Original file line number Diff line number Diff line change 1
1
import Vue from 'vue'
2
2
import Vuex from 'vuex'
3
- import { watchTopIds , fetchIdsByType , fetchItems } from './api'
3
+ import { fetchIdsByType , fetchItems } from './api'
4
4
5
5
Vue . use ( Vuex )
6
6
You can’t perform that action at this time.
0 commit comments