smolamic created page: dynamic components authored by Michel Smola's avatar Michel Smola
Dynamic components are a way to create something similar to classes that can extend standard HTMLElements.
They are written as plain objects that have a couple of special attributes. A typical component looks like:
```js
const Field = {
base: ({ classList }) => DOMore.create('div', { classList: ['field', ...classList] }),
init({ onClick, type, label, value }) {
},
value: {
get() {
return this.parse(this.valueContainer.textContent);
},
set(value) {
const parsedValue = this.parse(value);
if (!this.validate(parsedValue)) throw new Error('Field received wrong type');
this.valueContainer.textContent = parsedValue;
},
},
};
```
\ No newline at end of file