Insert state into strategic components rather than entire app

This commit is contained in:
John Furrow
2015-11-08 21:34:05 -08:00
parent cf11f386d8
commit 535652d074
12 changed files with 227 additions and 126 deletions
@@ -1,10 +1,42 @@
export default function torrentsReducer(state = [], action) {
import { selectTorrents } from '../util/selectTorrents';
const initialState = {
selectedTorrents: [],
torrents: []
};
export default function torrentsReducer(state = initialState, action) {
switch (action.type) {
case 'CLICK_TORRENT':
let event = action.payload.event;
let hash = action.payload.hash;
let selectedTorrents = Object.assign([], state.selectedTorrents);
let torrentList = action.payload.torrentList;
selectedTorrents = selectTorrents({
event,
hash,
selectedTorrents,
torrentList
});
return Object.assign(
{},
state,
{
...state,
selectedTorrents: selectedTorrents
}
);
case 'RECEIVE_TORRENTS':
return Object.assign(
[],
{},
state,
action.payload.torrents
{
...state,
torrents: action.payload.torrents
}
);
default:
+1 -38
View File
@@ -1,5 +1,3 @@
import { selectTorrents } from '../util/selectTorrents';
const initialState = {
fetchingData: true,
modal: null,
@@ -14,45 +12,10 @@ const initialState = {
property: 'added'
}
}
}
};
export default function uiReducer(state = initialState, action) {
switch (action.type) {
case 'CLICK_TORRENT':
let event = action.payload.event;
let hash = action.payload.hash;
let selectedTorrents = Object.assign([], state.torrentList.selected);
let torrentList = action.payload.torrentList;
selectedTorrents = selectTorrents({
event,
hash,
selectedTorrents,
torrentList
});
return Object.assign(
{},
state,
{
...state,
torrentList: {
...state.torrentList,
selected: selectedTorrents
}
}
);
case 'REQUEST_TORRENTS':
return Object.assign(
{},
state,
{
...state,
fetchingData: true
}
);
case 'RECEIVE_TORRENTS':
return Object.assign(
{},