Skip to content

Commit 21feacc

Browse files
authored
Merge pull request #159 from Next2D/develop
3月のパッケージアップデート
2 parents 2b90ebe + 2e6996f commit 21feacc

11 files changed

Lines changed: 251 additions & 34 deletions

File tree

.github/workflows/integration.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ name: Integration UnitTest
33
on:
44
push:
55
branches:
6-
- main
76
- develop
87
pull_request:
98
branches:
109
- main
1110
- develop
11+
workflow_call:
1212

1313
jobs:
1414
macos-browser-test:
1515
runs-on: macos-latest
1616
permissions:
1717
contents: read
18-
pull-requests: write
1918
steps:
2019
- uses: actions/setup-node@v6
2120
with:
@@ -33,7 +32,6 @@ jobs:
3332
runs-on: windows-latest
3433
permissions:
3534
contents: read
36-
pull-requests: write
3735
steps:
3836
- uses: actions/setup-node@v6
3937
with:

.github/workflows/lint.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,18 @@ name: Lint
33
on:
44
push:
55
branches:
6-
- main
76
- develop
87
pull_request:
98
branches:
109
- main
1110
- develop
11+
workflow_call:
1212

1313
jobs:
1414
macos-browser-test:
1515
runs-on: macos-latest
1616
permissions:
1717
contents: read
18-
pull-requests: write
1918
steps:
2019
- uses: actions/checkout@v6
2120
- uses: actions/setup-node@v6
@@ -24,13 +23,12 @@ jobs:
2423
registry-url: "https://registry.npmjs.org"
2524
- run: npm install -g npm@latest
2625
- run: npm install
27-
- run: npx eslint ./src/**/*.ts
26+
- run: npm run lint
2827

2928
windows-browser-test:
3029
runs-on: windows-latest
3130
permissions:
3231
contents: read
33-
pull-requests: write
3432
steps:
3533
- uses: actions/checkout@v6
3634
- uses: actions/setup-node@v6
@@ -39,4 +37,4 @@ jobs:
3937
registry-url: "https://registry.npmjs.org"
4038
- run: npm install -g npm@latest
4139
- run: npm install
42-
- run: npx eslint ./src/**/*.ts
40+
- run: npm run lint

.github/workflows/publish.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,19 @@ permissions:
1010
contents: read
1111

