ViewElement: detach()
ViewElement
に取り付けられている ViewLogic
を取り外します。
構文
viewElement.detach() => ViewLogic | null
返値: ViewLogic
| null
呼び出し前に対象の ViewElement
に取り付けられていた ViewLogic
です。なにも取り付けられていなかった場合は null
を返します。
例
const vl = new class extends ViewLogic {
constructor() {
super();
this.loadContainer({
text: `<div id="hello"><p>Hello!</p></div>`,
id: "hello",
});
this.relateElements(this.collectElements(this.container));
}
async messageHandler(msg) {
msg.deliver({
vl$attached: () => {
// attach() 呼び出し後に実行される
console.log("attached!");
},
vl$detached: () => {
// detach() 呼び出し後に実行される
console.log("detached!");
},
});
}
};
// vl を Alier.View へ取り付ける
Alier.View.attach(vl);
// ==> "attached!"
const detachedVl = Alier.View.detach();
// ==> "detached!"
console.log(detachedVl === vl);
// ==> true
解説
取り付けられている ViewLogic
がなければこの関数は何も行いません。
取り外しに成功すると、取り外した ViewLogic
にメッセージ { id: "vl$detached" }
が送出されます。メッセージのパラメータについては ViewLogic::detachFrom()
を参照してください。