-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: move from objects to Maps #5468
Conversation
✅ Deploy Preview for mermaid-js ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #5468 +/- ##
==========================================
- Coverage 5.74% 5.73% -0.01%
==========================================
Files 277 278 +1
Lines 41967 41991 +24
Branches 515 490 -25
==========================================
Hits 2409 2409
- Misses 39558 39582 +24
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yash-Singh1 were you able to fix the tests? |
Hi @sidharthv96, sorry for the late reply, I was busy with exams. I just fixed the e2e tests. |
No worries @Yash-Singh1! Hope they went well :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the great work!
I have a few comments. Is there a reason for some tests to be different? Like, some of them use it.each
and some don't?
And I just would like the PR description to have the "why". Like listing the possible limitations of objects or downsides.
Remove the non-null assertion operator when possible from PR #5468
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work @Yash-Singh1!!!
This is something I've wanted to do for a while too, so it's awesome to see you've done it (I can imagine that all the .js
files must have been really painful without TypeScript).
I've got some minor nitpicks about not using the !
non-null assertion in TypeScript, but I've made a separate PR: #5518 for fixing this. You're welcome to merge it into your branch, or maybe we can merge this PR first, and then the other refactoring PR can also land.
Merging this now, as both the review comments are non blockers, and can be done in a follow up PR. |
…ipt-non-null-assertion-when-possible
@Yash-Singh1, Thank you for the contribution! |
📑 Summary
Switches from objects to
Map
s in places where the keys accepted are user inputs.Resolves #5451
📏 Design Decisions
Describe the way your implementation works or what design decisions you made if applicable.
This is a breaking change for v11 since it changes the structure of the databases and as such can break code that relies on the db, e.g.
https://github.com/excalidraw/mermaid-to-excalidraw/blob/d0b00dc63eeabd5e92ca3997650f47bf4901cb2c/src/parser/flowchart.ts#L226
Why?
The main reason for this change was so that we wouldn't have to validate for
constructor
and__proto__
(#5451) everytime we have to modify or get a property on the database objects. Another good reason would be that objects in JavaScript are generally designed to work like dynamic structs, where the JIT compiler would store the shape of the object and rereference that shape everytime that object is passed around. However, when we have a "map" with user-generated keys,Map
s work better because they are designed for that purpose.📋 Tasks
Make sure you
MERMAID_RELEASE_VERSION
is used for all new features.develop
branch