Rename AutoRefresh util to AutoRefresher

So as not to be confused with `autoRefresh` props, which are of type
number.
pull/4297/head
Christopher Henn 2018-08-29 12:59:05 -07:00 committed by Chris Henn
parent ef9fc85654
commit 1e8088d60d
5 changed files with 28 additions and 28 deletions

View File

@ -37,7 +37,7 @@ import idNormalizer, {TYPE_ID} from 'src/normalizers/id'
import {millisecondTimeRange} from 'src/dashboards/utils/time' import {millisecondTimeRange} from 'src/dashboards/utils/time'
import {getDeep} from 'src/utils/wrappers' import {getDeep} from 'src/utils/wrappers'
import {updateDashboardLinks} from 'src/dashboards/utils/dashboardSwitcherLinks' import {updateDashboardLinks} from 'src/dashboards/utils/dashboardSwitcherLinks'
import {GlobalAutoRefresh} from 'src/utils/AutoRefresh' import {GlobalAutoRefresher} from 'src/utils/AutoRefresher'
// APIs // APIs
import {loadDashboardLinks} from 'src/dashboards/apis' import {loadDashboardLinks} from 'src/dashboards/apis'
@ -179,8 +179,8 @@ class DashboardPage extends Component<Props, State> {
public async componentDidMount() { public async componentDidMount() {
const {autoRefresh} = this.props const {autoRefresh} = this.props
GlobalAutoRefresh.poll(autoRefresh) GlobalAutoRefresher.poll(autoRefresh)
GlobalAutoRefresh.subscribe(this.fetchAnnotations) GlobalAutoRefresher.subscribe(this.fetchAnnotations)
window.addEventListener('resize', this.handleWindowResize, true) window.addEventListener('resize', this.handleWindowResize, true)
@ -214,7 +214,7 @@ class DashboardPage extends Component<Props, State> {
} }
if (autoRefresh !== prevProps.autoRefresh) { if (autoRefresh !== prevProps.autoRefresh) {
GlobalAutoRefresh.poll(autoRefresh) GlobalAutoRefresher.poll(autoRefresh)
} }
if ( if (
@ -226,8 +226,8 @@ class DashboardPage extends Component<Props, State> {
} }
public componentWillUnmount() { public componentWillUnmount() {
GlobalAutoRefresh.stopPolling() GlobalAutoRefresher.stopPolling()
GlobalAutoRefresh.unsubscribe(this.fetchAnnotations) GlobalAutoRefresher.unsubscribe(this.fetchAnnotations)
window.removeEventListener('resize', this.handleWindowResize, true) window.removeEventListener('resize', this.handleWindowResize, true)
this.props.handleDismissEditingAnnotation() this.props.handleDismissEditingAnnotation()

View File

@ -9,7 +9,7 @@ import _ from 'lodash'
// Utils // Utils
import {stripPrefix} from 'src/utils/basepath' import {stripPrefix} from 'src/utils/basepath'
import {GlobalAutoRefresh} from 'src/utils/AutoRefresh' import {GlobalAutoRefresher} from 'src/utils/AutoRefresher'
// Components // Components
import QueryMaker from 'src/data_explorer/components/QueryMaker' import QueryMaker from 'src/data_explorer/components/QueryMaker'
@ -82,7 +82,7 @@ export class DataExplorer extends PureComponent<Props, State> {
await handleGetDashboards() await handleGetDashboards()
} }
GlobalAutoRefresh.poll(autoRefresh) GlobalAutoRefresher.poll(autoRefresh)
if (query && query.length) { if (query && query.length) {
const qc = this.props.queryConfigs[0] const qc = this.props.queryConfigs[0]
@ -97,7 +97,7 @@ export class DataExplorer extends PureComponent<Props, State> {
public componentDidUpdate(prevProps: Props) { public componentDidUpdate(prevProps: Props) {
const {autoRefresh} = this.props const {autoRefresh} = this.props
if (autoRefresh !== prevProps.autoRefresh) { if (autoRefresh !== prevProps.autoRefresh) {
GlobalAutoRefresh.poll(autoRefresh) GlobalAutoRefresher.poll(autoRefresh)
} }
} }
@ -116,7 +116,7 @@ export class DataExplorer extends PureComponent<Props, State> {
} }
public componentWillUnmount() { public componentWillUnmount() {
GlobalAutoRefresh.stopPolling() GlobalAutoRefresher.stopPolling()
} }
public render() { public render() {

View File

@ -20,7 +20,7 @@ import {EMPTY_LINKS} from 'src/dashboards/constants/dashboardHeader'
import {setAutoRefresh, delayEnablePresentationMode} from 'shared/actions/app' import {setAutoRefresh, delayEnablePresentationMode} from 'shared/actions/app'
import {ErrorHandling} from 'src/shared/decorators/errors' import {ErrorHandling} from 'src/shared/decorators/errors'
import {GlobalAutoRefresh} from 'src/utils/AutoRefresh' import {GlobalAutoRefresher} from 'src/utils/AutoRefresher'
@ErrorHandling @ErrorHandling
class HostPage extends Component { class HostPage extends Component {
@ -55,7 +55,7 @@ class HostPage extends Component {
} = await getLayouts() } = await getLayouts()
const {location, autoRefresh} = this.props const {location, autoRefresh} = this.props
GlobalAutoRefresh.poll(autoRefresh) GlobalAutoRefresher.poll(autoRefresh)
// fetching layouts and mappings can be done at the same time // fetching layouts and mappings can be done at the same time
const {host, measurements} = await this.fetchHostsAndMeasurements(layouts) const {host, measurements} = await this.fetchHostsAndMeasurements(layouts)
@ -82,12 +82,12 @@ class HostPage extends Component {
componentDidUpdate(prevProps) { componentDidUpdate(prevProps) {
const {autoRefresh} = this.props const {autoRefresh} = this.props
if (prevProps.autoRefresh !== autoRefresh) { if (prevProps.autoRefresh !== autoRefresh) {
GlobalAutoRefresh.poll(autoRefresh) GlobalAutoRefresher.poll(autoRefresh)
} }
} }
componentWillUnmount() { componentWillUnmount() {
GlobalAutoRefresh.stopPolling() GlobalAutoRefresher.stopPolling()
} }
handleChooseTimeRange = ({lower, upper}) => { handleChooseTimeRange = ({lower, upper}) => {

View File

@ -19,7 +19,7 @@ import {TimeSeriesServerResponse, TimeSeriesResponse} from 'src/types/series'
import {GrabDataForDownloadHandler} from 'src/types/layout' import {GrabDataForDownloadHandler} from 'src/types/layout'
// Utils // Utils
import {GlobalAutoRefresh, AutoRefresh} from 'src/utils/AutoRefresh' import {GlobalAutoRefresher, AutoRefresher} from 'src/utils/AutoRefresher'
import {CellNoteVisibility} from 'src/types/dashboards' import {CellNoteVisibility} from 'src/types/dashboards'
// Components // Components
@ -39,7 +39,7 @@ interface Props {
queries: Query[] queries: Query[]
timeRange: TimeRange timeRange: TimeRange
children: (r: RenderProps) => JSX.Element children: (r: RenderProps) => JSX.Element
autoRefresh?: AutoRefresh autoRefresher?: AutoRefresher
inView?: boolean inView?: boolean
templates?: Template[] templates?: Template[]
editQueryStatus?: () => void editQueryStatus?: () => void
@ -67,7 +67,7 @@ class TimeSeries extends Component<Props, State> {
public static defaultProps = { public static defaultProps = {
inView: true, inView: true,
templates: [], templates: [],
autoRefresh: GlobalAutoRefresh, autoRefresher: GlobalAutoRefresher,
} }
public static getDerivedStateFromProps(props: Props, state: State) { public static getDerivedStateFromProps(props: Props, state: State) {
@ -119,24 +119,24 @@ class TimeSeries extends Component<Props, State> {
} }
public async componentDidMount() { public async componentDidMount() {
const {autoRefresh} = this.props const {autoRefresher} = this.props
this.isComponentMounted = true this.isComponentMounted = true
this.executeQueries() this.executeQueries()
autoRefresh.subscribe(this.executeQueries) autoRefresher.subscribe(this.executeQueries)
} }
public componentWillUnmount() { public componentWillUnmount() {
const {autoRefresh} = this.props const {autoRefresher} = this.props
this.isComponentMounted = false this.isComponentMounted = false
autoRefresh.unsubscribe(this.executeQueries) autoRefresher.unsubscribe(this.executeQueries)
} }
public async componentDidUpdate(prevProps: Props) { public async componentDidUpdate(prevProps: Props) {
if (this.props.autoRefresh !== prevProps.autoRefresh) { if (this.props.autoRefresher !== prevProps.autoRefresher) {
prevProps.autoRefresh.unsubscribe(this.executeQueries) prevProps.autoRefresher.unsubscribe(this.executeQueries)
this.props.autoRefresh.subscribe(this.executeQueries) this.props.autoRefresher.subscribe(this.executeQueries)
} }
if (!this.isPropsDifferent(prevProps)) { if (!this.isPropsDifferent(prevProps)) {

View File

@ -1,6 +1,6 @@
type func = (...args: any[]) => any type func = (...args: any[]) => any
export class AutoRefresh { export class AutoRefresher {
public subscribers: func[] = [] public subscribers: func[] = []
private intervalID: NodeJS.Timer private intervalID: NodeJS.Timer
@ -39,7 +39,7 @@ export class AutoRefresh {
} }
} }
// A global singleton, intended to be configured (via `AutoRefresh#poll`) at a // A global singleton, intended to be configured (via `AutoRefresher#poll`) at
// page level and consumed arbitrarily deep within the page's render tree // a page level and consumed arbitrarily deep within the page's render tree
// (usually in a `TimeSeries` component) // (usually in a `TimeSeries` component)
export const GlobalAutoRefresh = new AutoRefresh() export const GlobalAutoRefresher = new AutoRefresher()