Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React from 'react';
  2.  
  3. import NodeStore from '../stores/NodeStore';
  4. import SectionStore from '../stores/SectionStore';
  5. import TimeoutStore from '../stores/TimeoutStore';
  6.  
  7. let TIMEOUT_NODE = 'node';
  8. let TIMEOUT_DATE = 'date';
  9.  
  10. export default class Time extends React.Component {
  11.     constructor(props) {
  12.         super(props);
  13.  
  14.         this.onList = this.onList.bind(this);
  15.         this.onListDate = this.onListDate.bind(this);
  16.     }
  17.  
  18.     componentDidMount() {
  19.         SectionStore.addLoadNodesListListener(this.onList);
  20.         NodeStore.addListListener(this.onList);
  21.         NodeStore.addDateTimeListener(this.onListDate);
  22.     }
  23.  
  24.     componentWillUnmount() {
  25.         SectionStore.removeLoadNodesListListener(this.onList);
  26.         NodeStore.removeListListener(this.onList);
  27.         NodeStore.removeDateTimeListener(this.onListDate);
  28.         TimeoutStore.remove(TIMEOUT_NODE);
  29.         TimeoutStore.remove(TIMEOUT_DATE);
  30.     }
  31.  
  32.     onList() {
  33.         let component = this;
  34.         TimeoutStore.remove(TIMEOUT_NODE);
  35.         TimeoutStore.append(TIMEOUT_NODE, 1000, new DateTime(NodeStore.current().props.datetime), () => {
  36.             component.forceUpdate(() => {
  37.                 TimeoutStore.getData(TIMEOUT_NODE).tick();
  38.                
  39.             });
  40.         });
  41.     }
  42.  
  43.     onListDate() {
  44.         TimeoutStore.remove(TIMEOUT_DATE);
  45.         TimeoutStore.append(TIMEOUT_DATE, 5000, null, () => {
  46.             NodeStore.datetime();
  47.         });
  48.     }
  49.  
  50.     render() {
  51.         let date = TimeoutStore.getData(TIMEOUT_NODE);
  52.  
  53.         return (
  54.             <div className="time">{date !== null && date.toString()}</div>
  55.         );
  56.     }
  57. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement