Skip to content

Commit

Permalink
Enum Default Values Fix (rust-diplomat#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
ambiguousname authored Oct 23, 2024
1 parent 0ce7ebb commit 808d18a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
12 changes: 7 additions & 5 deletions example/demo_gen/demo/rendering/rendering.mjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions feature_tests/demo_gen/demo/rendering/rendering.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ParameterTemplate extends HTMLElement {
if ("defaultValue" in options) {
this.default = options.defaultValue;
this.setValue(options.defaultValue);
} else {
} else if (this.default === null) {
this.default = defaultValue;
}
}
Expand Down Expand Up @@ -140,11 +140,13 @@ class EnumTemplate extends ParameterTemplate {

initialize(clone, enumType) {
let options = clone.querySelector("*[data-options]");

if (this.default === null) {
for (let entry of enumType.getAllEntries()) {
options.append(...(new EnumOption(entry[0])).children);

for (let entry of enumType.getAllEntries()) {

if (this.default === null) {
this.default = entry[0];
}
options.append(...(new EnumOption(entry[0])).children);
}
}

Expand Down
12 changes: 7 additions & 5 deletions tool/templates/demo_gen/default_renderer/rendering.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ParameterTemplate extends HTMLElement {
if ("defaultValue" in options) {
this.default = options.defaultValue;
this.setValue(options.defaultValue);
} else {
} else if (this.default === null) {
this.default = defaultValue;
}
}
Expand Down Expand Up @@ -140,11 +140,13 @@ class EnumTemplate extends ParameterTemplate {

initialize(clone, enumType) {
let options = clone.querySelector("*[data-options]");

if (this.default === null) {
for (let entry of enumType.getAllEntries()) {
options.append(...(new EnumOption(entry[0])).children);

for (let entry of enumType.getAllEntries()) {

if (this.default === null) {
this.default = entry[0];
}
options.append(...(new EnumOption(entry[0])).children);
}
}

Expand Down

0 comments on commit 808d18a

Please sign in to comment.