Skip to content

Commit 79b9851

Browse files
committed
Add update children methods
1 parent f59d3be commit 79b9851

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

Diff for: src/ColorConverter.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ export class ColorConverter extends LitElement {
6262
);
6363
}
6464

65+
updateChildren() {
66+
this._slottedChildren.forEach((child) => {
67+
if (child instanceof ColorConverterInput) {
68+
child.inputValues = this.inputValues;
69+
child.color = this.color;
70+
}
71+
});
72+
}
73+
6574
render() {
6675
const floatCoordinates = {
6776
x: this.coordinates.x / this.coordinates.width,
@@ -75,12 +84,7 @@ export class ColorConverter extends LitElement {
7584
Math.round(this.coordinates.x),
7685
Math.round(this.coordinates.y),
7786
];
78-
this._slottedChildren.forEach((child) => {
79-
if (child instanceof ColorConverterInput) {
80-
child.inputValues = this.inputValues;
81-
child.color = this.color;
82-
}
83-
});
87+
this.updateChildren();
8488
return html`
8589
${bootstrap}
8690
<h5>Color Converter</h5>
@@ -100,7 +104,7 @@ export class ColorConverter extends LitElement {
100104
</table>
101105
<slot
102106
class="d-flex flex-column inputs-container"
103-
@slotchange=${this.render}
107+
@slotchange=${this.updateChildren}
104108
>
105109
</slot>
106110
`;

Diff for: src/ColorPicker.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ export class ColorPicker extends LitElement {
102102
);
103103
}
104104

105-
render() {
106-
this.style.background = "#" + this.color.getHex();
105+
updateChildren() {
107106
this._slottedChildren.forEach((child) => {
108107
if (child instanceof ColorSelection) {
109108
child.color = this.color;
@@ -118,10 +117,15 @@ export class ColorPicker extends LitElement {
118117
child.activeColor = this.interpolationActive;
119118
}
120119
});
120+
}
121+
122+
render() {
123+
this.style.background = "#" + this.color.getHex();
124+
this.updateChildren();
121125
return html` ${bootstrap}
122126
<slot
123127
class="d-flex flex-row flex-wrap main-container"
124-
@slotchange=${this.render}
128+
@slotchange=${this.updateChildren}
125129
>
126130
</slot>`;
127131
}

0 commit comments

Comments
 (0)