Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
simplevuestore
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Adam Procter
simplevuestore
Commits
44948440
Commit
44948440
authored
Apr 10, 2019
by
Adam Procter
💩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vuex and pouch data /sync to couch
parent
e98b5f86
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
7 deletions
+68
-7
src/components/DisplayText.vue
src/components/DisplayText.vue
+1
-1
src/store.js
src/store.js
+67
-6
No files found.
src/components/DisplayText.vue
View file @
44948440
<
template
>
<div>
<p>
You
like
{{
$store
.
getters
.
currentflavour
}}
</p>
<p>
You
r current fav flavour is:
{{
$store
.
getters
.
currentflavour
}}
</p>
</div>
</
template
>
...
...
src/store.js
View file @
44948440
import
Vue
from
'
vue
'
import
Vuex
from
'
vuex
'
import
PouchDB
from
'
pouchdb
'
Vue
.
use
(
Vuex
)
export
default
new
Vuex
.
Store
({
state
:
{
flavour
:
null
},
var
pouchdb
=
new
PouchDB
(
'
icecream
'
)
var
remote
=
'
https://nn.adamprocter.co.uk/icecream
'
const
store
=
new
Vuex
.
Store
({
state
:
{
flavour
:
null
},
mutations
:
{
GET_DB
(
state
)
{
pouchdb
.
get
(
'
myfav
'
)
.
then
(
function
(
doc
)
{
state
.
flavour
=
doc
.
flavour
})
.
catch
(
function
(
err
)
{
console
.
log
(
err
)
})
},
CHANGE_STATE
(
state
,
flavour
)
{
state
.
flavour
=
flavour
pouchdb
.
get
(
'
myfav
'
)
.
then
(
function
(
doc
)
{
return
pouchdb
.
put
({
_id
:
'
myfav
'
,
_rev
:
doc
.
_rev
,
flavour
:
flavour
})
})
.
then
(
function
(
response
)
{
// handle response
if
(
response
.
ok
==
true
)
{
//if all good could do something
}
})
.
catch
(
function
(
err
)
{})
},
CLEAR_STATE
()
{
this
.
replaceState
({
flavour
:
null
})
store
.
replaceState
({
flavour
:
null
})
}
},
actions
:
{
SYNC_DB
()
{
pouchdb
.
sync
(
remote
,
{
live
:
true
,
retry
:
true
})
},
INCOMING_CHANGE
(
_state
,
event
)
{
this
.
commit
(
'
CHANGE_STATE
'
,
event
)
var
id
=
'
myfav
'
store
.
commit
(
'
CHANGE_STATE
'
,
event
)
// send change also to the pouch
pouchdb
.
get
(
'
myfav
'
)
.
then
(
function
(
doc
)
{
return
pouchdb
.
put
({
_id
:
'
myfav
'
,
_rev
:
doc
.
_rev
,
flavour
:
event
})
})
.
then
(
function
(
response
)
{
// handle response
if
(
response
.
ok
==
true
)
{
//if all good could do something
}
})
.
catch
(
function
(
err
)
{
if
(
err
.
status
==
404
)
{
pouchdb
.
put
({
_id
:
id
,
flavour
:
event
})
}
})
}
},
getters
:
{
//flavour: state => state.flavour
currentflavour
:
state
=>
{
return
state
.
flavour
}
}
})
export
default
store
store
.
dispatch
(
'
SYNC_DB
'
)
store
.
commit
(
'
GET_DB
'
)
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