Flesh out reducers for remaining resources
This commit is contained in:
parent
0050f12c65
commit
59c57f55db
|
@ -1,24 +1,3 @@
|
|||
import {
|
||||
UPDATE_RESOURCES,
|
||||
RESOURCES_REMOVED
|
||||
} from '../actions/resources';
|
||||
|
||||
export default function files(state = {}, action) {
|
||||
switch (action.type) {
|
||||
case UPDATE_RESOURCES:
|
||||
return {
|
||||
...state,
|
||||
...action.resources
|
||||
.filter(r => r.type === "file")
|
||||
.reduce((s, r) => ({
|
||||
...s,
|
||||
[r.id]: { ...state[r.id], ...r }
|
||||
}), {})
|
||||
};
|
||||
case RESOURCES_REMOVED:
|
||||
return Object.values(state)
|
||||
.filter(r => action.ids.indexOf(r.id) === -1)
|
||||
.reduce((s, r) => ({ ...s, [r.id]: r }), {});
|
||||
}
|
||||
return state;
|
||||
}
|
||||
import reducer from './resource';
|
||||
const files = reducer("file");
|
||||
export default files;
|
||||
|
|
|
@ -6,6 +6,9 @@ import filter_subscribe from './filter_subscribe';
|
|||
import server from './server';
|
||||
import torrents from './torrents';
|
||||
import files from './files';
|
||||
import peers from './peers';
|
||||
import trackers from './trackers';
|
||||
import pieces from './pieces';
|
||||
|
||||
const root = combineReducers({
|
||||
selection,
|
||||
|
@ -14,6 +17,9 @@ const root = combineReducers({
|
|||
server,
|
||||
torrents,
|
||||
files,
|
||||
peers,
|
||||
trackers,
|
||||
pieces,
|
||||
router: routerReducer
|
||||
});
|
||||
|
||||
|
|
3
src/reducers/peers.js
Normal file
3
src/reducers/peers.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import reducer from './resource';
|
||||
const peers = reducer("peer");
|
||||
export default peers;
|
3
src/reducers/pieces.js
Normal file
3
src/reducers/pieces.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import reducer from './resource';
|
||||
const pieces = reducer("piece");
|
||||
export default pieces;
|
23
src/reducers/resource.js
Normal file
23
src/reducers/resource.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
import { UPDATE_RESOURCES, RESOURCES_REMOVED } from '../actions/resources';
|
||||
|
||||
export default function resourceReducer(type) {
|
||||
return (state = {}, action) => {
|
||||
switch (action.type) {
|
||||
case UPDATE_RESOURCES:
|
||||
return {
|
||||
...state,
|
||||
...action.resources
|
||||
.filter(r => r.type === type)
|
||||
.reduce((s, r) => ({
|
||||
...s,
|
||||
[r.id]: { ...state[r.id], ...r }
|
||||
}), {})
|
||||
};
|
||||
case RESOURCES_REMOVED:
|
||||
return Object.values(state)
|
||||
.filter(r => action.ids.indexOf(r.id) === -1)
|
||||
.reduce((s, r) => ({ ...s, [r.id]: r }), {});
|
||||
}
|
||||
return state;
|
||||
};
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
import { UNION, SUBTRACT, EXCLUSIVE, NONE } from '../actions/selection';
|
||||
import { RESOURCES_REMOVED } from '../actions/resources';
|
||||
|
||||
export default function selection(state = [], action) {
|
||||
const { ids } = action;
|
||||
|
@ -9,6 +10,8 @@ export default function selection(state = [], action) {
|
|||
return state.filter(id => ids.indexOf(id) === -1);
|
||||
case EXCLUSIVE:
|
||||
return [...ids];
|
||||
case RESOURCES_REMOVED:
|
||||
return state.filter(id => ids.indexOf(id) === -1);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { SUBSCRIBE, UNSUBSCRIBE } from '../actions/subscribe';
|
||||
import { RESOURCES_REMOVED } from '../actions/resources';
|
||||
|
||||
export default function subscribe(state = [], action) {
|
||||
switch (action.type) {
|
||||
|
@ -10,6 +11,8 @@ export default function subscribe(state = [], action) {
|
|||
const { ids } = action;
|
||||
return state.filter(sub => ids.indexOf(sub.id) === -1);
|
||||
}
|
||||
case RESOURCES_REMOVED:
|
||||
return state.filter(sub => ids.indexOf(sub.id) === -1);
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -1,24 +1,3 @@
|
|||
import {
|
||||
UPDATE_RESOURCES,
|
||||
RESOURCES_REMOVED
|
||||
} from '../actions/resources';
|
||||
|
||||
export default function torrents(state = {}, action) {
|
||||
switch (action.type) {
|
||||
case UPDATE_RESOURCES:
|
||||
return {
|
||||
...state,
|
||||
...action.resources
|
||||
.filter(r => r.type === "torrent")
|
||||
.reduce((s, r) => ({
|
||||
...s,
|
||||
[r.id]: { ...state[r.id], ...r }
|
||||
}), {})
|
||||
};
|
||||
case RESOURCES_REMOVED:
|
||||
return Object.values(state)
|
||||
.filter(r => action.ids.indexOf(r.id) === -1)
|
||||
.reduce((s, r) => ({ ...s, [r.id]: r }), {});
|
||||
}
|
||||
return state;
|
||||
}
|
||||
import reducer from './resource';
|
||||
const torrents = reducer("torrent");
|
||||
export default torrents;
|
||||
|
|
3
src/reducers/trackers.js
Normal file
3
src/reducers/trackers.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
import reducer from './resource';
|
||||
const trackers = reducer("tracker");
|
||||
export default trackers;
|
Loading…
Reference in New Issue
Block a user