Component.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. var util = require('../../util');
  2. /**
  3. * Prototype for visual components
  4. * @param {{dom: Object, domProps: Object, emitter: Emitter, range: Range}} [body]
  5. * @param {Object} [options]
  6. */
  7. function Component (body, options) { // eslint-disable-line no-unused-vars
  8. this.options = null;
  9. this.props = null;
  10. }
  11. /**
  12. * Set options for the component. The new options will be merged into the
  13. * current options.
  14. * @param {Object} options
  15. */
  16. Component.prototype.setOptions = function(options) {
  17. if (options) {
  18. util.extend(this.options, options);
  19. }
  20. };
  21. /**
  22. * Repaint the component
  23. * @return {boolean} Returns true if the component is resized
  24. */
  25. Component.prototype.redraw = function() {
  26. // should be implemented by the component
  27. return false;
  28. };
  29. /**
  30. * Destroy the component. Cleanup DOM and event listeners
  31. */
  32. Component.prototype.destroy = function() {
  33. // should be implemented by the component
  34. };
  35. /**
  36. * Test whether the component is resized since the last time _isResized() was
  37. * called.
  38. * @return {Boolean} Returns true if the component is resized
  39. * @protected
  40. */
  41. Component.prototype._isResized = function() {
  42. var resized = (this.props._previousWidth !== this.props.width ||
  43. this.props._previousHeight !== this.props.height);
  44. this.props._previousWidth = this.props.width;
  45. this.props._previousHeight = this.props.height;
  46. return resized;
  47. };
  48. module.exports = Component;