From f3c9d9882bb32aba8c20660359bc4a28800964e7 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Sat, 10 Mar 2018 09:48:10 -0500 Subject: [PATCH] Unsubscribe to removed resources --- src/reducers/resource.js | 2 +- src/socket.js | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/reducers/resource.js b/src/reducers/resource.js index f6db220..a925f0c 100644 --- a/src/reducers/resource.js +++ b/src/reducers/resource.js @@ -16,7 +16,7 @@ export default function resourceReducer(type) { switch (action.type) { case UPDATE_RESOURCES: action.resources - .filter(r => r.type ===type) + .filter(r => r.type === type) .map(r => ns[r.id] = hack(state[r.id], { ...state[r.id], ...r })); return ns; case RESOURCES_REMOVED: diff --git a/src/socket.js b/src/socket.js index 5bf3813..c33ee3c 100644 --- a/src/socket.js +++ b/src/socket.js @@ -1,5 +1,5 @@ import { dispatch } from './store'; -import { subscribe } from './actions/subscribe'; +import { subscribe, unsubscribe } from './actions/subscribe'; let ws; let serial = 0; @@ -30,10 +30,15 @@ export default function ws_send(type, body, callback = null, __serial = null) { return _serial; } +function _resources_removed(msg) { + dispatch(unsubscribe(...msg.ids)); + dispatch(msg); +} + const handlers = { RESOURCES_EXTANT: msg => dispatch(subscribe(...msg.ids)), UPDATE_RESOURCES: msg => dispatch(msg), - RESOURCES_REMOVED: msg => dispatch(msg), + RESOURCES_REMOVED: msg => _resources_removed(msg), }; function ws_recv(e) {