-
-
Notifications
You must be signed in to change notification settings - Fork 2
3月のパッケージアップデート #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3月のパッケージアップデート #159
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -10,8 +10,19 @@ permissions: | |||
| contents: read | ||||
|
|
||||
| jobs: | ||||
| lint: | ||||
| uses: ./.github/workflows/lint.yml | ||||
|
|
||||
| integration: | ||||
| uses: ./.github/workflows/integration.yml | ||||
|
|
||||
| publish: | ||||
| needs: [lint, integration] | ||||
| runs-on: ubuntu-latest | ||||
| permissions: | ||||
| contents: read | ||||
| pull-requests: write | ||||
|
||||
| pull-requests: write |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -149,6 +149,12 @@ Next2D Framework 可以作为单页应用程序通过 URL 控制场景。路由 | |||||
| ### 使用缓存 | ||||||
|
|
||||||
| 设置 `cache: true` 会缓存数据。缓存的数据在画面转换中持久存在。 | ||||||
| `app.getCache()` 返回 `Map<string, unknown>`,可通过每个请求的 `name` 键访问。 | ||||||
|
|
||||||
| 缓存使用要点: | ||||||
|
|
||||||
| - 如果同一键已存在,请求处理可优先复用缓存值。 | ||||||
| - 缓存不会自动清理,不再需要时请显式使用 `delete` 或 `clear`。 | ||||||
|
|
||||||
| ```json | ||||||
| { | ||||||
|
|
@@ -216,7 +222,15 @@ export class HomeDataCallback | |||||
|
|
||||||
| ### app.gotoView() | ||||||
|
|
||||||
| 使用 `app.gotoView()` 进行画面转换: | ||||||
| 使用 `app.gotoView(name?: string)` 进行画面转换。其返回 `Promise<void>`,可等待请求完成、View/ViewModel 重新绑定以及 `onEnter()` 执行完成。 | ||||||
|
|
||||||
| `gotoView` 要点: | ||||||
|
|
||||||
| - `name` 参数类型是 `string`(可省略,默认值为 `""`)。 | ||||||
| - `name` 使用 `routing.json` 的键,例如 `home`、`quest/list`。 | ||||||
| - 支持附带 `?id=123` 这类查询字符串。 | ||||||
| - 省略 `name` 时,会从当前 URL 解析目标路由(SPA 的 `popstate` 流程)。 | ||||||
| - 开始新转换时会清空上一轮的 `response` 数据。 | ||||||
|
|
||||||
| ```typescript | ||||||
| import { app } from "@next2d/framework"; | ||||||
|
|
@@ -267,9 +281,26 @@ export class TopViewModel extends ViewModel | |||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ### app.getContext() | ||||||
|
|
||||||
| 使用 `app.getContext()` 获取当前运行中的 `Context`。其中包含 `root`(根 `Sprite`)、`view`、`viewModel` 引用。转换过程中 `view` 与 `viewModel` 可能暂时为 `null`。 | ||||||
|
||||||
| 使用 `app.getContext()` 获取当前运行中的 `Context`。其中包含 `root`(根 `Sprite`)、`view`、`viewModel` 引用。转换过程中 `view` 与 `viewModel` 可能暂时为 `null`。 | |
| 使用 `app.getContext()` 获取当前运行中的 `Context`。其中包含 `root`(根 `Sprite`)、`view`、`viewModel` 引用。转换过程中 `view` 与 `viewModel` 可能暂时为 `null`。注意:必须先通过 `app.run()` 等方式启动应用并完成 `Context` 初始化后再调用本方法;如果在 `Context` 尚未初始化时调用,`app.getContext()` 会抛出 `"Context is not initialized. Call run() first."` 异常。 |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -295,7 +295,15 @@ export class HomeView extends View<HomeViewModel> | |||||
|
|
||||||
| ## 画面转换 | ||||||
|
|
||||||
| 使用 `app.gotoView()` 进行画面转换。 | ||||||
| 使用 `app.gotoView(name?: string)` 进行画面转换。返回值是 `Promise<void>`,可用于等待完整的转换流程(请求执行、View/ViewModel 重新绑定、`onEnter()` 调用)。 | ||||||
|
|
||||||
| `gotoView` 要点: | ||||||
|
|
||||||
| - `name` 参数类型是 `string`(可省略,默认值为 `""`)。 | ||||||
| - `name` 传入 `routing.json` 的键(如 `home`、`quest/list`),也支持 `?id=123` 这类查询字符串。 | ||||||
| - 省略 `name` 时,会从当前 URL 解析目标路由(常用于 SPA 的 `popstate` 流程)。 | ||||||
| - 转换开始时会先清空上一画面的 `response`,然后将新请求结果按 `name` 键重新写入。 | ||||||
| - 当 `config.json` 中设置 `all.spa: true` 时,普通转换会通过 `pushState` 更新浏览器历史。 | ||||||
|
|
||||||
| ```typescript | ||||||
| import { app } from "@next2d/framework"; | ||||||
|
|
@@ -321,9 +329,34 @@ export class NavigateToViewUseCase | |||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ## 获取上下文 | ||||||
|
|
||||||
| `app.getContext()` 返回当前运行时的 `Context`,包含: | ||||||
|
||||||
| `app.getContext()` 返回当前运行时的 `Context`,包含: | |
| `app.getContext()` 返回当前运行时的 `Context`,包含(前提是应用已启动且 Context 已初始化,否则该方法可能抛出异常): |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -149,6 +149,12 @@ Enclose with `{{***}}` to get variables from `config.json`: | |||||
| ### Using Cache | ||||||
|
|
||||||
| Setting `cache: true` caches the data. Cached data persists through screen transitions. | ||||||
| `app.getCache()` returns `Map<string, unknown>`, and values are accessed by each request `name`. | ||||||
|
|
||||||
| Key points for cache usage: | ||||||
|
|
||||||
| - If the same key already exists, request processing can reuse cached values. | ||||||
| - Cache is not auto-cleared, so remove unused entries explicitly with `delete` or `clear`. | ||||||
|
|
||||||
| ```json | ||||||
| { | ||||||
|
|
@@ -216,7 +222,15 @@ export class HomeDataCallback | |||||
|
|
||||||
| ### app.gotoView() | ||||||
|
|
||||||
| Use `app.gotoView()` for screen transitions: | ||||||
| Use `app.gotoView(name?: string)` for screen transitions. It returns `Promise<void>` so you can await request completion, View/ViewModel rebind, and `onEnter()`. | ||||||
|
|
||||||
| Key points for `gotoView`: | ||||||
|
|
||||||
| - The `name` parameter type is `string` (optional, default is `""`). | ||||||
| - `name` is a `routing.json` key such as `home` or `quest/list`. | ||||||
| - You can include query strings such as `?id=123`. | ||||||
| - If `name` is omitted, the destination is resolved from the current URL (SPA `popstate` flow). | ||||||
| - Previous transition `response` data is cleared when a new transition starts. | ||||||
|
|
||||||
| ```typescript | ||||||
| import { app } from "@next2d/framework"; | ||||||
|
|
@@ -267,9 +281,26 @@ export class TopViewModel extends ViewModel | |||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| ### app.getContext() | ||||||
|
|
||||||
| Use `app.getContext()` to get the active `Context`. It provides references to `root` (root `Sprite`), `view`, and `viewModel`. During transitions, `view` and `viewModel` can temporarily be `null`. | ||||||
|
||||||
| Use `app.getContext()` to get the active `Context`. It provides references to `root` (root `Sprite`), `view`, and `viewModel`. During transitions, `view` and `viewModel` can temporarily be `null`. | |
| Use `app.getContext()` to get the active `Context`. It provides references to `root` (root `Sprite`), `view`, and `viewModel`. During transitions, `view` and `viewModel` can temporarily be `null`. If the application has not been started and the context has not been initialized (for example, before calling `run()`), `app.getContext()` will throw an error such as `"Context is not initialized. Call run() first."`. |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -295,7 +295,15 @@ export class HomeView extends View<HomeViewModel> | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Screen Transition | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Use `app.gotoView()` for screen transitions. | ||||||||||||||||||||||||||
| Use `app.gotoView(name?: string)` for screen transitions. It returns `Promise<void>`, so you can await the full transition flow (request execution, View/ViewModel rebind, and `onEnter()`). | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Key points for `gotoView`: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| - The `name` parameter type is `string` (optional, default is `""`). | ||||||||||||||||||||||||||
| - Pass a `routing.json` key such as `home` or `quest/list`. Query strings like `?id=123` are also supported. | ||||||||||||||||||||||||||
| - If `name` is omitted, the destination is resolved from the current URL (used in SPA `popstate` flows). | ||||||||||||||||||||||||||
| - At transition start, the previous `response` map is cleared, then new request results are stored by their `name` keys. | ||||||||||||||||||||||||||
| - When `all.spa: true` in `config.json`, normal transitions update browser history via `pushState`. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ```typescript | ||||||||||||||||||||||||||
| import { app } from "@next2d/framework"; | ||||||||||||||||||||||||||
|
|
@@ -321,9 +329,34 @@ export class NavigateToViewUseCase | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| ## Getting Context | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| `app.getContext()` returns the current runtime `Context`. It includes: | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| - `root`: Root `Sprite` under Stage | ||||||||||||||||||||||||||
| - `view`: Currently bound View (can be `null` during transition or right after startup) | ||||||||||||||||||||||||||
| - `viewModel`: Currently bound ViewModel (can be `null` during transition or right after startup) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Comment on lines
+334
to
+339
|
||||||||||||||||||||||||||
| `app.getContext()` returns the current runtime `Context`. It includes: | |
| - `root`: Root `Sprite` under Stage | |
| - `view`: Currently bound View (can be `null` during transition or right after startup) | |
| - `viewModel`: Currently bound ViewModel (can be `null` during transition or right after startup) | |
| `app.getContext()` returns the current runtime `Context` once the application has been initialized with `app.run()`. It includes: | |
| - `root`: Root `Sprite` under Stage | |
| - `view`: Currently bound View (can be `null` during transition or right after startup) | |
| - `viewModel`: Currently bound ViewModel (can be `null` during transition or right after startup) | |
| > Note: If you call `app.getContext()` before the context has been initialized (that is, before `app.run()` has completed), it will throw an error: `"Context is not initialized. Call run() first."`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the newly added
lint/integrationjobs, the workflow-levelpermissions(includingid-token: write) will also apply to those jobs unless overridden. Consider explicitly setting minimalpermissionson thelintandintegrationjobs (e.g.,contents: read) and/or movingid-token: writeto only thepublishjob to avoid over-privileging the reusable workflows.