refactor: use WeakMap for block data storage in inspector#166
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors MageForge Inspector’s frontend block-metadata association to use a shared WeakMap (blockDataMap) instead of attaching a custom property on DOM elements, reducing DOM namespace pollution and enabling automatic cleanup when elements are removed.
Changes:
- Added a new
inspector/blockData.jsmodule exporting a sharedWeakMapfor element→block metadata. - Updated picker logic to store block metadata via
blockDataMap.set(element, data)rather thanelement._mageforgeBlockData. - Updated UI/panel rendering to read metadata via
blockDataMap.get(element).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/view/frontend/web/js/inspector/blockData.js | Introduces shared WeakMap storage for block metadata keyed by DOM elements. |
| src/view/frontend/web/js/inspector/picker.js | Stores detected block metadata into blockDataMap for the hovered/selected element. |
| src/view/frontend/web/js/inspector/ui.js | Reads block metadata from blockDataMap when building badge content. |
| src/view/frontend/web/js/inspector.js | Reads block metadata from blockDataMap when updating the panel data. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors how block metadata is associated with DOM elements in the MageForge Inspector. Instead of attaching data directly to elements as a custom property, it now uses a shared
WeakMap(blockDataMap). This approach avoids polluting the DOM element namespace and allows for better memory management.Block metadata storage refactor:
blockDataMap(aWeakMap) ininspector/blockData.jsto store block metadata associated with DOM elements, enabling automatic garbage collection and preventing namespace pollution.blockDataMapinstead of the_mageforgeBlockDataproperty ininspector.js,picker.js, andui.js. [1] [2] [3]blockDataMapfrom the new module. [1] [2] [3]