-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from daymosik/rewrite-to-fc
rewrite to FC
- Loading branch information
Showing
5 changed files
with
5,262 additions
and
3,706 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,33 @@ | ||
import * as React from 'react' | ||
import { StatusAlertContainer } from './status-alert-container' | ||
import { Alert } from './status-alert-item' | ||
import statusAlertStore, { Unsubscriber } from './status-alert-store' | ||
import statusAlertStore from './status-alert-store' | ||
|
||
export interface StatusAlertState { | ||
alerts: Alert[] | ||
} | ||
export const StatusAlertView: React.FC = () => { | ||
const [alerts, setAlerts] = React.useState<Alert[]>([]) | ||
|
||
export class StatusAlertView extends React.Component<unknown, StatusAlertState> { | ||
private unsubscribeStore: Unsubscriber | ||
private frameId = 0 | ||
private frameId2 = 0 | ||
let frameId = 0 | ||
let frameId2 = 0 | ||
|
||
public constructor(props: unknown) { | ||
super(props) | ||
const updateState = () => { | ||
frameId = requestAnimationFrame(() => { | ||
frameId2 = requestAnimationFrame(() => { | ||
const state = statusAlertStore.getState() | ||
setAlerts(state) | ||
}) | ||
}) | ||
} | ||
|
||
this.state = { | ||
alerts: [], | ||
} | ||
React.useEffect(() => { | ||
const unsubscribeStore = statusAlertStore.subscribe(updateState) | ||
|
||
this.unsubscribeStore = statusAlertStore.subscribe(this.updateState) | ||
} | ||
return () => { | ||
unsubscribeStore() | ||
|
||
public componentWillUnmount(): void { | ||
if (this.unsubscribeStore) { | ||
this.unsubscribeStore() | ||
window.cancelAnimationFrame(frameId) | ||
window.cancelAnimationFrame(frameId2) | ||
} | ||
window.cancelAnimationFrame(this.frameId) | ||
window.cancelAnimationFrame(this.frameId2) | ||
} | ||
|
||
public render() { | ||
return <StatusAlertContainer alerts={this.state.alerts} /> | ||
} | ||
}) | ||
|
||
public updateState = () => { | ||
this.frameId = requestAnimationFrame(() => { | ||
this.frameId2 = requestAnimationFrame(() => { | ||
const state = statusAlertStore.getState() | ||
this.setState({ alerts: state }) | ||
}) | ||
}) | ||
} | ||
return <StatusAlertContainer alerts={alerts} /> | ||
} |
Oops, something went wrong.