var TimeAgo = React.createClass({

  componentWillMount: function() {
    this.intervals = [];
  },

  setInterval: function() {
    this.intervals.push(setInterval.apply(null, arguments));
  },

  componentWillUnmount: function() {
    this.intervals.map(clearInterval);
  },

  render: function () {
    return (
      <small className="time-ago">{this.state.time}</small>
    );
  },

  componentDidMount: function () {
    this.setInterval(this.updateTime, 1000);
  },

  getInitialState: function () {
    return { time: moment(this.props.children).fromNow() };
  },

  updateTime: function () {
    this.setState({ time: moment(this.props.children).fromNow() });
  },

});