연결될 타겟과 props를 인자로 받는다. this바인딩
선언
export default class Component<T> {
$target: Element;
props: T;
constructor($target: Element, props?: T) {
this.$target = $target;
this.props = props;
}
}
사용
공통 Component를 확장하고 super함수에 targe과 props를 인자를 넣고 실행하면
this.target과 this.props가 자동 생성되어 사용할 수 있다
class ImageSlider extends Component<PropsType> {
constructor($target: Element, props: PropsType) {
super($target, props);
}
export Skima class Component<PropsType> {
state:StateType
constructor($target: Element, props: PropsType) {
super($target, props);
this.state
}
setState(newState) {
this.state = newState;
this.render();
}
template() {
return ``;
}
render() {
this.$target.innerHTML = this.template();
this.mount();
}
mount() {}
async initialState() {}
}
this.state: 내부에서 사용하는 데이터
this.props: 외부에서 들어온 데이터
this.target: 루트 dom
mount()
render()
setState()
template()
eventHandler():