MassMarks.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import React, { Component, PureComponent } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { createMassMarks, updateMassMarks } from './api';
  4. var __com__ = 'MassMarks';
  5. //const debug = console.log;
  6. var debug = function debug() {};
  7. export var MassMarks = function (_Component) {
  8. babelHelpers.inherits(MassMarks, _Component);
  9. function MassMarks() {
  10. babelHelpers.classCallCheck(this, MassMarks);
  11. var _this = babelHelpers.possibleConstructorReturn(this, (MassMarks.__proto__ || Object.getPrototypeOf(MassMarks)).call(this));
  12. _this.refElement = null;
  13. _this._entity = null;
  14. debug(__com__, 'constructor', _this._entity);
  15. return _this;
  16. }
  17. babelHelpers.createClass(MassMarks, [{
  18. key: 'componentWillMount',
  19. value: function componentWillMount() {
  20. debug(__com__, 'componentWillMount', this.props.children, this._entity);
  21. }
  22. }, {
  23. key: 'componentDidMount',
  24. value: function componentDidMount() {
  25. debug(__com__, 'componentDidMount', this.props.children, this._entity);
  26. var _props = this.props,
  27. AMap = _props.AMap,
  28. __map__ = _props.__map__,
  29. options = _props.options,
  30. events = _props.events,
  31. children = _props.children;
  32. //let opts = { ...(options || {}), map: __map__, content: children };
  33. var opts = babelHelpers.extends({}, options || {}, { map: __map__ });
  34. this._entity = createMassMarks(AMap, opts, events);
  35. }
  36. }, {
  37. key: 'componentWillReceiveProps',
  38. value: function componentWillReceiveProps(nextProps) {
  39. debug(__com__, 'componentWillReceiveProps', this.props.children, this._entity);
  40. }
  41. }, {
  42. key: 'componentWillUpdate',
  43. value: function componentWillUpdate() {
  44. debug(__com__, 'componentWillUpdate', this.props.children, this._entity);
  45. }
  46. }, {
  47. key: 'componentDidUpdate',
  48. value: function componentDidUpdate(prevProps) {
  49. debug(__com__, 'componentDidUpdate', this.props.children, this._entity);
  50. var _props2 = this.props,
  51. AMap = _props2.AMap,
  52. __map__ = _props2.__map__,
  53. options = _props2.options,
  54. events = _props2.events,
  55. children = _props2.children;
  56. //let opts = { ...(options || {}), map: __map__, content: children };
  57. var opts = babelHelpers.extends({}, options || {}, { map: __map__ });
  58. if (!this._entity) {
  59. this._entity = createMassMarks(AMap, opts, events);
  60. return;
  61. }
  62. // need check props changes, then update.
  63. var oldOpts = babelHelpers.extends({}, prevProps.options || {}, {
  64. map: prevProps.__map__
  65. });
  66. updateMassMarks(this._entity, opts, events, oldOpts, prevProps.events);
  67. }
  68. }, {
  69. key: 'componentWillUnmount',
  70. value: function componentWillUnmount() {
  71. debug(__com__, 'componentWillUnmount', this.props.children, this._entity);
  72. if (this._entity) {
  73. // this._entity.clearMap();
  74. this._entity.setMap(null);
  75. delete this._entity;
  76. // delete this._entity;
  77. this._entity = null;
  78. }
  79. }
  80. // shouldComponentUpdate(nextProps, nextState) {
  81. // debug(__com__, 'shouldComponentUpdate', this._entity);
  82. // return false;
  83. // }
  84. }, {
  85. key: 'render',
  86. value: function render() {
  87. debug(__com__, 'render', this.props.children, this._entity);
  88. var _props3 = this.props,
  89. AMap = _props3.AMap,
  90. options = _props3.options,
  91. events = _props3.events,
  92. match = _props3.match,
  93. location = _props3.location,
  94. history = _props3.history,
  95. staticContext = _props3.staticContext,
  96. rest = babelHelpers.objectWithoutProperties(_props3, ['AMap', 'options', 'events', 'match', 'location', 'history', 'staticContext']);
  97. return null;
  98. // return (
  99. // <React.Fragment>
  100. // </React.Fragment>
  101. // )
  102. }
  103. }]);
  104. return MassMarks;
  105. }(Component);
  106. MassMarks.propTypes = {
  107. AMap: PropTypes.object,
  108. __map__: PropTypes.object,
  109. options: PropTypes.object,
  110. events: PropTypes.object
  111. };
  112. export default MassMarks;