1212
jobs:
13+
lint:
14+
uses: ./.github/workflows/lint.yml
15+
16+
integration:
17+
uses: ./.github/workflows/integration.yml
18+
1319
publish:
20+
needs: [lint, integration]
1421
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
pull-requests: write
25+
id-token: write
1526
steps:
1627
- uses: actions/checkout@v6
1728
- uses: actions/setup-node@v6

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@next2d/framework",
33
"description": "Next2D Framework is designed according to the principles of clean architecture, domain-driven development, test-driven development, and MVVM, with an emphasis on flexibility, scalability, and maintainability, and a design methodology that keeps each layer loosely coupled.",
4-
"version": "4.0.0",
4+
"version": "4.0.1",
55
"homepage": "https://next2d.app",
66
"bugs": "https://github.com/Next2D/Framework/issues/new",
77
"author": "Toshiyuki Ienaga <ienaga@next2d.app> (https://github.com/ienaga/)",
@@ -31,17 +31,17 @@
3131
"url": "git+https://github.com/Next2D/Framework.git"
3232
},
3333
"devDependencies": {
34-
"@eslint/eslintrc": "^3.3.3",
35-
"@eslint/js": "^9.39.2",
36-
"@types/node": "^25.2.0",
37-
"@typescript-eslint/eslint-plugin": "^8.54.0",
38-
"@typescript-eslint/parser": "^8.54.0",
34+
"@eslint/eslintrc": "^3.3.4",
35+
"@eslint/js": "^10.0.1",
36+
"@types/node": "^25.3.3",
37+
"@typescript-eslint/eslint-plugin": "^8.56.1",
38+
"@typescript-eslint/parser": "^8.56.1",
3939
"@vitest/coverage-v8": "^4.0.18",
4040
"@vitest/web-worker": "^4.0.18",
41-
"eslint": "^9.39.2",
42-
"eslint-plugin-unused-imports": "^4.3.0",
43-
"globals": "^17.3.0",
44-
"jsdom": "^28.0.0",
41+
"eslint": "^10.0.2",
42+
"eslint-plugin-unused-imports": "^4.4.1",
43+
"globals": "^17.4.0",
44+
"jsdom": "^28.1.0",
4545
"typescript": "^5.9.3",
4646
"vite": "^7.3.1",
4747
"vitest": "^4.0.18",

specs/cn/routing.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ Next2D Framework 可以作为单页应用程序通过 URL 控制场景。路由
149149
### 使用缓存
150150

151151
设置 `cache: true` 会缓存数据。缓存的数据在画面转换中持久存在。
152+
`app.getCache()` 返回 `Map<string, unknown>`,可通过每个请求的 `name` 键访问。
153+
154+
缓存使用要点:
155+
156+
- 如果同一键已存在,请求处理可优先复用缓存值。
157+
- 缓存不会自动清理,不再需要时请显式使用 `delete``clear`
152158

153159
```json
154160
{
@@ -216,7 +222,15 @@ export class HomeDataCallback
216222

217223
### app.gotoView()
218224

219-
使用 `app.gotoView()` 进行画面转换:
225+
使用 `app.gotoView(name?: string)` 进行画面转换。其返回 `Promise<void>`,可等待请求完成、View/ViewModel 重新绑定以及 `onEnter()` 执行完成。
226+
227+
`gotoView` 要点:
228+
229+
- `name` 参数类型是 `string`(可省略,默认值为 `""`)。
230+
- `name` 使用 `routing.json` 的键,例如 `home``quest/list`
231+
- 支持附带 `?id=123` 这类查询字符串。
232+
- 省略 `name` 时,会从当前 URL 解析目标路由(SPA 的 `popstate` 流程)。
233+
- 开始新转换时会清空上一轮的 `response` 数据。
220234

221235
```typescript
222236
import { app } from "@next2d/framework";
@@ -267,9 +281,26 @@ export class TopViewModel extends ViewModel
267281
}
268282
```
269283

284+
### app.getContext()
285+
286+
使用 `app.getContext()` 获取当前运行中的 `Context`。其中包含 `root`(根 `Sprite`)、`view``viewModel` 引用。转换过程中 `view``viewModel` 可能暂时为 `null`
287+
288+
```typescript
289+
import { app } from "@next2d/framework";
290+
291+
const context = app.getContext();
292+
const root = context.root;
293+
```
294+
270295
## 获取响应数据
271296

272-
`requests` 的数据可以通过 `app.getResponse()` 获取:
297+
`app.getResponse()` 返回 `Map<string, unknown>`。它保存当前一次转换中 `requests` 里定义了 `name` 的响应数据。
298+
299+
`getResponse` 要点:
300+
301+
- 它是一次 `gotoView` 周期内的临时数据容器。
302+
- 开始下一次 `gotoView` 时会重置。
303+
- 值类型为 `unknown`,使用前请做类型守卫或类型断言。
273304

274305
```typescript
275306
import { app } from "@next2d/framework";

specs/cn/view.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,15 @@ export class HomeView extends View<HomeViewModel>
295295

296296
## 画面转换
297297

