calculateViewBox.js 613 B

123456789101112131415161718
  1. import memoize from 'lodash/memoize';
  2. /**
  3. * This is memoized because the viewBox is unlikely to change often
  4. * - but because it is computed from offset, any change to it would re-render all children.
  5. *
  6. * And because we have many readers of the viewBox, and update it only rarely,
  7. * then let's optimize with memoization.
  8. */
  9. export var calculateViewBox = memoize(function (offset) {
  10. return {
  11. x: offset.left,
  12. y: offset.top,
  13. width: offset.width,
  14. height: offset.height
  15. };
  16. }, function (offset) {
  17. return ['l', offset.left, 't', offset.top, 'w', offset.width, 'h', offset.height].join('');
  18. });