-
Notifications
You must be signed in to change notification settings - Fork 0
feat(datamodel): introduce side-effect free element accessors #87
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -273,7 +273,13 @@ class Element implements ToValue, Equatable, Freezable { | |||||||||||||||
|
|
||||||||||||||||
| /** Unique identifier for this element. */ | ||||||||||||||||
| get id(): Element { | ||||||||||||||||
| return this.getMetaProperty('id', ''); | ||||||||||||||||
| if (this.isFrozen) { | ||||||||||||||||
| return this.getMetaProperty('id', '') as Element; | ||||||||||||||||
| } | ||||||||||||||||
| if (!this.hasMetaProperty('id')) { | ||||||||||||||||
| this.setMetaProperty('id', ''); | ||||||||||||||||
| } | ||||||||||||||||
| return this.meta.get('id') as Element; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| set id(value: Element | string) { | ||||||||||||||||
|
|
@@ -282,7 +288,13 @@ class Element implements ToValue, Equatable, Freezable { | |||||||||||||||
|
|
||||||||||||||||
| /** CSS-like class names. */ | ||||||||||||||||
| get classes(): ArrayElement { | ||||||||||||||||
| return this.getMetaProperty('classes', []) as ArrayElement; | ||||||||||||||||
| if (this.isFrozen) { | ||||||||||||||||
| return this.getMetaProperty('classes', []) as ArrayElement; | ||||||||||||||||
| } | ||||||||||||||||
| if (!this.hasMetaProperty('classes')) { | ||||||||||||||||
| this.setMetaProperty('classes', []); | ||||||||||||||||
| } | ||||||||||||||||
| return this.meta.get('classes') as ArrayElement; | ||||||||||||||||
char0n marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| set classes(value: ArrayElement | unknown[]) { | ||||||||||||||||
|
|
@@ -291,7 +303,13 @@ class Element implements ToValue, Equatable, Freezable { | |||||||||||||||
|
|
||||||||||||||||
| /** Hyperlinks associated with this element. */ | ||||||||||||||||
| get links(): ArrayElement { | ||||||||||||||||
| return this.getMetaProperty('links', []) as ArrayElement; | ||||||||||||||||
| if (this.isFrozen) { | ||||||||||||||||
| return this.getMetaProperty('links', []) as ArrayElement; | ||||||||||||||||
| } | ||||||||||||||||
| if (!this.hasMetaProperty('links')) { | ||||||||||||||||
| this.setMetaProperty('links', []); | ||||||||||||||||
| } | ||||||||||||||||
| return this.meta.get('links') as ArrayElement; | ||||||||||||||||
char0n marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| set links(value: ArrayElement | unknown[]) { | ||||||||||||||||
|
|
@@ -451,16 +469,27 @@ class Element implements ToValue, Equatable, Freezable { | |||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| /** | ||||||||||||||||
| * Gets a meta property, creating it with default value if not present. | ||||||||||||||||
| * Gets a meta property. | ||||||||||||||||
| * | ||||||||||||||||
| * When the property doesn't exist: | ||||||||||||||||
| * - With defaultValue: returns a new refracted element instance (not cached) | ||||||||||||||||
| * - Without defaultValue: returns undefined | ||||||||||||||||
| * | ||||||||||||||||
| * Note: Each call with a default creates a new instance. Use setMetaProperty | ||||||||||||||||
| * first if you need reference equality across multiple accesses. | ||||||||||||||||
|
Comment on lines
+478
to
+479
|
||||||||||||||||
| * Note: Each call with a default creates a new instance. Use setMetaProperty | |
| * first if you need reference equality across multiple accesses. | |
| * Note: When the property is missing, each call that supplies a default | |
| * creates a new instance (the value is not cached). Once the property | |
| * exists, the stored value is returned and the default is ignored. Use | |
| * setMetaProperty first if you need reference equality across multiple | |
| * accesses. |
Copilot
AI
Feb 12, 2026
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.
getMetaProperty uses defaultValue === undefined to decide whether a default was provided. This makes getMetaProperty(name, undefined) indistinguishable from calling it without a default, which changes behavior compared to passing an explicit default. Use arguments.length (or similar) to distinguish “no default argument” from “default explicitly set to undefined”.
| if (!this.hasMetaProperty(name)) { | |
| if (defaultValue === undefined) { | |
| const hasDefaultArg = arguments.length >= 2; | |
| if (!this.hasMetaProperty(name)) { | |
| if (!hasDefaultArg) { |
char0n marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Feb 12, 2026
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.
The overload getMetaProperty(name, defaultValue): Element is not guaranteed by the implementation: if the meta key exists with an explicit undefined value (possible via setMetaProperty/ObjectElement.set), this.meta.get(name) returns undefined, even when a defaultValue is provided. Either prevent storing undefined for meta properties, treat undefined values as “missing” when reading (so the default applies), or relax the overload return type to Element | undefined to match runtime behavior.
Uh oh!
There was an error while loading. Please reload this page.