Use config

This commit is contained in:
John Furrow
2015-12-15 23:32:28 -08:00
parent 3a56da6d1c
commit ad34bf6eaa
3 changed files with 54 additions and 48 deletions

View File

@@ -2,11 +2,9 @@ import ActionTypes from '../constants/ActionTypes';
import AppDispatcher from '../dispatcher/AppDispatcher'; import AppDispatcher from '../dispatcher/AppDispatcher';
import BaseStore from './BaseStore'; import BaseStore from './BaseStore';
import ClientActions from '../actions/ClientActions'; import ClientActions from '../actions/ClientActions';
import config from '../config/config';
import EventTypes from '../constants/EventTypes'; import EventTypes from '../constants/EventTypes';
const historyLength = 100;
const pollInterval = 5000;
class ClientDataStoreClass extends BaseStore { class ClientDataStoreClass extends BaseStore {
constructor() { constructor() {
super(); super();
@@ -54,14 +52,14 @@ class ClientDataStoreClass extends BaseStore {
let downloadRateHistory = Object.assign([], this.transferRates.download); let downloadRateHistory = Object.assign([], this.transferRates.download);
let uploadRateHistory = Object.assign([], this.transferRates.upload); let uploadRateHistory = Object.assign([], this.transferRates.upload);
if (uploadRateHistory.length === historyLength) { if (uploadRateHistory.length === config.maxHistoryStates) {
downloadRateHistory.shift(); downloadRateHistory.shift();
uploadRateHistory.shift(); uploadRateHistory.shift();
downloadRateHistory.push(parseInt(transferData.downloadRate)); downloadRateHistory.push(parseInt(transferData.downloadRate));
uploadRateHistory.push(parseInt(transferData.uploadRate)); uploadRateHistory.push(parseInt(transferData.uploadRate));
} else { } else {
while (index < historyLength) { while (index < config.maxHistoryStates) {
if (index < historyLength - 1) { if (index < config.maxHistoryStates - 1) {
uploadRateHistory[index] = 0; uploadRateHistory[index] = 0;
downloadRateHistory[index] = 0; downloadRateHistory[index] = 0;
} else { } else {
@@ -87,7 +85,7 @@ class ClientDataStoreClass extends BaseStore {
startPollingTransferData() { startPollingTransferData() {
this.pollTransferDataID = setInterval( this.pollTransferDataID = setInterval(
this.fetchTransferData.bind(this), this.fetchTransferData.bind(this),
pollInterval config.pollInterval
); );
} }

View File

@@ -3,6 +3,7 @@ import _ from 'lodash';
import ActionTypes from '../constants/ActionTypes'; import ActionTypes from '../constants/ActionTypes';
import AppDispatcher from '../dispatcher/AppDispatcher'; import AppDispatcher from '../dispatcher/AppDispatcher';
import BaseStore from './BaseStore'; import BaseStore from './BaseStore';
import config from '../config/config';
import EventTypes from '../constants/EventTypes'; import EventTypes from '../constants/EventTypes';
import {filterTorrents} from '../util/filterTorrents'; import {filterTorrents} from '../util/filterTorrents';
import {searchTorrents} from '../util/searchTorrents'; import {searchTorrents} from '../util/searchTorrents';
@@ -12,16 +13,13 @@ import TorrentActions from '../actions/TorrentActions';
import TorrentFilterStore from './TorrentFilterStore'; import TorrentFilterStore from './TorrentFilterStore';
import UIStore from './UIStore'; import UIStore from './UIStore';
const pollInterval = 5000;
class TorrentStoreClass extends BaseStore { class TorrentStoreClass extends BaseStore {
constructor() { constructor() {
super(); super();
this.filteredTorrents = [];
this.pollTorrentDetailsIntervalID = null; this.pollTorrentDetailsIntervalID = null;
this.pollTorrentsIntervalID = null; this.pollTorrentsIntervalID = null;
this.isPollingTorrentDetails = false;
this.isPollingTorrents = false;
this.selectedTorrents = []; this.selectedTorrents = [];
this.torrentDetails = {}; this.torrentDetails = {};
this.torrents = []; this.torrents = [];
@@ -29,7 +27,7 @@ class TorrentStoreClass extends BaseStore {
fetchTorrentDetails() { fetchTorrentDetails() {
TorrentActions.fetchTorrentDetails(UIStore.getTorrentDetailsHash()); TorrentActions.fetchTorrentDetails(UIStore.getTorrentDetailsHash());
if (!this.isPollingTorrentDetails) { if (this.pollTorrentDetailsIntervalID === null) {
this.stopPollingTorrentDetails(); this.stopPollingTorrentDetails();
this.startPollingTorrentDetails(); this.startPollingTorrentDetails();
} }
@@ -38,7 +36,7 @@ class TorrentStoreClass extends BaseStore {
fetchTorrents() { fetchTorrents() {
TorrentActions.fetchTorrents(); TorrentActions.fetchTorrents();
if (!this.isPollingTorrents) { if (this.pollTorrentsIntervalID === null) {
this.startPollingTorrents(); this.startPollingTorrents();
} }
} }
@@ -108,29 +106,27 @@ class TorrentStoreClass extends BaseStore {
} }
startPollingTorrentDetails() { startPollingTorrentDetails() {
this.isPollingTorrentDetails = true;
this.pollTorrentDetailsIntervalID = setInterval( this.pollTorrentDetailsIntervalID = setInterval(
this.fetchTorrentDetails.bind(this), this.fetchTorrentDetails.bind(this),
pollInterval config.pollInterval
); );
} }
startPollingTorrents() { startPollingTorrents() {
this.isPollingTorrents = true;
this.pollTorrentsIntervalID = setInterval( this.pollTorrentsIntervalID = setInterval(
this.fetchTorrents.bind(this), this.fetchTorrents.bind(this),
pollInterval config.pollInterval
); );
} }
stopPollingTorrentDetails() { stopPollingTorrentDetails() {
clearInterval(this.pollTorrentDetailsIntervalID); clearInterval(this.pollTorrentDetailsIntervalID);
this.isPollingTorrents = false; this.pollTorrentDetailsIntervalID = null;
} }
stopPollingTorrents() { stopPollingTorrents() {
clearInterval(this.pollTorrentsIntervalID); clearInterval(this.pollTorrentsIntervalID);
this.isPollingTorrentDetails = false; this.pollTorrentsIntervalID = null;
} }
triggerTorrentsFilter() { triggerTorrentsFilter() {

File diff suppressed because one or more lines are too long