esmDevelopers
JSプラグイン
esm API
JSプラグイン
esm API
  • Listenable

Listenable

ListenableクラスはeventHookを登録・解除するインタフェースを提供します。

継承

なし

インスタンスメソッド

unlistenGroup

引数で指定したgroupのeventHookを全て解除します。

構文

unlistenGroup();
unlistenGroup(group);
引数

group

指定されたgroupで登録されたeventHookを全て解除します。

省略した場合、groupを指定せず登録したeventHookが全て解除されます。

返値

なし

例

esmJSPlugin.screen.sheetSave("customer").onEntered(function (screen) {
  const customerNameItem = screen.getSheetItemByLabel("顧客名");

  customerNameItem.onMounted(
    function () {
      console.log("mounted");
    },
    "test-plugin" // eventHook登録時にグループを指定
  );
  customerNameItem.onUpdated(
    function () {
      console.log("updated");
      customerNameItem.unlistenGroup("test-plugin"); // "test-plugin"で登録されたeventHookを全て解除
    },
    "test-plugin" // eventHook登録時にグループを指定
  );
});

顧客名項目の初期化時と更新時に一度だけ処理が走り、以降の更新時には実行されません。

unlistenAll

登録されているeventHookを全て解除します。

構文

unlistenAll();
引数

なし

返値

なし

例

esmJSPlugin.screen.sheetSave("customer").onEntered(function (screen) {
  const customerNameItem = screen.getSheetItemByLabel("顧客名");

  customerNameItem.onMounted(
    function () {
      console.log("mounted");
    },
    "test-plugin" // eventHook登録時にグループを指定
  );
  customerNameItem.onUpdated(
    function () {
      console.log("updated");
      customerNameItem.unlistenAll();
    }
    // eventHook登録時にグループを指定しない
  );
});

顧客名項目の初期化時と更新時に一度だけ処理が走り、以降の更新時には実行されません。

groupの指定に関わらず全てのeventHookを解除します。

関連情報

  • eventHook