Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React from 'react';
- import NodeStore from '../stores/NodeStore';
- import SectionStore from '../stores/SectionStore';
- import TimeoutStore from '../stores/TimeoutStore';
- let TIMEOUT_NODE = 'node';
- let TIMEOUT_DATE = 'date';
- export default class Time extends React.Component {
- constructor(props) {
- super(props);
- this.onList = this.onList.bind(this);
- this.onListDate = this.onListDate.bind(this);
- }
- componentDidMount() {
- SectionStore.addLoadNodesListListener(this.onList);
- NodeStore.addListListener(this.onList);
- NodeStore.addDateTimeListener(this.onListDate);
- }
- componentWillUnmount() {
- SectionStore.removeLoadNodesListListener(this.onList);
- NodeStore.removeListListener(this.onList);
- NodeStore.removeDateTimeListener(this.onListDate);
- TimeoutStore.remove(TIMEOUT_NODE);
- TimeoutStore.remove(TIMEOUT_DATE);
- }
- onList() {
- let component = this;
- TimeoutStore.remove(TIMEOUT_NODE);
- TimeoutStore.append(TIMEOUT_NODE, 1000, new DateTime(NodeStore.current().props.datetime), () => {
- component.forceUpdate(() => {
- TimeoutStore.getData(TIMEOUT_NODE).tick();
- });
- });
- }
- onListDate() {
- TimeoutStore.remove(TIMEOUT_DATE);
- TimeoutStore.append(TIMEOUT_DATE, 5000, null, () => {
- NodeStore.datetime();
- });
- }
- render() {
- let date = TimeoutStore.getData(TIMEOUT_NODE);
- return (
- <div className="time">{date !== null && date.toString()}</div>
- );
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement