This project is archived. Its data is
read-only
.
Changes
Page history
smolamic created page: dynamic components
authored
Oct 12, 2018
by
Michel Smola
Show whitespace changes
Inline
Side-by-side
dynamic-components.md
0 → 100644
View page @
5dc3494f
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