298-
使用 `app.gotoView()` 进行画面转换。
298+
使用 `app.gotoView(name?: string)` 进行画面转换。返回值是 `Promise<void>`,可用于等待完整的转换流程(请求执行、View/ViewModel 重新绑定、`onEnter()` 调用)。
299+
300+
`gotoView` 要点:
301+
302+
- `name` 参数类型是 `string`(可省略,默认值为 `""`)。
303+
- `name` 传入 `routing.json` 的键(如 `home``quest/list`),也支持 `?id=123` 这类查询字符串。
304+
- 省略 `name` 时,会从当前 URL 解析目标路由(常用于 SPA 的 `popstate` 流程)。
305+
- 转换开始时会先清空上一画面的 `response`,然后将新请求结果按 `name` 键重新写入。
306+
-`config.json` 中设置 `all.spa: true` 时,普通转换会通过 `pushState` 更新浏览器历史。
299307

300308
```typescript
301309
import { app } from "@next2d/framework";
@@ -321,9 +329,34 @@ export class NavigateToViewUseCase
321329
}
322330
```
323331

332+
## 获取上下文
333+
334+
`app.getContext()` 返回当前运行时的 `Context`,包含:
335+
336+
- `root`:Stage 下的根 `Sprite`
337+
- `view`:当前绑定的 View(转换中或启动初期可能为 `null`
338+
- `viewModel`:当前绑定的 ViewModel(转换中或启动初期可能为 `null`
339+
340+
```typescript
341+
import { app } from "@next2d/framework";
342+
343+
const context = app.getContext();
344+
const root = context.root;
345+
346+
if (context.view && context.viewModel) {
347+
// 访问当前 View / ViewModel
348+
}
349+
```
350+
324351
## 获取响应数据
325352

326-
`routing.json``requests` 的数据可以通过 `app.getResponse()` 获取。
353+
`app.getResponse()` 返回 `Map<string, unknown>``routing.json``requests` 中设置了 `name` 的响应,会按当前一次画面转换写入该 Map。
354+
355+
`getResponse` 要点:
356+
357+
- 它是单次 `gotoView` 的临时数据容器。
358+
- 开始下一次 `gotoView` 时,上一轮内容会被清空。
359+
- 值类型为 `unknown`,业务侧应使用类型守卫或类型断言后再读取。
327360

328361
```typescript
329362
import { app } from "@next2d/framework";
@@ -341,7 +374,13 @@ async initialize(): Promise<void>
341374

342375
## 获取缓存数据
343376

344-
`cache: true` 的数据可以通过 `app.getCache()` 获取。
377+
`app.getCache()` 返回 `Map<string, unknown>`。在 `requests` 中设置 `cache: true` 的数据会跨画面保留,适合主数据等可复用数据。
378+
379+
`getCache` 要点:
380+
381+
- 同时具备 `cache: true``name` 的请求会进入缓存。
382+
- 当相同键已存在时,请求处理可优先复用缓存值。
383+
- 缓存不会自动清理;不再需要时请显式 `delete``clear`
345384

346385
```typescript
347386
import { app } from "@next2d/framework";

specs/en/routing.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ Enclose with `{{***}}` to get variables from `config.json`:
149149
### Using Cache
150150

151151
Setting `cache: true` caches the data. Cached data persists through screen transitions.
152+
`app.getCache()` returns `Map<string, unknown>`, and values are accessed by each request `name`.
153+
154+
Key points for cache usage:
155+
156+
- If the same key already exists, request processing can reuse cached values.
157+
- Cache is not auto-cleared, so remove unused entries explicitly with `delete` or `clear`.
152158

153159
```json
154160
{
@@ -216,7 +222,15 @@ export class HomeDataCallback
216222

217223
### app.gotoView()
218224

219-
Use `app.gotoView()` for screen transitions:
225+
Use `app.gotoView(name?: string)` for screen transitions. It returns `Promise<void>` so you can await request completion, View/ViewModel rebind, and `onEnter()`.
226+
227+
Key points for `gotoView`:
228+
229+
- The `name` parameter type is `string` (optional, default is `""`).
230+
- `name` is a `routing.json` key such as `home` or `quest/list`.
231+
- You can include query strings such as `?id=123`.
232+
- If `name` is omitted, the destination is resolved from the current URL (SPA `popstate` flow).
233+
- Previous transition `response` data is cleared when a new transition starts.
220234

221235
```typescript
222236
import { app } from "@next2d/framework";
@@ -267,9 +281,26 @@ export class TopViewModel extends ViewModel
267281
}
268282
```
269283

284+
### app.getContext()
285+
286+
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`.
287+
288+
```typescript
289+
import { app } from "@next2d/framework";
290+
291+
const context = app.getContext();
292+
const root = context.root;
293+
```
294+
270295
## Getting Response Data
271296

272-
Data from `requests` can be retrieved with `app.getResponse()`:
297+
`app.getResponse()` returns `Map<string, unknown>`. It stores response values whose `name` is defined in `requests` for the current transition.
298+
299+
Key points for `getResponse`:
300+
301+
- It is a temporary store for one `gotoView` cycle.
302+
- The map is reset when the next `gotoView` starts.
303+
- Values are `unknown`; use type guards or type assertions before use.
273304

274305
```typescript
275306
import { app } from "@next2d/framework";

specs/en/view.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,15 @@ export class HomeView extends View<HomeViewModel>
295295

296296
## Screen Transition
297297

298-
Use `app.gotoView()` for screen transitions.
298+
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()`).
299+
300+
Key points for `gotoView`:
301+
302+
- The `name` parameter type is `string` (optional, default is `""`).
303+
- Pass a `routing.json` key such as `home` or `quest/list`. Query strings like `?id=123` are also supported.
304+
- If `name` is omitted, the destination is resolved from the current URL (used in SPA `popstate` flows).
305+
- At transition start, the previous `response` map is cleared, then new request results are stored by their `name` keys.
306+
- When `all.spa: true` in `config.json`, normal transitions update browser history via `pushState`.
299307

