Skip to content

Instantly share code, notes, and snippets.

@xenji
Created August 2, 2013 15:11
Show Gist options
  • Save xenji/6140638 to your computer and use it in GitHub Desktop.
Save xenji/6140638 to your computer and use it in GitHub Desktop.
This is an AjaxSpinner component, written for the React framework using EventEmitter2
/** @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