Skip to content

refactor: alignment to use string literals instead of magic numbers#42

Open
dreyfus92 wants to merge 5 commits into
mainfrom
refactor-alignment
Open

refactor: alignment to use string literals instead of magic numbers#42
dreyfus92 wants to merge 5 commits into
mainfrom
refactor-alignment

Conversation

@dreyfus92

Copy link
Copy Markdown
Member

closes: #3

@pkg-pr-new

pkg-pr-new Bot commented May 24, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/clayterm@42

commit: 7025bdc

Comment thread ops.ts
o += 4;

view.setUint32(o, (l.alignX ?? 0) | ((l.alignY ?? 0) << 8), true);
let alignX = l.alignX === "right" ? 1 : l.alignX === "center" ? 2 : 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

hmm, think we might benefit from a more generalized approach to string > enum conversion? like a typed resolveInt(property, value) util?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agree. We might even be able to use typescript enums? If so, it would be the first legitimate use-case I've encountered ever (although probably not).

In fairness, there is some of this one-off ternary stuff already in the codebase with "ttb", "ltr", etc.. so not sure it should be a blocker https://github.com/bombshell-dev/clayterm/blob/refactor-alignment/ops.ts#L113

Perhaps we should come up with a const handling strategy and do it all in one go?

@natemoo-re natemoo-re left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Love this from a DX perspective! Think we'll need to discuss how far we want to take the idea of papering over clay's lower-level layout concepts for a flexbox-friendly audience.

@cowboyd cowboyd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@dreyfus92 Nice one! Thanks.

One thing to note: specs/renderer-spec.md needs to be updated.

§12.2 referecences this transition and should now be updated to reflect that it's done. Two spots:

Lines 604–606 — the parenthetical still says alignment is numeric:

Lines 620–622 — drop the trailing sentence about the planned transition:

Happy to do this if you allow maintainers access to the fork :)

Comment thread ops.ts
o += 4;

view.setUint32(o, (l.alignX ?? 0) | ((l.alignY ?? 0) << 8), true);
let alignX = l.alignX === "right" ? 1 : l.alignX === "center" ? 2 : 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Agree. We might even be able to use typescript enums? If so, it would be the first legitimate use-case I've encountered ever (although probably not).

In fairness, there is some of this one-off ternary stuff already in the codebase with "ttb", "ltr", etc.. so not sure it should be a blocker https://github.com/bombshell-dev/clayterm/blob/refactor-alignment/ops.ts#L113

Perhaps we should come up with a const handling strategy and do it all in one go?

@dreyfus92 dreyfus92 force-pushed the refactor-alignment branch from 1571dde to fbb9762 Compare May 29, 2026 01:10
@codspeed-hq

codspeed-hq Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 54.46%

❌ 1 regressed benchmark
✅ 22 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation long input burst (200 bytes) 576.2 µs 1,265.1 µs -54.46%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing refactor-alignment (7025bdc) with main (0c13b1e)

Open in CodSpeed

@dreyfus92 dreyfus92 requested a review from cowboyd May 29, 2026 01:21

@cowboyd cowboyd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍🏻 looks good, thank you!

@cowboyd

cowboyd commented May 30, 2026

Copy link
Copy Markdown
Collaborator

@dreyfus92 looks like the only thing missing is signed commits

@dreyfus92 dreyfus92 force-pushed the refactor-alignment branch from 8157616 to 764dd5a Compare June 8, 2026 19:03
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Size Increased — +0.3 KB

107.8 KB unpacked

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.

Use string literals for alignX/alignY instead of magic numbers

3 participants