зеркало из https://github.com/github/catalyst.git
drop attributes
This commit is contained in:
Родитель
adce14dc19
Коммит
6aacacd543
|
@ -1,5 +1,5 @@
|
|||
<hello-controller>
|
||||
<input data-target="hello.input" type="text" />
|
||||
<input data-target="hello.name" type="text" />
|
||||
|
||||
<button data-action="click->hello#greet">
|
||||
Greet
|
||||
|
|
19
index.ts
19
index.ts
|
@ -40,29 +40,14 @@ function target(proto, propertyKey) {
|
|||
});
|
||||
}
|
||||
|
||||
function attribute(proto, propertyKey) {
|
||||
Object.defineProperty(proto, propertyKey, {
|
||||
get() {
|
||||
console.log('get attribute', propertyKey, this)
|
||||
return this.getAttribute("data-" + propertyKey);
|
||||
},
|
||||
set(value) {
|
||||
return this.setAttribute("data-" + propertyKey, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
@controllerElement
|
||||
class Hello extends HTMLElement {
|
||||
@target input = HTMLInputElement;
|
||||
@target name = HTMLInputElement;
|
||||
@target output = HTMLElement;
|
||||
|
||||
@attribute name = "World";
|
||||
|
||||
greet() {
|
||||
this.outputTarget.textContent = `Hello, ${this.inputTarget.value}!`;
|
||||
this.outputTarget.textContent = `Hello, ${this.nameTarget.value}!`;
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче