Meriadec Pillet
7 years ago
committed by
GitHub
20 changed files with 423 additions and 337 deletions
@ -0,0 +1,21 @@ |
|||
// @flow
|
|||
|
|||
import React, { Component } from 'react' |
|||
import CounterValues from 'helpers/countervalues' |
|||
|
|||
class Effect extends Component<{ cvPolling: * }> { |
|||
componentDidMount() { |
|||
this.props.cvPolling.poll() |
|||
} |
|||
render() { |
|||
return null |
|||
} |
|||
} |
|||
|
|||
const PollCounterValuesOnMount = () => ( |
|||
<CounterValues.PollingConsumer> |
|||
{cvPolling => <Effect cvPolling={cvPolling} />} |
|||
</CounterValues.PollingConsumer> |
|||
) |
|||
|
|||
export default PollCounterValuesOnMount |
@ -0,0 +1,39 @@ |
|||
// @flow
|
|||
|
|||
import React, { Component } from 'react' |
|||
import { BridgeSyncConsumer } from 'bridge/BridgeSyncContext' |
|||
import type { Sync } from 'bridge/BridgeSyncContext' |
|||
|
|||
export class Effect extends Component<{ |
|||
sync: Sync, |
|||
accountId: string, |
|||
priority: number, |
|||
}> { |
|||
componentDidMount() { |
|||
const { sync, accountId, priority } = this.props |
|||
sync({ type: 'SYNC_ONE_ACCOUNT', accountId, priority }) |
|||
} |
|||
componentDidUpdate(prevProps: *) { |
|||
const { sync, accountId, priority } = this.props |
|||
if (accountId !== prevProps.accountId) { |
|||
sync({ type: 'SYNC_ONE_ACCOUNT', accountId, priority }) |
|||
} |
|||
} |
|||
render() { |
|||
return null |
|||
} |
|||
} |
|||
|
|||
const SyncOneAccountOnMount = ({ |
|||
accountId, |
|||
priority, |
|||
}: { |
|||
accountId: string, |
|||
priority: number, |
|||
}) => ( |
|||
<BridgeSyncConsumer> |
|||
{sync => <Effect sync={sync} accountId={accountId} priority={priority} />} |
|||
</BridgeSyncConsumer> |
|||
) |
|||
|
|||
export default SyncOneAccountOnMount |
@ -0,0 +1,41 @@ |
|||
// @flow
|
|||
|
|||
import React, { PureComponent } from 'react' |
|||
import { BridgeSyncConsumer } from 'bridge/BridgeSyncContext' |
|||
import type { Sync } from 'bridge/BridgeSyncContext' |
|||
|
|||
const instances = [] |
|||
|
|||
export class Effect extends PureComponent<{ |
|||
sync: Sync, |
|||
priority: number, // eslint-disable-line
|
|||
}> { |
|||
componentDidMount() { |
|||
instances.push(this) |
|||
this.check() |
|||
} |
|||
componentDidUpdate() { |
|||
this.check() |
|||
} |
|||
componentWillUnmount() { |
|||
const i = instances.indexOf(this) |
|||
if (i !== -1) { |
|||
instances.splice(i, 1) |
|||
this.check() |
|||
} |
|||
} |
|||
check() { |
|||
const { sync } = this.props |
|||
const priority = instances.length === 0 ? -1 : Math.max(...instances.map(i => i.props.priority)) |
|||
sync({ type: 'SET_SKIP_UNDER_PRIORITY', priority }) |
|||
} |
|||
render() { |
|||
return null |
|||
} |
|||
} |
|||
|
|||
const SyncSkipUnderPriority = ({ priority }: { priority: number }) => ( |
|||
<BridgeSyncConsumer>{sync => <Effect sync={sync} priority={priority} />}</BridgeSyncConsumer> |
|||
) |
|||
|
|||
export default SyncSkipUnderPriority |
Loading…
Reference in new issue