mirror of
https://github.com/MetinSeylan/Vue-Socket.io.git
synced 2025-04-16 15:21:28 +02:00
Add support to native events
Native event was passed capitalized which cause unexpected camelCase conversion. Event is now passed without uppercasing and save string transformations e.g. SOCKET_CONNECT => `socket_cONNECT` instead of `socket_connect` SOCKET_CONNECT_ERROR => `socket_cONNECTERROR` instead of `socket_connectError`
This commit is contained in:
parent
3a86a906d5
commit
8709b16a78
2 changed files with 5 additions and 5 deletions
2
dist/build.js
vendored
2
dist/build.js
vendored
File diff suppressed because one or more lines are too long
|
@ -30,24 +30,24 @@ export default class{
|
||||||
.forEach((value) => {
|
.forEach((value) => {
|
||||||
_this.Socket.on(value, (data) => {
|
_this.Socket.on(value, (data) => {
|
||||||
Emitter.emit(value, data);
|
Emitter.emit(value, data);
|
||||||
if(_this.store) _this.passToStore('SOCKET_'+value.toUpperCase(), data)
|
if(_this.store) _this.passToStore('SOCKET_'+value, data)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
passToStore(event, payload){
|
passToStore(event, payload){
|
||||||
if(!event.toUpperCase().startsWith('SOCKET_')) return
|
if(!event.startsWith('SOCKET_')) return
|
||||||
|
|
||||||
for(let namespaced in this.store._mutations) {
|
for(let namespaced in this.store._mutations) {
|
||||||
let mutation = namespaced.split('/').pop()
|
let mutation = namespaced.split('/').pop()
|
||||||
if(mutation === event) this.store.commit(namespaced, payload)
|
if(mutation === event.toUpperCase()) this.store.commit(namespaced, payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
for(let namespaced in this.store._actions) {
|
for(let namespaced in this.store._actions) {
|
||||||
let action = namespaced.split('/').pop()
|
let action = namespaced.split('/').pop()
|
||||||
|
|
||||||
if(!action.toLowerCase().startsWith('socket_')) continue
|
if(!action.startsWith('socket_')) continue
|
||||||
|
|
||||||
let camelcased = 'socket_'+event
|
let camelcased = 'socket_'+event
|
||||||
.replace('SOCKET_', '')
|
.replace('SOCKET_', '')
|
||||||
|
|
Loading…
Add table
Reference in a new issue