MassMarks.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 { createMassMarks, updateMassMarks } from './api';
  9. var __com__ = 'MassMarks';
  10. //const debug = console.log;
  11. var debug = function debug() {};
  12. export var MassMarks = function (_Component) {
  13. _inherits(MassMarks, _Component);
  14. function MassMarks() {
  15. _classCallCheck(this, MassMarks);
  16. var _this = _possibleConstructorReturn(this, (MassMarks.__proto__ || Object.getPrototypeOf(MassMarks)).call(this));
  17. _this.refElement = null;
  18. _this._entity = null;
  19. debug(__com__, 'constructor', _this._entity);
  20. return _this;
  21. }
  22. _createClass(MassMarks, [{
  23. key: 'componentWillMount',
  24. value: function componentWillMount() {
  25. debug(__com__, 'componentWillMount', this.props, this._entity);
  26. }
  27. }, {
  28. key: 'componentDidMount',
  29. value: function componentDidMount() {
  30. debug(__com__, 'componentDidMount', this.props, this._entity);
  31. var _props = this.props,
  32. __map__ = _props.__map__,
  33. options = _props.options,
  34. events = _props.events,
  35. children = _props.children;
  36. //let opts = { ...(options || {}), map: __map__, content: children };
  37. var opts = _extends({}, options || {}, { map: __map__ });
  38. this._entity = createMassMarks(opts, events);
  39. if (this._entity) {
  40. if (this.props.refer) this.props.refer(this._entity);
  41. }
  42. }
  43. }, {
  44. key: 'componentWillReceiveProps',
  45. value: function componentWillReceiveProps(nextProps) {
  46. debug(__com__, 'componentWillReceiveProps', this.props, this._entity);
  47. }
  48. }, {
  49. key: 'componentWillUpdate',
  50. value: function componentWillUpdate() {
  51. debug(__com__, 'componentWillUpdate', this.props, this._entity);
  52. }
  53. }, {
  54. key: 'componentDidUpdate',
  55. value: function componentDidUpdate(prevProps) {
  56. debug(__com__, 'componentDidUpdate', this.props, this._entity);
  57. var _props2 = this.props,
  58. __map__ = _props2.__map__,
  59. options = _props2.options,
  60. events = _props2.events;
  61. var opts = _extends({}, options || {}, { map: __map__ });
  62. if (!this._entity) {
  63. debug(__com__, 'componentDidUpdate', opts, events);
  64. this._entity = createMassMarks(opts, events);
  65. if (this._entity) {
  66. if (this.props.refer) this.props.refer(this._entity);
  67. }
  68. return;
  69. }
  70. // need check props changes, then update.
  71. var oldOpts = _extends({}, prevProps.options || {}, {
  72. map: prevProps.__map__
  73. });
  74. updateMassMarks(this._entity, opts, events, oldOpts, prevProps.events);
  75. }
  76. }, {
  77. key: 'componentWillUnmount',
  78. value: function componentWillUnmount() {
  79. debug(__com__, 'componentWillUnmount', this.props, this._entity);
  80. if (this._entity) {
  81. this._entity.setMap(null);
  82. // delete this._entity;
  83. this._entity = null;
  84. if (this.props.refer) this.props.refer(this._entity);
  85. }
  86. }
  87. // shouldComponentUpdate(nextProps, nextState) {
  88. // debug(__com__, 'shouldComponentUpdate', this._entity);
  89. // return false;
  90. // }
  91. }, {
  92. key: 'render',
  93. value: function render() {
  94. debug(__com__, 'render', this._entity);
  95. return null;
  96. }
  97. }]);
  98. return MassMarks;
  99. }(Component);
  100. MassMarks.propTypes = {
  101. __map__: PropTypes.object,
  102. options: PropTypes.object,
  103. events: PropTypes.object
  104. };
  105. export default MassMarks;