ViewElement: post()

ViewElement に取り付けられたコンテナにメッセージを送ります。

構文

viewElement.post(param) =>  Promise<boolean>

引数

  • msg: { id, code, param, origin }

    処理するメッセージオブジェクトです。

返値: Promise<boolean>

メッセージを送ったコンテナの、メッセージの処理結果です。依頼されたメッセージ処理が消費されたかどうかを返すプロミスです。true ならメッセージが処理されたことを示し、false なら未処理であることを示します。

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({
            post: () => {
                //  ViewElementから送られてきたメッセージを処理する
                console.log("receive messages")
            },
        });
    }
};

//  vl を Alier.View へ取り付ける
Alier.View.attach(vl);


Alier.View.post(vl.message("post","sent","message"))
//  Alier.ViewにattachされているViewLogicにメッセージを送る

解説

ViewElement に取り付けられている ViewLogic にメッセージを送ります。

取り付けられている ViewLogic がなければこの関数は何も行いません。