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
f70d7afa
Commit
f70d7afa
authored
Aug 21, 2017
by
Sebastien Chopin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix asynchronous api
parent
200a69da
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
4 deletions
+5
-4
index.js
api/index.js
+3
-2
ItemList.vue
components/ItemList.vue
+2
-2
No files found.
api/index.js
View file @
f70d7afa
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
import
{
createAPI
}
from
'create-api'
import
{
createAPI
}
from
'create-api'
const
logRequests
=
!!
process
.
env
.
DEBUG_API
const
logRequests
=
!!
process
.
env
.
DEBUG_API
let
api
=
{}
let
api
=
null
let
_api
=
createAPI
({
let
_api
=
createAPI
({
version
:
'/v0'
,
version
:
'/v0'
,
...
@@ -64,8 +64,9 @@ export function fetchUser(id) {
...
@@ -64,8 +64,9 @@ export function fetchUser(id) {
return
fetch
(
`user/
${
id
}
`
)
return
fetch
(
`user/
${
id
}
`
)
}
}
export
function
watchList
(
type
,
cb
)
{
export
async
function
watchList
(
type
,
cb
)
{
let
first
=
true
let
first
=
true
await
_api
const
ref
=
api
.
child
(
`
${
type
}
stories`
)
const
ref
=
api
.
child
(
`
${
type
}
stories`
)
const
handler
=
snapshot
=>
{
const
handler
=
snapshot
=>
{
if
(
first
)
{
if
(
first
)
{
...
...
components/ItemList.vue
View file @
f70d7afa
...
@@ -44,12 +44,12 @@ export default {
...
@@ -44,12 +44,12 @@ export default {
}
}
},
},
beforeMount
()
{
async
beforeMount
()
{
if
(
this
.
$root
.
_isMounted
)
{
if
(
this
.
$root
.
_isMounted
)
{
this
.
loadItems
(
this
.
page
)
this
.
loadItems
(
this
.
page
)
}
}
// watch the current list for realtime updates
// 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
.
commit
(
'SET_LIST'
,
{
type
:
this
.
type
,
ids
})
this
.
$store
.
dispatch
(
'ENSURE_ACTIVE_ITEMS'
).
then
(()
=>
{
this
.
$store
.
dispatch
(
'ENSURE_ACTIVE_ITEMS'
).
then
(()
=>
{
this
.
displayedItems
=
this
.
$store
.
getters
.
activeItems
this
.
displayedItems
=
this
.
$store
.
getters
.
activeItems
...
...
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