Created
August 2, 2013 15:11
-
-
Save xenji/6140638 to your computer and use it in GitHub Desktop.
This is an AjaxSpinner component, written for the React framework using EventEmitter2
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
/** @jsx React.DOM */ | |
define(['react'], function(React){ | |
/** | |
* Ajax Spinner | |
* | |
* Props: | |
* - {object} data | |
* - {String} data.imgSrc | |
* - {int} data.width | |
* - {int} data.height | |
* - {String} data.alt | |
* - {EventEmitter2} eventEmitter | |
* | |
* @type {Function} | |
*/ | |
var AjaxSpinner = React.createClass({ | |
getInitialState: function() { | |
return {style: {display: 'none'}}; | |
}, | |
componentDidMount: function() { | |
var that = this, p = this.props, ee = p.eventEmitter; | |
ee.on(p.startEvent, function(){ | |
that.setState({style: {display:'block'}}); | |
}); | |
ee.on(p.endEvent, function(){ | |
that.setState({style: {display:'none'}}); | |
}); | |
}, | |
render: function() { | |
var style = this.state.style; | |
return ( | |
<img style={style} src={this.props.data.imgSrc} width={this.props.data.width} height={this.props.data.height} alt={this.props.data.alt}/> | |
); | |
} | |
}); | |
return AjaxSpinner; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment