Unsubscribe to removed resources

master
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

@ -16,7 +16,7 @@ export default function resourceReducer(type) {
switch (action.type) { switch (action.type) {
case UPDATE_RESOURCES: case UPDATE_RESOURCES:
action.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 })); .map(r => ns[r.id] = hack(state[r.id], { ...state[r.id], ...r }));
return ns; return ns;
case RESOURCES_REMOVED: case RESOURCES_REMOVED:

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) {