Skip to content

Conversation

@sq86-qazi
Copy link
Contributor

No description provided.

@sq86-qazi sq86-qazi marked this pull request as draft October 20, 2025 16:02
@sq86-qazi sq86-qazi requested a review from sampsyo October 20, 2025 16:02
Copy link
Contributor

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are a few suggestions! The main thing here is that the JavaScript code could really use some more comments—some of the uncommented functions are hard to follow without more context.

}
}

const bitfieldJSON = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this part could use some comments. What exactly is bitfieldJSON? What fields are present, and what is it eventually used for?

.eleventy.js Outdated
return String(range);
});

eleventyConfig.addPassthroughCopy({ "node_modules/bit-field": "bitfield" });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we just include the .../build subdirectory instead of the whole directory? Seems like that's all we're actually using (in the <script> tag above).

}
function renderBitfieldScripts() {
const scripts = document.querySelectorAll('script[type="text/bitfield"]');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a tiny bit confused about the overall strategy here. Maybe it just needs more comments? I think what you're doing is finding a way to embed the underlying JSON data in a way that the frontend will then parse? And the <script> tag is a hack for embedding that JSON string?

A little bit of commenting here could go a long way!

Comment on lines 66 to 76
try {
const payload = JSON.parse(raw);
if (Array.isArray(payload)) {
return { segments: payload };
}
if (payload && Array.isArray(payload.reg)) {
return { segments: payload.reg, options: payload.options };
}
if (payload && Array.isArray(payload.fields)) {
return { segments: payload.fields, options: payload.options };
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please explain a bit more about why we need these three cases? I guess I don't understand why we make the underlying raw JSON document have optional fields, like reg and fields, instead of just having it provide segments and options directly… it would be simpler if we could just assume that the JSON we parse always has all the data we need.

Comment on lines 99 to 109
const segments = parsed.segments
.map(seg => {
const bits = Number(seg.bits ?? seg.width ?? 0);
return Object.assign({}, seg, { bits });
})
.filter(seg => seg.bits > 0);
if (!segments.length) return;
const totalBits = segments.reduce((sum, seg) => sum + seg.bits, 0);
const options = Object.assign({ bits: totalBits }, parsed.options || {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly to the above, I don't think I quite follow why this logic is necessary. I get that we eventually need to compute the options to pass to bitfield.render, but it seems a little weird that those options are being built up in multiple locations: here, in parseBitFieldData, and potentially in the thing that generates the JSON. Can we centralize that so that this option computation only appears in one place? That would make it a LOT easier to read/maintain.


<script>
(function () {
function jsonmlToDom(node, inSvg) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I don't understand what this function does or why it's necessary. Can you please add some comments to describe overall what the arguments are and what it is supposed to return?

Here's my best guess so far. bitfield.render produces an SVG-like data structure, and we need to convert this into real SVG elements. It seems like this uses a particular standard-ish format for representing XML in JavaScript called JsonML. So you have hand-written a translator from that JsonML format to DOM elements.

But looking at the JsonML page, it looks like there are plenty of existing tools for converting from it to DOM nodes. And the bit-field README suggests using onml.stringify to get the SVG code, which seems really simple. Can we just do that, and use something like innerHTML to insert this SVG code into the page?

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.

4 participants