You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: package.json
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
{
2
2
"name": "@next2d/framework",
3
3
"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.",
Copy file name to clipboardExpand all lines: specs/en/routing.md
+33-2Lines changed: 33 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -149,6 +149,12 @@ Enclose with `{{***}}` to get variables from `config.json`:
149
149
### Using Cache
150
150
151
151
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`.
152
158
153
159
```json
154
160
{
@@ -216,7 +222,15 @@ export class HomeDataCallback
216
222
217
223
### app.gotoView()
218
224
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.
220
234
221
235
```typescript
222
236
import { app } from"@next2d/framework";
@@ -267,9 +281,26 @@ export class TopViewModel extends ViewModel
267
281
}
268
282
```
269
283
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
+
270
295
## Getting Response Data
271
296
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.
Copy file name to clipboardExpand all lines: specs/en/view.md
+42-3Lines changed: 42 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -295,7 +295,15 @@ export class HomeView extends View<HomeViewModel>
295
295
296
296
## Screen Transition
297
297
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`.
299
307
300
308
```typescript
301
309
import { app } from"@next2d/framework";
@@ -321,9 +329,34 @@ export class NavigateToViewUseCase
321
329
}
322
330
```
323
331
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
+
324
351
## Getting Response Data
325
352
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.
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.
0 commit comments