ghost-portal/packages/react-api/src/util/intervalObservable.ts
Jaco 8a898c6b6d
Bump deps (#5789)
* Bump deps

* Updates

* Rewrite translation keys

* Lint fixes
2021-07-08 06:24:01 +02:00

22 lines
640 B
TypeScript

// Copyright 2017-2021 @polkadot/react-api authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { CallState } from '../types';
import { interval, Subscription } from 'rxjs';
const interval$ = interval(500);
export default function intervalObservable<Props, State extends CallState> (that: React.Component<Props, State>): Subscription {
return interval$.subscribe((): void => {
const elapsed = Date.now() - ((that.state.callUpdatedAt as number) || 0);
const callUpdated = elapsed <= 1500;
if (callUpdated !== that.state.callUpdated) {
that.setState({
callUpdated
});
}
});
}