2
0
mirror of https://github.com/tenrok/vue-native-websocket.git synced 2026-06-11 23:22:26 +03:00

Add custom pass to store handler

This commit is contained in:
Joshua Morris
2018-06-05 11:34:25 -06:00
parent 649485e28b
commit 4d8bf21ab4
5 changed files with 60 additions and 3 deletions
+10
View File
@@ -12,6 +12,8 @@ export default class {
this.reconnectTimeoutId = 0
this.reconnectionCount = 0
this.passToStoreHandler = this.opts.passToStoreHandler || false
this.connect(connectionUrl, opts)
if (opts.store) { this.store = opts.store }
@@ -61,6 +63,14 @@ export default class {
}
passToStore (eventName, event) {
if (this.passToStoreHandler) {
this.passToStoreHandler(eventName, event, this.defaultPassToStore)
} else {
this.defaultPassToStore(eventName, event)
}
}
defaultPassToStore (eventName, event) {
if (!eventName.startsWith('SOCKET_')) { return }
let method = 'commit'
let target = eventName.toUpperCase()