1 | var _class, _temp2;
|
2 |
|
3 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
4 |
|
5 | function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
|
6 |
|
7 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
|
8 |
|
9 | import React, { PropTypes } from 'react';
|
10 | import SVGInline from 'react-svg-inline';
|
11 | import 'whatwg-fetch';
|
12 |
|
13 | var MalibuSprites = (_temp2 = _class = function (_React$Component) {
|
14 | _inherits(MalibuSprites, _React$Component);
|
15 |
|
16 | function MalibuSprites() {
|
17 | var _temp, _this, _ret;
|
18 |
|
19 | _classCallCheck(this, MalibuSprites);
|
20 |
|
21 | for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
|
22 | args[_key] = arguments[_key];
|
23 | }
|
24 |
|
25 | return _ret = (_temp = (_this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))), _this), _this.state = {
|
26 | fetchTries: 0,
|
27 | sprites: ''
|
28 | }, _this.fetchSprites = function () {
|
29 | var version = _this.props.version;
|
30 |
|
31 | fetch('https://www.herokucdn.com/malibu/' + version + '/sprite.svg').then(function (res) {
|
32 | return res.text();
|
33 | }).then(function (sprites) {
|
34 | _this.setState({
|
35 | fetchTries: 0,
|
36 | sprites: sprites
|
37 | });
|
38 | }).catch(function (err) {
|
39 |
|
40 | var fetchTries = _this.state.fetchTries;
|
41 |
|
42 | fetchTries += 1;
|
43 | _this.setState({ fetchTries: fetchTries });
|
44 | var fetchDelaySeconds = Math.pow(2, fetchTries);
|
45 | console.warn('Error when fetching Malibu sprites, retrying in ' + Math.pow(2, fetchTries), err);
|
46 | setTimeout(_this.fetchSprites, Math.pow(fetchDelaySeconds, 1000));
|
47 | });
|
48 | }, _temp), _possibleConstructorReturn(_this, _ret);
|
49 | }
|
50 |
|
51 | MalibuSprites.prototype.componentDidMount = function componentDidMount() {
|
52 | this.fetchSprites();
|
53 | };
|
54 |
|
55 | MalibuSprites.prototype.render = function render() {
|
56 | var sprites = this.state.sprites;
|
57 |
|
58 | return React.createElement(SVGInline, { svg: sprites });
|
59 | };
|
60 |
|
61 | return MalibuSprites;
|
62 | }(React.Component), _class.defaultProps = {
|
63 | version: 'latest'
|
64 | }, _temp2);
|
65 | export { MalibuSprites as default };
|
66 | process.env.NODE_ENV !== "production" ? MalibuSprites.propTypes = {
|
67 | version: PropTypes.string.isRequired
|
68 | } : void 0; |
\ | No newline at end of file |