mobx-route 0.21.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +226 -177
- package/index.cjs.map +1 -1
- package/index.d.ts +79 -52
- package/index.js +228 -179
- package/index.js.map +1 -1
- package/package.json +4 -4
- package/react.cjs +4 -1
- package/react.cjs.map +1 -1
- package/react.d.ts +4 -3
- package/react.js +4 -1
- package/react.js.map +1 -1
- package/view-model.cjs +5 -8
- package/view-model.cjs.map +1 -1
- package/view-model.js +5 -8
- package/view-model.js.map +1 -1
package/index.cjs
CHANGED
|
@@ -5,41 +5,51 @@ const complex = require("yummies/complex");
|
|
|
5
5
|
const linkedAbortController = require("linked-abort-controller");
|
|
6
6
|
const mobx = require("mobx");
|
|
7
7
|
const pathToRegexp = require("path-to-regexp");
|
|
8
|
+
const mobx$1 = require("yummies/mobx");
|
|
8
9
|
const common = require("yummies/common");
|
|
9
|
-
let localHistory;
|
|
10
10
|
const routeConfig = complex.createGlobalDynamicConfig(
|
|
11
|
-
(update) => {
|
|
12
|
-
if (localHistory && update?.history && mobxLocationHistory.isObservableHistory(localHistory)) {
|
|
13
|
-
localHistory.destroy();
|
|
14
|
-
}
|
|
11
|
+
(update, current) => {
|
|
15
12
|
let history;
|
|
13
|
+
let queryParams;
|
|
16
14
|
if (update?.history) {
|
|
17
15
|
history = update.history;
|
|
18
|
-
|
|
19
|
-
history
|
|
20
|
-
|
|
21
|
-
let queryParams;
|
|
22
|
-
if (update?.history && !update.queryParams) {
|
|
23
|
-
queryParams = new mobxLocationHistory.QueryParams({ history });
|
|
24
|
-
} else {
|
|
25
|
-
if (update?.queryParams) {
|
|
26
|
-
queryParams = update.queryParams;
|
|
27
|
-
} else {
|
|
28
|
-
queryParams = new mobxLocationHistory.QueryParams({ history });
|
|
16
|
+
queryParams = update.queryParams;
|
|
17
|
+
if (current?.history && mobxLocationHistory.isObservableHistory(current.history)) {
|
|
18
|
+
current.history.destroy();
|
|
29
19
|
}
|
|
20
|
+
} else if (current?.history) {
|
|
21
|
+
history = current.history;
|
|
22
|
+
queryParams = update?.queryParams ?? current.queryParams;
|
|
23
|
+
} else {
|
|
24
|
+
history = mobxLocationHistory.createBrowserHistory();
|
|
30
25
|
}
|
|
26
|
+
queryParams ??= mobxLocationHistory.createQueryParams({ history });
|
|
31
27
|
return {
|
|
32
28
|
...update,
|
|
33
29
|
history,
|
|
34
|
-
location,
|
|
35
30
|
queryParams
|
|
36
31
|
};
|
|
37
32
|
},
|
|
38
33
|
Symbol.for("MOBX_ROUTE_CONFIG")
|
|
39
34
|
);
|
|
35
|
+
const annotations$3 = [
|
|
36
|
+
[
|
|
37
|
+
mobx.computed,
|
|
38
|
+
"isPathMatched",
|
|
39
|
+
"isOpened",
|
|
40
|
+
"isOpening",
|
|
41
|
+
"path",
|
|
42
|
+
"hasOpenedChildren",
|
|
43
|
+
"isAbleToMergeQuery",
|
|
44
|
+
"baseUrl"
|
|
45
|
+
],
|
|
46
|
+
[mobx.computed.struct, "parsedPathData", "params"],
|
|
47
|
+
[mobx.observable, "children"],
|
|
48
|
+
[mobx.observable.ref, "parent", "status"]
|
|
49
|
+
];
|
|
40
50
|
class Route {
|
|
41
|
-
constructor(
|
|
42
|
-
this.
|
|
51
|
+
constructor(pathDeclaration, config = {}) {
|
|
52
|
+
this.pathDeclaration = pathDeclaration;
|
|
43
53
|
this.config = config;
|
|
44
54
|
this.abortController = new linkedAbortController.LinkedAbortController(config.abortSignal);
|
|
45
55
|
this.history = config.history ?? routeConfig.get().history;
|
|
@@ -49,23 +59,7 @@ class Route {
|
|
|
49
59
|
this.meta = this.config.meta;
|
|
50
60
|
this.status = "unknown";
|
|
51
61
|
this.parent = config.parent ?? null;
|
|
52
|
-
mobx.
|
|
53
|
-
mobx.computed(this, "isOpened");
|
|
54
|
-
mobx.computed.struct(this, "data");
|
|
55
|
-
mobx.computed.struct(this, "params");
|
|
56
|
-
mobx.computed(this, "currentPath");
|
|
57
|
-
mobx.computed(this, "hasOpenedChildren");
|
|
58
|
-
mobx.computed(this, "isAbleToMergeQuery");
|
|
59
|
-
mobx.computed(this, "baseUrl");
|
|
60
|
-
mobx.observable(this, "children");
|
|
61
|
-
mobx.observable.ref(this, "parent");
|
|
62
|
-
mobx.observable.ref(this, "status");
|
|
63
|
-
mobx.computed(this, "isOpening");
|
|
64
|
-
mobx.action(this, "addChildren");
|
|
65
|
-
mobx.action(this, "confirmOpening");
|
|
66
|
-
mobx.action(this, "confirmClosing");
|
|
67
|
-
mobx.action(this, "removeChildren");
|
|
68
|
-
mobx.makeObservable(this);
|
|
62
|
+
mobx$1.applyObservable(this, annotations$3);
|
|
69
63
|
mobx.reaction(() => this.isPathMatched, this.checkPathMatch, {
|
|
70
64
|
signal: this.abortController.signal,
|
|
71
65
|
fireImmediately: true
|
|
@@ -78,19 +72,19 @@ class Route {
|
|
|
78
72
|
_tokenData;
|
|
79
73
|
_matcher;
|
|
80
74
|
_compiler;
|
|
81
|
-
|
|
75
|
+
ignoreOpenByPathMatch = false;
|
|
82
76
|
status;
|
|
83
77
|
meta;
|
|
84
78
|
/**
|
|
85
79
|
* Indicates if this route is an index route. Index routes activate when parent route path matches exactly.
|
|
86
80
|
*
|
|
87
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#isindex
|
|
81
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#isindex)
|
|
88
82
|
*/
|
|
89
83
|
isIndex;
|
|
90
84
|
/**
|
|
91
85
|
* Indicates if this route is an hash route.
|
|
92
86
|
*
|
|
93
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#ishash
|
|
87
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#ishash)
|
|
94
88
|
*/
|
|
95
89
|
isHash;
|
|
96
90
|
children = [];
|
|
@@ -111,7 +105,7 @@ class Route {
|
|
|
111
105
|
}
|
|
112
106
|
pathnameToCheck = pathnameToCheck.replace(this.baseUrl, "");
|
|
113
107
|
}
|
|
114
|
-
if ((this.
|
|
108
|
+
if ((this.pathDeclaration === "" || this.pathDeclaration === "/") && (pathnameToCheck === "/" || pathnameToCheck === "")) {
|
|
115
109
|
return { params: {}, path: pathnameToCheck };
|
|
116
110
|
}
|
|
117
111
|
this._matcher ??= pathToRegexp.match(this.tokenData, {
|
|
@@ -124,21 +118,24 @@ class Route {
|
|
|
124
118
|
}
|
|
125
119
|
return parsed;
|
|
126
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#isopening)
|
|
123
|
+
*/
|
|
127
124
|
get isOpening() {
|
|
128
125
|
return this.status === "opening";
|
|
129
126
|
}
|
|
130
127
|
/**
|
|
131
128
|
* Matched path segment for current URL.
|
|
132
129
|
*
|
|
133
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#
|
|
130
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#path)
|
|
134
131
|
*/
|
|
135
|
-
get
|
|
132
|
+
get path() {
|
|
136
133
|
return this.parsedPathData?.path ?? null;
|
|
137
134
|
}
|
|
138
135
|
/**
|
|
139
136
|
* Current parsed path parameters.
|
|
140
137
|
*
|
|
141
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#params
|
|
138
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#params)
|
|
142
139
|
*/
|
|
143
140
|
get params() {
|
|
144
141
|
if (!this.parsedPathData?.params) {
|
|
@@ -164,22 +161,25 @@ class Route {
|
|
|
164
161
|
/**
|
|
165
162
|
* Defines the "open" state for this route.
|
|
166
163
|
*
|
|
167
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#isopened
|
|
164
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#isopened)
|
|
168
165
|
*/
|
|
169
166
|
get isOpened() {
|
|
170
167
|
if (!this.isPathMatched || this.params === null || this.status !== "open-confirmed") {
|
|
171
168
|
return false;
|
|
172
169
|
}
|
|
173
|
-
return
|
|
170
|
+
return (
|
|
171
|
+
// this.parsedPathData is defined because this.params !== null
|
|
172
|
+
!this.config.checkOpened || this.config.checkOpened(this.parsedPathData)
|
|
173
|
+
);
|
|
174
174
|
}
|
|
175
175
|
/**
|
|
176
176
|
* Allows to create child route based on this route with merging this route path and extending path.
|
|
177
177
|
*
|
|
178
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#extend
|
|
178
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#extend)
|
|
179
179
|
*/
|
|
180
|
-
extend(
|
|
180
|
+
extend(pathDeclaration, config) {
|
|
181
181
|
const { index, params, exact, ...configFromCurrentRoute } = this.config;
|
|
182
|
-
const extendedChild = new Route(`${this.
|
|
182
|
+
const extendedChild = new Route(`${this.pathDeclaration}${pathDeclaration}`, {
|
|
183
183
|
...configFromCurrentRoute,
|
|
184
184
|
...config,
|
|
185
185
|
parent: this
|
|
@@ -194,7 +194,7 @@ class Route {
|
|
|
194
194
|
this.children = this.children.filter((child) => !routes.includes(child));
|
|
195
195
|
}
|
|
196
196
|
/**
|
|
197
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#hasopenedchildren
|
|
197
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#hasopenedchildren)
|
|
198
198
|
*/
|
|
199
199
|
get hasOpenedChildren() {
|
|
200
200
|
return this.children.some(
|
|
@@ -239,7 +239,7 @@ class Route {
|
|
|
239
239
|
/**
|
|
240
240
|
* Navigates to this route.
|
|
241
241
|
*
|
|
242
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#open
|
|
242
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/Route.html#open)
|
|
243
243
|
*/
|
|
244
244
|
async open(...args) {
|
|
245
245
|
const {
|
|
@@ -266,47 +266,55 @@ class Route {
|
|
|
266
266
|
state,
|
|
267
267
|
query
|
|
268
268
|
};
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
this.skipPathMatchCheck = true;
|
|
274
|
-
if (trx.replace) {
|
|
275
|
-
this.history.replace(trx.url, trx.state);
|
|
276
|
-
} else {
|
|
277
|
-
this.history.push(trx.url, trx.state);
|
|
269
|
+
if (await this.confirmOpening(trx)) {
|
|
270
|
+
this.ignoreOpenByPathMatch = true;
|
|
278
271
|
}
|
|
279
272
|
}
|
|
280
273
|
get tokenData() {
|
|
281
274
|
if (!this._tokenData) {
|
|
282
|
-
this._tokenData = pathToRegexp.parse(this.
|
|
275
|
+
this._tokenData = pathToRegexp.parse(this.pathDeclaration, this.config.parseOptions);
|
|
283
276
|
}
|
|
284
277
|
return this._tokenData;
|
|
285
278
|
}
|
|
286
279
|
async confirmOpening(trx) {
|
|
287
|
-
|
|
280
|
+
mobx.runInAction(() => {
|
|
281
|
+
this.status = "opening";
|
|
282
|
+
});
|
|
283
|
+
let skipHistoryUpdate = !!trx.preferSkipHistoryUpdate;
|
|
288
284
|
if (this.config.beforeOpen) {
|
|
289
285
|
const feedback = await this.config.beforeOpen(trx);
|
|
290
286
|
if (feedback === false) {
|
|
291
287
|
mobx.runInAction(() => {
|
|
292
288
|
this.status = "open-rejected";
|
|
293
289
|
});
|
|
294
|
-
return false;
|
|
295
290
|
}
|
|
296
291
|
if (typeof feedback === "object") {
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
});
|
|
300
|
-
return Object.assign(trx, feedback);
|
|
292
|
+
skipHistoryUpdate = false;
|
|
293
|
+
Object.assign(trx, feedback);
|
|
301
294
|
}
|
|
302
295
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
}
|
|
296
|
+
if (this.abortController.signal.aborted) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
if (!skipHistoryUpdate) {
|
|
300
|
+
if (trx.replace) {
|
|
301
|
+
this.history.replace(trx.url, trx.state);
|
|
302
|
+
} else {
|
|
303
|
+
this.history.push(trx.url, trx.state);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (this.isPathMatched) {
|
|
307
|
+
mobx.runInAction(() => {
|
|
308
|
+
this.status = "open-confirmed";
|
|
309
|
+
});
|
|
310
|
+
this.config.afterOpen?.(this.parsedPathData, this);
|
|
311
|
+
}
|
|
306
312
|
return true;
|
|
307
313
|
}
|
|
308
314
|
confirmClosing() {
|
|
309
|
-
|
|
315
|
+
mobx.runInAction(() => {
|
|
316
|
+
this.status = "closed";
|
|
317
|
+
});
|
|
310
318
|
return true;
|
|
311
319
|
}
|
|
312
320
|
firstPathMatchingRun = true;
|
|
@@ -317,33 +325,19 @@ class Route {
|
|
|
317
325
|
return;
|
|
318
326
|
}
|
|
319
327
|
}
|
|
320
|
-
if (this.skipPathMatchCheck) {
|
|
321
|
-
this.skipPathMatchCheck = false;
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
328
|
if (isPathMathched) {
|
|
329
|
+
if (this.ignoreOpenByPathMatch) {
|
|
330
|
+
this.ignoreOpenByPathMatch = false;
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
325
333
|
const trx = {
|
|
326
334
|
url: this.parsedPathData.path,
|
|
327
335
|
params: this.parsedPathData.params,
|
|
328
336
|
state: this.history.location.state,
|
|
329
|
-
query: this.query.data
|
|
337
|
+
query: this.query.data,
|
|
338
|
+
preferSkipHistoryUpdate: true
|
|
330
339
|
};
|
|
331
|
-
|
|
332
|
-
if (!nextTrxOrConfirmed) {
|
|
333
|
-
return;
|
|
334
|
-
}
|
|
335
|
-
this.config.afterOpen?.(this.parsedPathData, this);
|
|
336
|
-
if (typeof nextTrxOrConfirmed === "object") {
|
|
337
|
-
if (nextTrxOrConfirmed.replace) {
|
|
338
|
-
this.history.replace(
|
|
339
|
-
nextTrxOrConfirmed.url,
|
|
340
|
-
nextTrxOrConfirmed.state
|
|
341
|
-
);
|
|
342
|
-
} else {
|
|
343
|
-
this.history.push(nextTrxOrConfirmed.url, nextTrxOrConfirmed.state);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
return;
|
|
340
|
+
await this.confirmOpening(trx);
|
|
347
341
|
} else {
|
|
348
342
|
const isConfirmed = this.confirmClosing();
|
|
349
343
|
if (isConfirmed) {
|
|
@@ -359,20 +353,21 @@ class Route {
|
|
|
359
353
|
}
|
|
360
354
|
}
|
|
361
355
|
const createRoute = (path, config) => new Route(path, config);
|
|
356
|
+
const annotations$2 = [
|
|
357
|
+
[mobx.computed, "isOpened", "indexRoute"],
|
|
358
|
+
[mobx.observable.shallow, "routes"]
|
|
359
|
+
];
|
|
362
360
|
class RouteGroup {
|
|
363
361
|
constructor(routes, _indexRoute) {
|
|
364
362
|
this._indexRoute = _indexRoute;
|
|
365
363
|
this.routes = routes;
|
|
366
|
-
mobx.
|
|
367
|
-
mobx.computed.struct(this, "indexRoute");
|
|
368
|
-
mobx.observable.shallow(this, "routes");
|
|
369
|
-
mobx.makeObservable(this);
|
|
364
|
+
mobx$1.applyObservable(this, annotations$2);
|
|
370
365
|
}
|
|
371
366
|
routes;
|
|
372
367
|
/**
|
|
373
368
|
* Returns true if at least one route in the group is open.
|
|
374
369
|
*
|
|
375
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/RouteGroup.html#isopened
|
|
370
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/RouteGroup.html#isopened)
|
|
376
371
|
*/
|
|
377
372
|
get isOpened() {
|
|
378
373
|
const routes = Object.values(this.routes);
|
|
@@ -383,7 +378,7 @@ class RouteGroup {
|
|
|
383
378
|
/**
|
|
384
379
|
* First found index route.
|
|
385
380
|
*
|
|
386
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/RouteGroup.html#indexroute
|
|
381
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/RouteGroup.html#indexroute)
|
|
387
382
|
*/
|
|
388
383
|
get indexRoute() {
|
|
389
384
|
return this._indexRoute ?? Object.values(this.routes).find(
|
|
@@ -393,7 +388,7 @@ class RouteGroup {
|
|
|
393
388
|
/**
|
|
394
389
|
* Main navigation method for the group.
|
|
395
390
|
*
|
|
396
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/RouteGroup.html#open
|
|
391
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/RouteGroup.html#open)
|
|
397
392
|
*/
|
|
398
393
|
open(...args) {
|
|
399
394
|
let lastGroupRoute;
|
|
@@ -417,6 +412,9 @@ class RouteGroup {
|
|
|
417
412
|
}
|
|
418
413
|
}
|
|
419
414
|
const createRouteGroup = (routes, indexRoute) => new RouteGroup(routes, indexRoute);
|
|
415
|
+
const annotations$1 = [
|
|
416
|
+
[mobx.computed.struct, "location"]
|
|
417
|
+
];
|
|
420
418
|
class Router {
|
|
421
419
|
routes;
|
|
422
420
|
history;
|
|
@@ -425,8 +423,7 @@ class Router {
|
|
|
425
423
|
this.routes = config.routes;
|
|
426
424
|
this.history = config.history ?? routeConfig.get().history;
|
|
427
425
|
this.query = config.queryParams ?? routeConfig.get().queryParams;
|
|
428
|
-
mobx.
|
|
429
|
-
mobx.makeObservable(this);
|
|
426
|
+
mobx$1.applyObservable(this, annotations$1);
|
|
430
427
|
}
|
|
431
428
|
get location() {
|
|
432
429
|
return this.history.location;
|
|
@@ -444,6 +441,12 @@ class Router {
|
|
|
444
441
|
}
|
|
445
442
|
const createRouter = (config) => new Router(config);
|
|
446
443
|
const isRouteEntity = (route) => route && "isOpened" in route;
|
|
444
|
+
const annotations = [
|
|
445
|
+
[mobx.observable, "params"],
|
|
446
|
+
[mobx.observable.ref, "status", "trx", "openChecker", "isOuterOpened"],
|
|
447
|
+
[mobx.computed, "isOpened", "isOpening", "isClosing"],
|
|
448
|
+
[mobx.action, "setOpenChecker", "open", "close"]
|
|
449
|
+
];
|
|
447
450
|
class VirtualRoute {
|
|
448
451
|
constructor(config = {}) {
|
|
449
452
|
this.config = config;
|
|
@@ -451,110 +454,156 @@ class VirtualRoute {
|
|
|
451
454
|
this.query = config.queryParams ?? routeConfig.get().queryParams;
|
|
452
455
|
this.params = common.callFunction(config.initialParams, this) ?? null;
|
|
453
456
|
this.openChecker = config.checkOpened;
|
|
454
|
-
this.
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
mobx.
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
(
|
|
469
|
-
|
|
470
|
-
{
|
|
471
|
-
signal: this.abortController.signal,
|
|
472
|
-
fireImmediately: true
|
|
457
|
+
this.skipAutoOpenClose = false;
|
|
458
|
+
this.isOuterOpened = this.openChecker?.(this);
|
|
459
|
+
this.status = this.isOuterOpened ? "opened" : "unknown";
|
|
460
|
+
mobx$1.applyObservable(this, annotations);
|
|
461
|
+
this.abortController.signal.addEventListener(
|
|
462
|
+
"abort",
|
|
463
|
+
mobx.action(() => {
|
|
464
|
+
this.status = "unknown";
|
|
465
|
+
})
|
|
466
|
+
);
|
|
467
|
+
mobx.reaction(
|
|
468
|
+
() => this.openChecker?.(this),
|
|
469
|
+
mobx.action((isOuterOpened) => {
|
|
470
|
+
this.isOuterOpened = isOuterOpened;
|
|
471
|
+
if (this.skipAutoOpenClose || this.status === "closing" || this.status === "opening") {
|
|
472
|
+
return;
|
|
473
473
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
474
|
+
if (this.isOuterOpened) {
|
|
475
|
+
if (this.status === "opened") {
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
this.confirmOpening({
|
|
479
|
+
params: this.params ?? null,
|
|
480
|
+
...this.config.getAutomatedOpenParams?.(this)
|
|
481
|
+
});
|
|
482
|
+
} else {
|
|
483
|
+
if (this.status === "closed" || this.status === "unknown") {
|
|
484
|
+
return;
|
|
485
|
+
}
|
|
486
|
+
this.confirmClosing();
|
|
487
|
+
}
|
|
488
|
+
}),
|
|
489
|
+
{ signal: this.abortController.signal, fireImmediately: true }
|
|
490
|
+
);
|
|
491
|
+
if (this.status === "opened") {
|
|
492
|
+
this.config.afterOpen?.(this.params, this);
|
|
493
|
+
}
|
|
480
494
|
}
|
|
481
|
-
abortController;
|
|
482
495
|
query;
|
|
483
496
|
params;
|
|
484
|
-
|
|
497
|
+
abortController;
|
|
498
|
+
status;
|
|
485
499
|
openChecker;
|
|
486
|
-
|
|
500
|
+
trx;
|
|
501
|
+
skipAutoOpenClose;
|
|
502
|
+
/**
|
|
503
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/VirtualRoute.html#isouteropened)
|
|
504
|
+
*/
|
|
505
|
+
isOuterOpened;
|
|
487
506
|
/**
|
|
488
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/VirtualRoute.html#isopened
|
|
507
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/VirtualRoute.html#isopened)
|
|
489
508
|
*/
|
|
490
509
|
get isOpened() {
|
|
491
|
-
|
|
492
|
-
|
|
510
|
+
return this.status === "opened" && this.isOuterOpened !== false;
|
|
511
|
+
}
|
|
512
|
+
/**
|
|
513
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/VirtualRoute.html#isopening)
|
|
514
|
+
*/
|
|
515
|
+
get isOpening() {
|
|
516
|
+
return this.status === "opening";
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/VirtualRoute.html#isclosing)
|
|
520
|
+
*/
|
|
521
|
+
get isClosing() {
|
|
522
|
+
return this.status === "closing";
|
|
493
523
|
}
|
|
494
524
|
/**
|
|
495
|
-
* [**Documentation**](https://js2me.github.io/mobx-route/core/VirtualRoute.html#setopenchecker
|
|
525
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/VirtualRoute.html#setopenchecker)
|
|
496
526
|
*/
|
|
497
527
|
setOpenChecker(openChecker) {
|
|
498
528
|
this.openChecker = openChecker;
|
|
499
529
|
}
|
|
500
530
|
async open(...args) {
|
|
501
|
-
const params = args[0] ??
|
|
502
|
-
const
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
}
|
|
509
|
-
|
|
531
|
+
const params = args[0] ?? null;
|
|
532
|
+
const extra = args[1];
|
|
533
|
+
this.skipAutoOpenClose = true;
|
|
534
|
+
this.trx = {
|
|
535
|
+
params,
|
|
536
|
+
extra,
|
|
537
|
+
manual: true
|
|
538
|
+
};
|
|
539
|
+
await this.confirmOpening(this.trx);
|
|
540
|
+
this.skipAutoOpenClose = false;
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* [**Documentation**](https://js2me.github.io/mobx-route/core/VirtualRoute.html#close)
|
|
544
|
+
*/
|
|
545
|
+
async close() {
|
|
546
|
+
this.skipAutoOpenClose = true;
|
|
547
|
+
const result = await this.confirmClosing();
|
|
548
|
+
this.skipAutoOpenClose = false;
|
|
549
|
+
return result;
|
|
550
|
+
}
|
|
551
|
+
async confirmOpening(trx) {
|
|
552
|
+
mobx.runInAction(() => {
|
|
553
|
+
this.trx = void 0;
|
|
554
|
+
this.status = "opening";
|
|
555
|
+
});
|
|
556
|
+
if (await this.config.beforeOpen?.(trx.params, this) === false) {
|
|
510
557
|
mobx.runInAction(() => {
|
|
511
|
-
this.
|
|
558
|
+
this.status = "open-rejected";
|
|
559
|
+
this.trx = void 0;
|
|
512
560
|
});
|
|
513
|
-
|
|
514
|
-
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
if (await this.config.open?.(trx.params, this) === false) {
|
|
515
564
|
mobx.runInAction(() => {
|
|
516
|
-
this.
|
|
565
|
+
this.status = "open-rejected";
|
|
566
|
+
this.trx = void 0;
|
|
517
567
|
});
|
|
518
|
-
}
|
|
519
|
-
if (!this.isLocalOpened) {
|
|
520
568
|
return;
|
|
521
569
|
}
|
|
522
|
-
if (extraParams?.query) {
|
|
523
|
-
this.query.update(extraParams.query, extraParams.replace);
|
|
524
|
-
}
|
|
525
570
|
mobx.runInAction(() => {
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
571
|
+
if (trx.extra?.query) {
|
|
572
|
+
this.query.update(trx.extra.query, trx.extra.replace);
|
|
573
|
+
}
|
|
574
|
+
this.trx = void 0;
|
|
575
|
+
this.params = trx.params;
|
|
576
|
+
this.status = "opened";
|
|
529
577
|
this.config.afterOpen?.(this.params, this);
|
|
530
|
-
}
|
|
578
|
+
});
|
|
579
|
+
return true;
|
|
531
580
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
close() {
|
|
536
|
-
if (this.config.close == null) {
|
|
537
|
-
this.isLocalOpened = false;
|
|
538
|
-
} else {
|
|
539
|
-
const result = this.config.close(this);
|
|
540
|
-
this.isLocalOpened = result !== false;
|
|
581
|
+
async confirmClosing() {
|
|
582
|
+
if (this.status === "closed") {
|
|
583
|
+
return true;
|
|
541
584
|
}
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
if (this.
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
585
|
+
const lastStatus = this.status;
|
|
586
|
+
mobx.runInAction(() => {
|
|
587
|
+
this.status = "closing";
|
|
588
|
+
});
|
|
589
|
+
if (await this.config.beforeClose?.() === false) {
|
|
590
|
+
mobx.runInAction(() => {
|
|
591
|
+
this.status = lastStatus;
|
|
592
|
+
});
|
|
593
|
+
return;
|
|
551
594
|
}
|
|
552
|
-
if (
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
595
|
+
if (this.config.close?.(this) === false) {
|
|
596
|
+
mobx.runInAction(() => {
|
|
597
|
+
this.status = lastStatus;
|
|
598
|
+
});
|
|
599
|
+
return;
|
|
556
600
|
}
|
|
557
|
-
|
|
601
|
+
mobx.runInAction(() => {
|
|
602
|
+
this.status = "closed";
|
|
603
|
+
this.params = null;
|
|
604
|
+
});
|
|
605
|
+
return true;
|
|
606
|
+
}
|
|
558
607
|
destroy() {
|
|
559
608
|
this.abortController.abort();
|
|
560
609
|
}
|