Circle.js 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  2. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  3. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  4. 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; }
  5. 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; }
  6. import React, { Component, PureComponent } from 'react';
  7. import PropTypes from 'prop-types';
  8. import { createCircle, updateCircle } from './api';
  9. var __com__ = 'Circle';
  10. //const debug = console.log;
  11. var debug = function debug() {};
  12. export var Circle = function (_Component) {
  13. _inherits(Circle, _Component);
  14. function Circle() {
  15. _classCallCheck(this, Circle);
  16. var _this = _possibleConstructorReturn(this, (Circle.__proto__ || Object.getPrototypeOf(Circle)).call(this));
  17. _this.refElement = null;
  18. _this._entity = null;
  19. return _this;
  20. }
  21. _createClass(Circle, [{
  22. key: 'componentDidMount',
  23. value: function componentDidMount() {
  24. var _props = this.props,
  25. __map__ = _props.__map__,
  26. options = _props.options,
  27. events = _props.events,
  28. children = _props.children;
  29. var opts = _extends({}, options || {}, { map: __map__ });
  30. this._entity = createCircle(opts, events);
  31. if (this._entity) {
  32. if (this.props.refer) this.props.refer(this._entity);
  33. }
  34. }
  35. }, {
  36. key: 'componentDidUpdate',
  37. value: function componentDidUpdate(prevProps) {
  38. var _props2 = this.props,
  39. __map__ = _props2.__map__,
  40. options = _props2.options,
  41. events = _props2.events,
  42. children = _props2.children;
  43. var opts = _extends({}, options || {}, { map: __map__ });
  44. if (!this._entity) {
  45. this._entity = createCircle(opts, events);
  46. if (this._entity) {
  47. if (this.props.refer) this.props.refer(this._entity);
  48. }
  49. return;
  50. }
  51. // need check props changes, then update.
  52. var oldOpts = _extends({}, prevProps.options || {}, {
  53. map: prevProps.__map__
  54. });
  55. updateCircle(this._entity, opts, events, oldOpts, prevProps.events);
  56. }
  57. }, {
  58. key: 'componentWillUnmount',
  59. value: function componentWillUnmount() {
  60. if (this._entity) {
  61. this._entity.setMap(null);
  62. this._entity = null;
  63. if (this.props.refer) this.props.refer(this._entity);
  64. }
  65. }
  66. }, {
  67. key: 'render',
  68. value: function render() {
  69. return null;
  70. }
  71. }]);
  72. return Circle;
  73. }(Component);
  74. Circle.propTypes = {
  75. __map__: PropTypes.object,
  76. options: PropTypes.object,
  77. events: PropTypes.object
  78. };
  79. export default Circle;