Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utils - memoize, calculateTextDimensions (and friends), assignWithDepth, etc #1519

Merged
merged 2 commits into from Jul 2, 2020

Conversation

cmmoran
Copy link
Collaborator

@cmmoran cmmoran commented Jul 1, 2020

馃搼 Summary

Added a few QoL functions to utils. No new modules introduced.

  • memoize: simple caching for computationally intensive functions. This comes in handy for things like calculating text dimensions (especially the way we do it with drawing to an svg canvas and then removing the element - this gets quite expensive quite quickly)
  • assignWithDepth - this is essentially a franken-merge of what we were doing with config.js and Object.assign. The goal / purpose of this function is to provide a sane mechanism for merging arbitrarily deep objects
  • calculateTextDimensions, calculateTextWidth, calculateTextHeight - for measuring text
  • random - similar to generateId except it generates random values based on the crypto-random-string package (already added to this project)

馃搹 Design Decisions

Added a fair number of unit tests to utils.spec.js.

- memoize to poor-man-cache properly-ish
- wrapLabel, calculateTextDimensions (and friends) moved to utils for all to enjoy
- drawSimpleText getTextObj moved to utils to support the functions listed above
- assignWithDepth - Object.assign but depth-ier
- random - for crypto random numbers
@knsv knsv merged commit 33d3bc5 into mermaid-js:develop Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants