<commit_before>/** @jsx React.DOM */

var HabitList = React.createClass({
	getInitialState: function() {
		return {items: []};
	},
	componentWillMount: function() {
		reqwest(this.props.endpoint).then(function(d){
			this.setState({items:d})
		}.bind(this));
		// connect to pubnub

		var self = this;

		pubnub.subscribe({
			channel : "do_channel",
			message : function(m){

				this.HabitNodes.forEach(function(node){
					
					if(node.props.id == m.did){
						var current = node.state.count;
						node.setState({
							count:current+1,
							triggered:true
						})

						// untrigger
						setTimeout(function(){
							var current = node.state.count;
							node.setState({
								count:current,
								triggered:false
							})

						}, 1000)
					}
				})
			}.bind(this),
		});

	},
	HabitNodes:[],
	render: function() {

		this.HabitNodes = this.state.items.map(function (data) {
		return <Habit id={data._id} name={data.name} count={data.count}></Habit>;
	});

	return (
		<div>
			{this.HabitNodes}
		</div>
	);
  }
})


var Habit = React.createClass({
	getInitialState: function() {
		return {count: 0};
	},
	componentWillMount: function() {
		reqwest('habits/' + this.props.id)
		.then(this.setState.bind(this));
	},
	render: function(){
		return (
			<form method="post" className={this.state.triggered?'habit-form triggered':'habit-form'}>
				<h2>{this.props.name}</h2>
				<input type="hidden" name="id" value={this.props.id} />
				<input type="submit" value="done" className="habit-action" />
                <span className={'habit-block habit-count'}>
					{this.state.count}
				</span>
                <span className={'habit-block habit-remove'}>
                    &times;
                </span>
			</form>
		);
	}
})

React.renderComponent(
	<HabitList endpoint="/habits" channel="do_channel" />,<commit_msg>lovely codez<commit_after>/** @jsx React.DOM */

var HabitList = React.createClass({
	getInitialState: function() {
		return {items: []};
	},
	componentWillMount: function() {
		reqwest(this.props.endpoint).then(function(d){
			this.setState({items:d})
		}.bind(this));
		// connect to pubnub

		var self = this;

		pubnub.subscribe({
			channel : "do_channel",
			message : function(m){

				this.HabitNodes.forEach(function(node){
					
					if(node.props.id == m.did){
						var current = node.state.count;
						node.setState({
							count:current+1,
							triggered:true
						})

						// untrigger
						setTimeout(function(){
							var current = node.state.count;
							node.setState({
								count:current,
								triggered:false
							})

						}, 1000)
					}
				})
			}.bind(this),
		});

	},
	HabitNodes:[],
	render: function() {

		this.HabitNodes = this.state.items.map(function (data) {
		return <Habit id={data._id} name={data.name} count={data.count}></Habit>;
	});

	return (
		<div>
			{this.HabitNodes}
		</div>
	);
  }
})


var Habit = React.createClass({
	getInitialState: function() {
		return {count: 0};
	},
	componentWillMount: function() {
		reqwest('habits/' + this.props.id)
		.then(this.setState.bind(this));
	},
	handleDelete: function(){
		reqwest({
		    url: 'habits/' + this.props.id
		  , method: 'delete'
		})

		this.setState({
			removed:true
		})

	},
	render: function(){

		var clazz = this.state.removed ? 'removed' :
					this.state.triggered ? 'habit-form triggered' :
					'habit-form' ;


		return (
			<form method="post" className={clazz}>
				<h2>{this.props.name}</h2>
				<input type="hidden" name="id" value={this.props.id} />
				<input type="submit" value="done" className="habit-action" />
                <span className={'habit-block habit-count'}>
					{this.state.count}
				</span>
                <span className={'habit-block habit-remove'} onClick={this.handleDelete.bind(this)}>
                    &times;
                </span>
			</form>
		);
	}
})

React.renderComponent(
	<HabitList endpoint="/habits" channel="do_channel" />,
{'fraction_non_alphanumeric': 0.17505691879585125, 'fraction_numerical': 0.004047558816089046, 'mean_word_length': 2.6987839101964455, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '53064', 'n_tokens_mistral': 1684, 'n_tokens_neox': 1353, 'n_words': 227}