Add start of event sourcing

This commit is contained in:
Peter Stuifzand 2018-12-29 10:43:05 +01:00
parent ca8764896b
commit 3d484def87
3 changed files with 46 additions and 6 deletions

View File

@ -8,6 +8,7 @@
"lint": "vue-cli-service lint"
},
"dependencies": {
"event-source-polyfill": "0.0.16",
"isomorphic-fetch": "^2.2.1",
"micropub-helper": "^1.4.0",
"moment": "^2.22.2",

View File

@ -11,9 +11,19 @@
<textarea class="textarea" v-model="newPost"></textarea>
</div>
</div>
<div class="field">
<div class="control">
<button class="button is-primary" @click="post">Post</button>
<div class="level">
<div class="level-left">
<div class="level-item">
<div class="field">
<div class="control">
<button class="button is-primary" @click="post">Post</button>
</div>
</div>
</div>
</div>
<div class="level-right">
<div class="level-item">
</div>
</div>
</div>
</div>
@ -27,7 +37,8 @@
name: "NewPost",
data() {
return {
newPost: ''
newPost: '',
tags: [{name:"twitter"},{name:"instagram"}]
}
},
methods: {

View File

@ -1,6 +1,7 @@
import Vue from 'vue'
import Vuex from 'vuex'
import Micropub from 'micropub-helper';
import EventSource from 'eventsource'
Vue.use(Vuex)
@ -13,8 +14,9 @@ export default new Vuex.Store({
debug: false,
logged_in: false,
micropubEndpoint: '',
microsubEndpoint: '',
channelCreatorIsOpen: false
microsubEndpoint: '/microsub',
channelCreatorIsOpen: false,
eventSource: null
};
let loginData = JSON.parse(window.localStorage.getItem('login_data'))
if (loginData) {
@ -51,6 +53,29 @@ export default new Vuex.Store({
},
setChannelCreatorState(state, open) {
state.channelCreatorIsOpen = open
},
createEventSource(state, url) {
state.eventSource = new EventSource(state.microsubEndpoint + url, {
headers: {
'Authorization': 'Bearer ' + this.state.access_token
}
})
state.eventSource.addEventListener('open', evt => {
// eslint-disable-next-line
console.log(evt)
})
state.eventSource.addEventListener('ping', evt => {
// eslint-disable-next-line
console.log(evt)
})
state.eventSource.addEventListener('message', evt => {
// eslint-disable-next-line
console.log(evt)
})
state.eventSource.addEventListener('error', evt => {
// eslint-disable-next-line
console.log(evt)
})
}
},
@ -153,6 +178,9 @@ export default new Vuex.Store({
if (count > 0) {
this.dispatch('fetchChannels')
}
},
startEventListening({commit}, url) {
commit('createEventSource', url)
}
}
})