ViewLogic

--- config: class: hideEmptyMembersBox: true --- classDiagram direction LR ProtoViewLogic <|-- ViewLogic link ProtoViewLogic "../ProtoViewLogic/protoviewlogic"

概要

ユーザとモデルインタフェースを仲介するクラスです。

詳細は ViewLogic モジュール を参照してください。

メソッド


attachTo()

  • ViewLogicAlierView に取り付けます。

detachFrom()

  • ViewLogicAlierView から取り外します。

parseHtmlToContainer()

  • HTML 文字列をパースし、パース結果からコンテナを取得します。

post()

  • 対象の ViewLogic にメッセージを送ります。

setContainer()

  • 対象の ViewLogic のコンテナを与えられた Element で置き換えます。

loadContainer()

  • テキストやファイルからコンテナを読み込みます。

loadContainerSync()

  • テキストやファイルからコンテナを同期で読み込みます。

replaceWithGrid()

  • 呼び出し先の ViewLogic のコンテンツ container を、ViewLogic に関連付けられた(ProtoViewLogic.relateElements() 参照)Element をグリッドレイアウトしたもので置換します。

プロパティ


container

AlierView に反映するコンテンツのルート要素です。

HTMLElement


host

このプロパティは読み取り専用です。

自身のコンテナが取り付けられている AlierView です。

AlierView | null

詳細

取り付けられた AlierView がない場合、プロパティ host の値は null となります。

このプロパティは AlierView のメソッド attach() および detach() によって変更されます。

AlierView::attach() で呼び出し先の AlierViewhost に設定されます。このとき、この ViewLogic に対してメッセージ { id: "vl$attached" }post() されます。メッセージのパラメータについては attachTo を参照してください。

AlierView::detach() で呼び出し先の AlierViewhost に設定されていたら、hostnull に変更されます。このとき、この ViewLogic に対してメッセージ { id: "vl$detached" }post() されます。メッセージのパラメータについては detachFrom() を参照してください。

const vl = new class extends ViewLogic {
    async messageHandler(msg) {
        return msg.deliver({
            vl$attached: (msg) => {
                const { target, newHost } = msg.param;
                console.log("attached!", target, newHost);
            },
            vl$detached: (msg) => {
                const { target, oldHost } = msg.param;
                console.log("detached!", target, oldHost);
            },
        });
    }
};

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

//  Alier.View から vl を取り外す
Alier.View.detach();

//  static attachTo() を使って vl を Alier.View に取り付ける (Alier.View.attach(vl) と等価)
ViewLogic.attachTo(vl, Alier.View);

//  static detachFrom() を使って vl を Alier.View から取り外す (vl.host === Alier.View && Alier.View.detach() と等価)
ViewLogic.attachTo(vl, Alier.View);

styles

このプロパティは読み取り専用です。

コンテナ要素に適用するスタイル定義を保持するためのラッパーオブジェクトです。

HTMLDivElement

詳細

子要素としてコンテナから取り出した <style> および <link rel="stylesheet"> を持ちます。

コンストラクタを呼び出してコンテナ要素の読み込みが完了した後、コンテナに含まれるすべてのスタイル定義がプロパティ styles の子要素に移動されます。

このプロパティは読み取り専用です。