LoginSignup
0
0

More than 1 year has passed since last update.

Next2D Frameworkのrouting設定[導入編]

Last updated at Posted at 2021-12-16

routing.json

routing設定について解説したいと思います。
ルーティングに設定できるトッププロパティは、英数字、スラッシュ、ハイフン、アンダースコアです。スラッシュ、ハイフン、アンダースコアをキーにCamelCaseViewクラスにアクセスします。

例)
下記のサンプルの場合は、https://example.com/quest/listでアクセスが可能になり、コンテキストにQuestListView.jsがセットされます。

routing.json
{
    "quest/list": {
        "requests": []
    }
}

第二階層のプロパティ設定

プロパティ 初期値 説明
private boolean false SPAモードでも直接のアクセスを制御した時に利用します。trueに設定し直接アクセスすると、TopViewが読み込まれます。
requests array null Viewにアクセスする前に、指定した先にリクエストを送信します。受け取った情報は、nameをキーにnext2d.fw.responseに設定されます。

requests

requests配列の設定は以下の項目が利用可能です。

プロパティ 初期値 説明
type string content json、content、image、customの固定値が利用可能です。
path string empty {{***}}で囲むと、config.jsonの変数を取得できます。例){{ api.endPoint }}path/to/api
name string empty nameを設定すると、設定した値をキーとして取得したデータをnext2d.fw.responseに格納します。
cache boolean false nameで設定した値をキーにして、取得したデータをキャッシュする。
callback string or array null リクエスト完了後にコールバックするクラスを指定することができます。指定したクラスのコントラクターの第一引数に取得した値が設定されます。
class string empty リクエストを実行するクラスを指定することができます。(typeがcustomのときのみ呼び出されます。)
access string public リクエストを実行する関数へのアクセスを指定できます。publicあるいはstaticを指定することができます。(typeがcustomのときのみ呼び出されます)。
method string empty リクエストを実行する関数を指定することができます。(typeがcustomのときのみ起動します)。

以下は初期で設定されているjsonです。

routing.json
{
  "top": {
    "requests": [
      {
        "type": "json",
        "path": "{{ api.endPoint }}api/top.json",
        "name": "TopText"
      },
      {
        "type": "content",
        "path": "{{ content.endPoint }}content/sample.json",
        "name": "MainContent",
        "cache": true
      }
    ]
  },
  "home": {
    "requests": [
      {
        "type": "custom",
        "class": "api.HomeText",
        "access": "static",
        "method": "get",
        "name": "HomeText",
        "cache": true
      },
      {
        "type": "content",
        "path": "{{ content.endPoint }}content/sample.json",
        "name": "MainContent",
        "cache": true
      }
    ]
  }
}

routing設定は設計を考慮する点からも重要な設定項目になりますので、是非、初期サンプルを参考にしていただければと思います。明日はカスタム設定に関しての記事を書きたいと思います。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0