mirror of
https://github.com/tenrok/vue-native-websocket.git
synced 2026-06-09 03:12:26 +03: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:
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+4
-4
@@ -30,24 +30,24 @@ export default class{
|
||||
.forEach((value) => {
|
||||
_this.Socket.on(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){
|
||||
if(!event.toUpperCase().startsWith('SOCKET_')) return
|
||||
if(!event.startsWith('SOCKET_')) return
|
||||
|
||||
for(let namespaced in this.store._mutations) {
|
||||
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) {
|
||||
let action = namespaced.split('/').pop()
|
||||
|
||||
if(!action.toLowerCase().startsWith('socket_')) continue
|
||||
if(!action.startsWith('socket_')) continue
|
||||
|
||||
let camelcased = 'socket_'+event
|
||||
.replace('SOCKET_', '')
|
||||
|
||||
Reference in New Issue
Block a user