300308
```typescript
301309
import { app } from "@next2d/framework";
@@ -321,9 +329,34 @@ export class NavigateToViewUseCase
321329
}
322330
```
323331

332+
## Getting Context
333+
334+
`app.getContext()` returns the current runtime `Context`. It includes:
335+
336+
- `root`: Root `Sprite` under Stage
337+
- `view`: Currently bound View (can be `null` during transition or right after startup)
338+
- `viewModel`: Currently bound ViewModel (can be `null` during transition or right after startup)
339+
340+
```typescript
341+
import { app } from "@next2d/framework";
342+
343+
const context = app.getContext();
344+
const root = context.root;
345+
346+
if (context.view && context.viewModel) {
347+
// Access current View / ViewModel
348+
}
349+
```
350+
324351
## Getting Response Data
325352

326-
Data from `requests` in `routing.json` can be retrieved with `app.getResponse()`.
353+
`app.getResponse()` returns `Map<string, unknown>`. Response values whose `name` is defined in `routing.json` `requests` are stored for the current transition.
354+
355+
Key points for `getResponse`:
356+
357+
- It is a per-transition temporary store for data fetched in one `gotoView`.
358+
- The map is cleared when the next `gotoView` starts.
359+
- Values are `unknown`, so consumers should apply type guards or type assertions.
327360

328361
```typescript
329362
import { app } from "@next2d/framework";
@@ -341,7 +374,13 @@ async initialize(): Promise<void>
341374

342375
## Getting Cache Data
343376

344-
Data with `cache: true` can be retrieved with `app.getCache()`.
377+
`app.getCache()` returns `Map<string, unknown>`. Data from `requests` with `cache: true` is kept across transitions, which is useful for reusable data such as master data.
378+
379+
Key points for `getCache`:
380+
381+
- Requests with both `cache: true` and `name` are eligible for cache storage.
382+
- If the same key already exists, request processing can reuse cached data.
383+
- Cache is not auto-cleared; manage it explicitly with `delete` or `clear` when needed.
345384

346385
```typescript
347386
import { app } from "@next2d/framework";

0 commit comments

Comments
 (0)