Skip to content

Rename Op discriminant to directive, open() name to id#20

Merged
cowboyd merged 1 commit into
mainfrom
refactor/rename-name-to-id
Apr 17, 2026
Merged

Rename Op discriminant to directive, open() name to id#20
cowboyd merged 1 commit into
mainfrom
refactor/rename-name-to-id

Conversation

@cowboyd
Copy link
Copy Markdown
Contributor

@cowboyd cowboyd commented Apr 17, 2026

Motivation

The open() parameter is called name but it functions as an element identity for Clay's layout engine (Clay_ElementId). Meanwhile, the id field on Op types is a numeric discriminant, creating a naming collision. See #16.

Additionally, the renderer was using an auto-incrementing seed (idx++) when hashing element IDs, making it impossible for callers to look up elements by name after layout — a prerequisite for exposing computed dimensions.

Approach

Op type restructuring:

  • Renamed the numeric discriminant field from id to directive on all Op interfaces (OpenElement, Text, CloseElement)
  • Renamed open()'s name parameter to id, and the OpenElement.name field to OpenElement.id
  • Updated pack(), validate.ts, and all tests to use the new field names

ID hashing:

  • Changed Clay__HashString(str, idx++) to Clay__HashString(str, 0) — element IDs are now hashed with a constant seed
  • Uniqueness is the caller's responsibility; duplicate IDs within a frame are undefined behavior

Spec updates:

  • Removed INV-7 (element identity disambiguation)
  • Updated Sections 8.3.1, 9.3, and 10.3 to reflect caller-owned uniqueness

Closes #16

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 17, 2026

Open in StackBlitz

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

commit: ee7f5bc

@cowboyd cowboyd force-pushed the refactor/rename-name-to-id branch from 88d2168 to 77cc2bf Compare April 17, 2026 21:07
Restructures the Op type so the discriminant field is `directive`
instead of `id`, freeing `id` for the element identity string. The
`name` parameter on `open()` and `OpenElement` becomes `id`, aligning
with Clay's terminology.

Drops the `idx++` seed from Clay_HashString — element IDs are now
hashed with seed 0 and uniqueness is the caller's responsibility.
Duplicate IDs within a frame are undefined behavior.

Removes INV-7 (element identity disambiguation) from the spec and
updates Sections 8.3.1, 9.3, and 10.3 accordingly.

Closes #16
@cowboyd cowboyd force-pushed the refactor/rename-name-to-id branch from 77cc2bf to ee7f5bc Compare April 17, 2026 21:12
@cowboyd cowboyd merged commit f6cc880 into main Apr 17, 2026
5 checks passed
@cowboyd cowboyd deleted the refactor/rename-name-to-id branch April 17, 2026 21:14
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.

Rename open() name parameter to id and restructure Op type

1 participant