Unsubscribe to removed resources

This commit is contained in:
Drew DeVault 2018-03-10 09:48:10 -05:00
parent 7354ab21e9
commit f3c9d9882b
2 changed files with 8 additions and 3 deletions

View File

@ -1,5 +1,5 @@
import { dispatch } from './store'; import { dispatch } from './store';
import { subscribe } from './actions/subscribe'; import { subscribe, unsubscribe } from './actions/subscribe';
let ws; let ws;
let serial = 0; let serial = 0;
@ -30,10 +30,15 @@ export default function ws_send(type, body, callback = null, __serial = null) {
return _serial; return _serial;
} }
function _resources_removed(msg) {
dispatch(unsubscribe(...msg.ids));
dispatch(msg);
}
const handlers = { const handlers = {
RESOURCES_EXTANT: msg => dispatch(subscribe(...msg.ids)), RESOURCES_EXTANT: msg => dispatch(subscribe(...msg.ids)),
UPDATE_RESOURCES: msg => dispatch(msg), UPDATE_RESOURCES: msg => dispatch(msg),
RESOURCES_REMOVED: msg => dispatch(msg), RESOURCES_REMOVED: msg => _resources_removed(msg),
}; };
function ws_recv(e) { function ws_recv(e) {