UNPKG

react-loadermixin

Version:

A React mixin for giving components loading behavior

42 lines (37 loc) 1.26 kB
var PropTypes, React, ReactLoaderMixin, merge, __slice = [].slice; React = require('react'); merge = require('xtend'); PropTypes = React.PropTypes; module.exports = ReactLoaderMixin = { propTypes: { src: PropTypes.string, onLoad: PropTypes.func, onError: PropTypes.func }, renderLoader: function(loader, props) { return loader(merge(props, { src: this.props.src, onLoad: (function(_this) { return function() { var args, _base; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; if (typeof _this.loaderDidLoad === "function") { _this.loaderDidLoad.apply(_this, args); } return typeof (_base = _this.props).onLoad === "function" ? _base.onLoad.apply(_base, args) : void 0; }; })(this), onError: (function(_this) { return function() { var args, _base; args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; if (typeof _this.loaderDidError === "function") { _this.loaderDidError.apply(_this, args); } return typeof (_base = _this.props).onError === "function" ? _base.onError.apply(_base, args) : void 0; }; })(this) })); } };