Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
node-sample
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
周韬
node-sample
Commits
55122cae
Commit
55122cae
authored
Aug 09, 2016
by
Evan You
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
abe0093a
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
14 deletions
+16
-14
NewsItem.vue
src/components/NewsItem.vue
+5
-0
NewsList.vue
src/components/NewsList.vue
+9
-4
api.js
src/store/api.js
+1
-9
index.js
src/store/index.js
+1
-1
No files found.
src/components/NewsItem.vue
View file @
55122cae
...
...
@@ -8,3 +8,8 @@ export default {
props
:
[
'item'
]
}
</
script
>
<
style
lang=
"stylus"
>
.news-item
background-color #fff
</
style
>
src/components/NewsList.vue
View file @
55122cae
...
...
@@ -41,11 +41,14 @@ export default {
},
data
()
{
const
isInitialRender
=
!
this
.
$root
.
_isMounted
return
{
loading
:
false
,
transition
:
'slide-left'
,
displayedPage
:
Number
(
this
.
$store
.
state
.
route
.
params
.
page
)
||
1
,
displayedItems
:
this
.
$store
.
getters
.
activeItems
// if this is the initial render, directly render with the store state
// otherwise this is a page switch, start with blank and wait for data load
displayedPage
:
isInitialRender
?
Number
(
this
.
$store
.
state
.
route
.
params
.
page
)
||
1
:
-
1
,
displayedItems
:
isInitialRender
?
this
.
$store
.
getters
.
activeItems
:
[]
}
},
...
...
@@ -63,7 +66,9 @@ export default {
},
mounted
()
{
this
.
loadItems
(
this
.
page
,
-
1
)
if
(
this
.
$root
.
_isMounted
)
{
this
.
loadItems
(
this
.
page
)
}
},
watch
:
{
...
...
@@ -73,7 +78,7 @@ export default {
},
methods
:
{
loadItems
(
to
,
from
)
{
loadItems
(
to
=
this
.
page
,
from
=
-
1
)
{
this
.
loading
=
true
this
.
$store
.
dispatch
(
'FETCH_DATA_FOR_TYPE'
,
{
type
:
this
.
type
...
...
src/store/api.js
View file @
55122cae
...
...
@@ -33,7 +33,7 @@ function createServerSideAPI () {
})
})
// warm the
cache every 15 min, since the front page changes quite ofte
n
// warm the
front page cache every 15 mi
n
warmCache
()
function
warmCache
()
{
fetchItems
((
api
.
__ids__
.
top
||
[]).
slice
(
0
,
30
))
...
...
@@ -57,14 +57,6 @@ export function fetchIdsByType (type) {
:
fetch
(
`
${
type
}
stories`
)
}
export
function
watchTopIds
(
cb
)
{
api
.
child
(
`topstories`
).
on
(
'value'
,
snapshot
=>
{
const
ids
=
snapshot
.
val
()
api
.
__ids__
&&
(
api
.
__ids__
.
top
=
ids
)
cb
(
ids
)
})
}
export
function
fetchItem
(
id
,
forceRefresh
)
{
if
(
!
forceRefresh
&&
cache
.
get
(
id
))
{
return
Promise
.
resolve
(
cache
.
get
(
id
))
...
...
src/store/index.js
View file @
55122cae
import
Vue
from
'vue'
import
Vuex
from
'vuex'
import
{
watchTopIds
,
fetchIdsByType
,
fetchItems
}
from
'./api'
import
{
fetchIdsByType
,
fetchItems
}
from
'./api'
Vue
.
use
(
Vuex
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment