テーマコンポーネント/プラグイン(JS)の一般的なインポートリスト

テーマコンポーネントを作成する際、さまざまなもののインポートを探し回ることがよくあるため、それらをいくつかコンパイルしてここにまとめました。

Ember関連

名前 インポート 使用法
Component import Component from "@glimmer/component"; export default class MyComponentClass extends Component {}
Action デコレーター import { action } from "@ember/object"; @action
Tracked デコレーター import { tracked } from "@glimmer/tracking"; @tracked myTrackedVar
Service デコレーター import { service } from "@ember/service"; @service modal
(Glimmer テンプレート) on import { on } from "@ember/modifier"; <p {{on "click" this.someAction}}>Click me!</p>[1]

Discourse関連

名前 インポート 使用法
apiInitializer import { apiInitializer } from "discourse/lib/api"; export default apiInitializer((api) => {})
withPluginApi import { withPluginApi } from "discourse/lib/plugin-api"; withPluginApi((api) => {})[2][3]
ConditionalLoadingSpinner import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner"; <ConditionalLoadingSpinner @condition={{this.loading}} />
DButton import DButton from "discourse/components/d-button"; <DButton @icon="..." @action={{this.someAction}} />
ajax import { ajax } from "discourse/lib/ajax"; ajax("/path/here")[4]
i18n import { i18n } from "discourse-i18n"; {{i18n "locale_key"}}[5]
(Glimmer テンプレート) Equals, not equals, greater than, greater than or equals, less than, less than or equals, or, not, and, has, includes import { eq, and, ... } from "truth-helpers"; {{#if (eq this.something this.something2)}}[6]

これらが組み合わされているのを目にするかもしれません。例えば、ConditionalLoadingSpinner の条件としてトラッキングされた変数を使用したり、DButton のアクションとして使用したり、などです。

お役に立てば幸いです!

私はプロではないので、誤りを見つけた場合は、修正にご協力いただくか、ご指摘ください。ありがとうございます :slightly_smiling_face:


  1. inputmousedownfocusin などのイベントも使用できます ↩︎

  2. discourse/app/assets/javascripts/discourse/app/instance-initializers/enable-emoji.js at 99ace1be120b928f6c694d0118959d745cc4bdbe · discourse/discourse · GitHub を参照 ↩︎

  3. apiInitializer の使用が推奨されていると思います。これは古いバージョンではないでしょうか? ↩︎

  4. fetch() と同様に機能します。async 関数内で await キーワードを付けて使用してください。 ↩︎

  5. コアリポジトリからロケールを取得する場合、例: user.summary.stats ↩︎

  6. andor のようなものは、2つ以上の引数を取ることができます ↩︎

「いいね!」 9

ハ、これは素晴らしい!私も同じものを所有していますが、VS Code の AI/オートフィルは頻繁にパスを幻覚表示します :wink:

「いいね!」 1