Remove selectors & reducers

This commit is contained in:
John Furrow
2015-12-14 21:27:57 -08:00
parent da4b6caed5
commit bf24b03a94
8 changed files with 0 additions and 324 deletions
@@ -1,56 +0,0 @@
const initialState = {
torrentDetails: {},
transfers: {
updatedAt: 0,
download: {
rate: 0,
total: 0
},
upload: {
rate: 0,
total: 0
}
}
};
export default function clientReducer(state = initialState, action) {
switch (action.type) {
case 'RECEIVE_TORRENT_DETAILS':
let torrentDetails = {};
torrentDetails[action.payload.hash] = action.payload.torrentDetails;
return Object.assign(
{},
state,
{
...state,
torrentDetails
}
);
case 'CLIENT_RECEIVE_TRANSFER_DATA':
return Object.assign(
{},
state,
{
...state,
transfers: {
...state.transfers,
updatedAt: Date.now(),
download: {
rate: action.payload.downloadRate,
total: action.payload.downloadTotal
},
upload: {
rate: action.payload.uploadRate,
total: action.payload.uploadTotal
}
}
}
);
default:
return state;
}
}
@@ -1,13 +0,0 @@
import {combineReducers} from 'redux';
import client from './clientReducer';
import torrents from './torrentsReducer';
import ui from './uiReducer';
const rootReducer = combineReducers({
client,
torrents,
ui
});
export default rootReducer;
@@ -1,45 +0,0 @@
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,
{
...state,
torrents: action.payload.torrents
}
);
default:
return state;
}
}
@@ -1,85 +0,0 @@
const initialState = {
fetchingData: true,
modal: null,
torrentList: {
count: 0,
filterBy: 'all',
searchString: '',
selected: [],
sortBy: {
direction: 'asc',
displayName: 'Date Added',
property: 'added'
}
}
};
export default function uiReducer(state = initialState, action) {
switch (action.type) {
case 'RECEIVE_TORRENTS':
return Object.assign(
{},
state,
{
...state,
fetchingData: false,
torrentList: {
...state.torrentList,
count: action.payload.torrents.length
}
}
);
case 'UI_DISPLAY_MODAL':
return Object.assign(
{},
state,
{
...state,
modal: action.payload.modal
}
);
case 'UI_SEARCH_TORRENTS':
return Object.assign(
{},
state,
{
...state,
torrentList: {
...state.torrentList,
searchString: action.payload.searchString
}
}
);
case 'UI_SORT_TORRENTS':
return Object.assign(
{},
state,
{
...state,
torrentList: {
...state.torrentList,
sortBy: action.payload.sortBy
}
}
);
case 'UI_FILTER_TORRENTS':
return Object.assign(
{},
state,
{
...state,
torrentList: {
...state.torrentList,
filterBy: action.payload.filterBy
}
}
);
default:
return state;
}
}
@@ -1,7 +0,0 @@
import {createSelector} from 'reselect';
const clientSelector = (state) => {
return state.client;
};
export default clientSelector;
@@ -1,20 +0,0 @@
import {createSelector} from 'reselect';
import clientSelector from './clientSelector';
import torrentSelector from './torrentSelector';
import uiSelector from './uiSelector';
const rootSelector = createSelector(
clientSelector,
torrentSelector,
uiSelector,
(client, torrents, ui) => {
return {
client,
torrents,
ui
};
}
);
export default rootSelector;
@@ -1,51 +0,0 @@
import {createSelector} from 'reselect';
import {filterTorrents} from '../util/filterTorrents';
import {searchTorrents} from '../util/searchTorrents';
import {sortTorrents} from '../util/sortTorrents';
const torrentListSearchString = state => state.ui.torrentList.searchString;
const torrentListSortBy = state => state.ui.torrentList.sortBy;
const torrentListFilterBy = state => state.ui.torrentList.filterBy;
const selectedTorrents = state => state.torrents.selectedTorrents;
const torrentList = state => state.torrents.torrents;
const filteredTorrents = createSelector(
torrentListFilterBy,
torrentList,
(torrentListFilterBy, torrentList) => {
return filterTorrents(torrentList, torrentListFilterBy);
}
);
const searchedTorrents = createSelector(
torrentListSearchString,
filteredTorrents,
(torrentListSearchString, filteredTorrents) => {
return searchTorrents(filteredTorrents, torrentListSearchString);
}
);
const sortedTorrents = createSelector(
searchedTorrents,
torrentListSortBy,
(searchedTorrents, torrentListSortBy) => {
return sortTorrents(searchedTorrents, torrentListSortBy);
}
);
const torrentSelector = createSelector(
selectedTorrents,
sortedTorrents,
(selectedTorrents, sortedTorrents) => {
return {
selectedTorrents,
torrents: sortedTorrents
};
}
);
export default torrentSelector;
@@ -1,47 +0,0 @@
import {createSelector} from 'reselect';
const fetchingData = state => state.ui.fetchingData;
const modal = state => state.ui.modal;
const torrentListCount = state => state.ui.torrentList.count;
const torrentListSelected = state => state.torrents.selectedTorrents;
const torrentListSearchString = state => state.ui.torrentList.searchString;
const torrentListSortBy = state => state.ui.torrentList.sortBy;
const torrentListFilterBy = state => state.ui.torrentList.filterBy;
const torrentList = createSelector(
torrentListCount,
torrentListSearchString,
torrentListSelected,
torrentListSortBy,
torrentListFilterBy,
(count, searchString, selected, sortBy, filterBy) => {
return {
count,
searchString,
selected,
sortBy,
filterBy
};
}
);
const uiSelector = createSelector(
fetchingData,
modal,
torrentList,
(fetchingData, modal, torrentList) => {
return {
fetchingData,
modal,
torrentList
};
}
);
export default uiSelector;