-
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 1 commit
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,10 @@ class Element implements ToValue, Equatable, Freezable { | |
|
|
||
| /** Unique identifier for this element. */ | ||
| get id(): Element { | ||
| return this.getMetaProperty('id', ''); | ||
| if (!this.hasMetaProperty('id')) { | ||
| this.setMetaProperty('id', ''); | ||
| } | ||
| return this.meta.get('id') as Element; | ||
| } | ||
|
|
||
| set id(value: Element | string) { | ||
|
|
@@ -282,7 +285,10 @@ class Element implements ToValue, Equatable, Freezable { | |
|
|
||
| /** CSS-like class names. */ | ||
| get classes(): ArrayElement { | ||
| 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 +297,10 @@ class Element implements ToValue, Equatable, Freezable { | |
|
|
||
| /** Hyperlinks associated with this element. */ | ||
| get links(): ArrayElement { | ||
| 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 +460,15 @@ class Element implements ToValue, Equatable, Freezable { | |
| } | ||
|
|
||
| /** | ||
| * Gets a meta property, creating it with default value if not present. | ||
| * Gets a meta property, returning default value if not present. | ||
char0n marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| */ | ||
| public getMetaProperty(name: string, defaultValue: unknown): Element { | ||
| if (!this.meta.hasKey(name)) { | ||
| if (this.isFrozen) { | ||
| const element = this.refract(defaultValue); | ||
| if (!this.hasMetaProperty(name)) { | ||
| const element = this.refract(defaultValue); | ||
| if (element && this.isFrozen) { | ||
| element.freeze(); | ||
| return element; | ||
| } | ||
| this.meta.set(name, defaultValue); | ||
| return element; | ||
char0n marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
char0n marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return this.meta.get(name)!; | ||
| } | ||
|
Comment on lines
+481
to
495
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.