Skip to content

Commit

Permalink
Demo_Gen: Default Values Bugfix (#701)
Browse files Browse the repository at this point in the history
* Adding default values fix

* Generation
  • Loading branch information
ambiguousname authored Oct 1, 2024
1 parent 32fd9ee commit f9dfe7a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 30 deletions.
18 changes: 8 additions & 10 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.

18 changes: 8 additions & 10 deletions feature_tests/demo_gen/demo/rendering/rendering.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ParameterTemplate extends HTMLElement {
inputElement = null;

static baseTemplate;
constructor(options = {}, className, selector, ...args) {
constructor(options = {}, className, selector, defaultValue=null, ...args) {
super();
generateTemplate(ParameterTemplate, "baseTemplate", "#parameter");
generateTemplate(className, "template", selector);
Expand All @@ -34,6 +34,8 @@ class ParameterTemplate extends HTMLElement {
if ("defaultValue" in options) {
this.default = options.defaultValue;
this.setValue(options.defaultValue);
} else {
this.default = defaultValue;
}
}

Expand Down Expand Up @@ -61,10 +63,9 @@ class ParameterTemplate extends HTMLElement {
customElements.define("terminus-param", ParameterTemplate);

class BooleanTemplate extends ParameterTemplate {
default = false;
static template;
constructor(options) {
super(options, BooleanTemplate, "template#boolean");
super(options, BooleanTemplate, "template#boolean", false);
}

getEventValue(event) {
Expand All @@ -79,10 +80,9 @@ class BooleanTemplate extends ParameterTemplate {
customElements.define("terminus-param-boolean", BooleanTemplate);

class NumberTemplate extends ParameterTemplate {
default = 0;
static template;
constructor(options) {
super(options, NumberTemplate, "template#number");
super(options, NumberTemplate, "template#number", 0);
}

getEventValue(event) {
Expand All @@ -93,20 +93,18 @@ class NumberTemplate extends ParameterTemplate {
customElements.define("terminus-param-number", NumberTemplate);

class StringTemplate extends ParameterTemplate {
default = "";
static template;
constructor(options) {
super(options, StringTemplate, "template#string");
super(options, StringTemplate, "template#string", "");
}
}

customElements.define("terminus-param-string", StringTemplate);

class StringArrayTemplate extends ParameterTemplate {
default = [];
static template;
constructor(options) {
super(options, StringArrayTemplate, "template#string-array");
super(options, StringArrayTemplate, "template#string-array", []);
}

getEventValue(event) {
Expand Down Expand Up @@ -136,7 +134,7 @@ class EnumTemplate extends ParameterTemplate {

#enumType;
constructor(options, enumType) {
super(options, EnumTemplate, "template#enum", enumType);
super(options, EnumTemplate, "template#enum", null, enumType);
this.#enumType = enumType;
}

Expand Down
18 changes: 8 additions & 10 deletions tool/templates/demo_gen/default_renderer/rendering.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class ParameterTemplate extends HTMLElement {
inputElement = null;

static baseTemplate;
constructor(options = {}, className, selector, ...args) {
constructor(options = {}, className, selector, defaultValue=null, ...args) {
super();
generateTemplate(ParameterTemplate, "baseTemplate", "#parameter");
generateTemplate(className, "template", selector);
Expand All @@ -34,6 +34,8 @@ class ParameterTemplate extends HTMLElement {
if ("defaultValue" in options) {
this.default = options.defaultValue;
this.setValue(options.defaultValue);
} else {
this.default = defaultValue;
}
}

Expand Down Expand Up @@ -61,10 +63,9 @@ class ParameterTemplate extends HTMLElement {
customElements.define("terminus-param", ParameterTemplate);

class BooleanTemplate extends ParameterTemplate {
default = false;
static template;
constructor(options) {
super(options, BooleanTemplate, "template#boolean");
super(options, BooleanTemplate, "template#boolean", false);
}

getEventValue(event) {
Expand All @@ -79,10 +80,9 @@ class BooleanTemplate extends ParameterTemplate {
customElements.define("terminus-param-boolean", BooleanTemplate);

class NumberTemplate extends ParameterTemplate {
default = 0;
static template;
constructor(options) {
super(options, NumberTemplate, "template#number");
super(options, NumberTemplate, "template#number", 0);
}

getEventValue(event) {
Expand All @@ -93,20 +93,18 @@ class NumberTemplate extends ParameterTemplate {
customElements.define("terminus-param-number", NumberTemplate);

class StringTemplate extends ParameterTemplate {
default = "";
static template;
constructor(options) {
super(options, StringTemplate, "template#string");
super(options, StringTemplate, "template#string", "");
}
}

customElements.define("terminus-param-string", StringTemplate);

class StringArrayTemplate extends ParameterTemplate {
default = [];
static template;
constructor(options) {
super(options, StringArrayTemplate, "template#string-array");
super(options, StringArrayTemplate, "template#string-array", []);
}

getEventValue(event) {
Expand Down Expand Up @@ -136,7 +134,7 @@ class EnumTemplate extends ParameterTemplate {

#enumType;
constructor(options, enumType) {
super(options, EnumTemplate, "template#enum", enumType);
super(options, EnumTemplate, "template#enum", null, enumType);
this.#enumType = enumType;
}

Expand Down

0 comments on commit f9dfe7a

Please sign in to comment.