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
328ef229
Commit
328ef229
authored
Jun 04, 2019
by
Sébastien Chopin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: Refactor store for better lisibility
parent
3f5ae21d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
36 deletions
+37
-36
index.js
store/index.js
+37
-36
No files found.
store/index.js
View file @
328ef229
...
...
@@ -4,12 +4,13 @@ import { validFeeds } from '~/common/api'
import
{
lazy
}
from
'~/common/utils'
import
{
CancelToken
}
from
'axios'
export
default
{
// =================================================
// State
// =================================================
state
:
()
=>
{
const
state
=
{
// Learn more on https://nuxtjs.org/guide/vuex-store
// =================================================
// State
// =================================================
export
const
state
=
()
=>
{
const
s
=
{
items
:
{
/* [id: number]: Item */
},
...
...
@@ -22,15 +23,39 @@ export default {
}
validFeeds
.
forEach
((
feed
)
=>
{
state
.
feeds
[
feed
]
=
{}
s
.
feeds
[
feed
]
=
{}
})
return
state
return
s
}
// =================================================
// Mutations
// =================================================
export
const
mutations
=
{
SET_FEED
:
(
state
,
{
feed
,
ids
,
page
})
=>
{
Vue
.
set
(
state
.
feeds
[
feed
],
page
,
ids
)
},
// =================================================
// Actions
// =================================================
actions
:
{
SET_ITEM
:
(
state
,
{
item
})
=>
{
if
(
item
)
{
Vue
.
set
(
state
.
items
,
item
.
id
,
item
)
}
},
SET_ITEMS
:
(
state
,
{
items
})
=>
{
items
.
forEach
((
item
)
=>
{
if
(
item
)
{
Vue
.
set
(
state
.
items
,
item
.
id
,
item
)
}
})
},
SET_USER
:
(
state
,
{
id
,
user
})
=>
{
Vue
.
set
(
state
.
users
,
id
,
user
||
false
)
/* false means user not found */
}
}
// =================================================
// Actions
// =================================================
export
const
actions
=
{
FETCH_FEED
({
commit
,
state
},
{
feed
,
page
,
prefetch
})
{
// Don't priorotize already fetched feeds
if
(
state
.
feeds
[
feed
][
page
]
&&
state
.
feeds
[
feed
][
page
].
length
)
{
...
...
@@ -74,28 +99,4 @@ export default {
Object
.
assign
({
id
,
loading
:
true
},
state
.
users
[
id
])
)
}
},
// =================================================
// Mutations
// =================================================
mutations
:
{
SET_FEED
:
(
state
,
{
feed
,
ids
,
page
})
=>
{
Vue
.
set
(
state
.
feeds
[
feed
],
page
,
ids
)
},
SET_ITEM
:
(
state
,
{
item
})
=>
{
if
(
item
)
{
Vue
.
set
(
state
.
items
,
item
.
id
,
item
)
}
},
SET_ITEMS
:
(
state
,
{
items
})
=>
{
items
.
forEach
((
item
)
=>
{
if
(
item
)
{
Vue
.
set
(
state
.
items
,
item
.
id
,
item
)
}
})
},
SET_USER
:
(
state
,
{
id
,
user
})
=>
{
Vue
.
set
(
state
.
users
,
id
,
user
||
false
)
/* false means user not found */
}
}
}
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