mirror of
https://github.com/zoriya/flood.git
synced 2026-06-01 02:29:01 +00:00
Insert state into strategic components rather than entire app
This commit is contained in:
@@ -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,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(
|
||||
{},
|
||||
|
||||
Reference in New Issue
Block a user