Move chat to own module.

This commit is contained in:
Roger Braun 2017-12-05 11:47:10 +01:00
parent 0e51fac2b2
commit 27be1e0fa3
5 changed files with 55 additions and 22 deletions

View file

@ -1,23 +1,18 @@
const chat = {
data () {
return {
messages: [],
currentMessage: '',
socket: this.$store.state.users.socket,
channel: null
}
},
created () {
this.channel = this.socket.channel('chat:public')
this.channel.on('new_msg', (msg) => {
this.messages.push(msg)
this.messages = this.messages.slice(-19, 20)
})
this.channel.join()
computed: {
messages () {
return this.$store.state.chat.messages
}
},
methods: {
submit(message) {
this.channel.push('new_msg', {text: message}, 10000)
this.$store.state.chat.channel.push('new_msg', {text: message}, 10000)
this.currentMessage = '';
}
}