From bf24b03a946da21304094de1850a7fd9dc695fdb Mon Sep 17 00:00:00 2001 From: John Furrow Date: Mon, 14 Dec 2015 21:27:57 -0800 Subject: [PATCH] Remove selectors & reducers --- .../source/scripts/reducers/clientReducer.js | 56 ------------ client/source/scripts/reducers/rootReducer.js | 13 --- .../scripts/reducers/torrentsReducer.js | 45 ---------- client/source/scripts/reducers/uiReducer.js | 85 ------------------- .../scripts/selectors/clientSelector.js | 7 -- .../source/scripts/selectors/rootSelector.js | 20 ----- .../scripts/selectors/torrentSelector.js | 51 ----------- client/source/scripts/selectors/uiSelector.js | 47 ---------- 8 files changed, 324 deletions(-) delete mode 100644 client/source/scripts/reducers/clientReducer.js delete mode 100644 client/source/scripts/reducers/rootReducer.js delete mode 100644 client/source/scripts/reducers/torrentsReducer.js delete mode 100644 client/source/scripts/reducers/uiReducer.js delete mode 100644 client/source/scripts/selectors/clientSelector.js delete mode 100644 client/source/scripts/selectors/rootSelector.js delete mode 100644 client/source/scripts/selectors/torrentSelector.js delete mode 100644 client/source/scripts/selectors/uiSelector.js diff --git a/client/source/scripts/reducers/clientReducer.js b/client/source/scripts/reducers/clientReducer.js deleted file mode 100644 index 7cb0ed9c..00000000 --- a/client/source/scripts/reducers/clientReducer.js +++ /dev/null @@ -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; - } -} diff --git a/client/source/scripts/reducers/rootReducer.js b/client/source/scripts/reducers/rootReducer.js deleted file mode 100644 index e6f3bde1..00000000 --- a/client/source/scripts/reducers/rootReducer.js +++ /dev/null @@ -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; diff --git a/client/source/scripts/reducers/torrentsReducer.js b/client/source/scripts/reducers/torrentsReducer.js deleted file mode 100644 index bea88ab9..00000000 --- a/client/source/scripts/reducers/torrentsReducer.js +++ /dev/null @@ -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; - } -} diff --git a/client/source/scripts/reducers/uiReducer.js b/client/source/scripts/reducers/uiReducer.js deleted file mode 100644 index 76ce5453..00000000 --- a/client/source/scripts/reducers/uiReducer.js +++ /dev/null @@ -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; - } -} diff --git a/client/source/scripts/selectors/clientSelector.js b/client/source/scripts/selectors/clientSelector.js deleted file mode 100644 index 4282be19..00000000 --- a/client/source/scripts/selectors/clientSelector.js +++ /dev/null @@ -1,7 +0,0 @@ -import {createSelector} from 'reselect'; - -const clientSelector = (state) => { - return state.client; -}; - -export default clientSelector; diff --git a/client/source/scripts/selectors/rootSelector.js b/client/source/scripts/selectors/rootSelector.js deleted file mode 100644 index 611a9164..00000000 --- a/client/source/scripts/selectors/rootSelector.js +++ /dev/null @@ -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; diff --git a/client/source/scripts/selectors/torrentSelector.js b/client/source/scripts/selectors/torrentSelector.js deleted file mode 100644 index fce2408c..00000000 --- a/client/source/scripts/selectors/torrentSelector.js +++ /dev/null @@ -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; diff --git a/client/source/scripts/selectors/uiSelector.js b/client/source/scripts/selectors/uiSelector.js deleted file mode 100644 index 07b16a18..00000000 --- a/client/source/scripts/selectors/uiSelector.js +++ /dev/null @@ -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;