ViewElement: attach()

ViewLogic のコンテナが持つコンテンツを取り付けて表示します。

構文

viewElement.attach(containerToBeAttached) => ViewLogic | null

引数

  • containerToBeAttached : ViewLogic

    ViewElement インスタンスに取り付けるコンテナを持った ViewLogic です。

返値: ViewLogic | null

detach() された ViewLogic です。何も detach() されなかった場合は null を返します。

例外

  • TypeError
    • 引数 containerToBeAttached が ViewLogic クラスのインスタンスでなかった場合

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 を Alier.View へ取り付ける
Alier.View.attach(vl);
//  ==>  "attached!"

解説

引数 containerToBeAttached が持つコンテナ要素およびスタイル定義を呼び出し先の ViewElement に取り付けます。containerToBeAttached が既に取り付けられているなら、この関数は何も行いません。

新たに取り付けられた ViewLogic は自身に対して id = "attach" のメッセージを post() します。メッセージのパラメータについては ViewLogic::attachTo() を参照してください。

既に対象の ViewElementViewLogic が取り付けられている場合、この関数の呼び出しの中で対象の ViewElementdetach() を実行します。