mobx-route 0.0.20 → 0.0.22
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/README.md
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
[bundlephobia-image]: https://badgen.net/bundlephobia/minzip/mobx-route
|
|
17
17
|
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
_Uses [`path-to-regexp` power](https://www.npmjs.com/package/path-to-regexp)_
|
|
20
20
|
|
|
21
21
|
|
|
22
22
|
### Documentation: [js2me.github.io/mobx-route](https://js2me.github.io/mobx-route)
|
package/core/route/route.d.ts
CHANGED
|
@@ -12,16 +12,16 @@ export declare class Route<TPath extends string, TParentRoute extends Route<any,
|
|
|
12
12
|
private _tokenData;
|
|
13
13
|
private _matcher?;
|
|
14
14
|
private _compiler?;
|
|
15
|
+
isIndex: boolean;
|
|
15
16
|
children: AnyRoute[];
|
|
16
17
|
constructor(path: TPath, config?: RouteConfiguration<TParentRoute>);
|
|
17
18
|
protected get data(): RouteMatchesData<TPath> | null;
|
|
18
19
|
get currentPath(): string | null;
|
|
19
20
|
get params(): ParsedPathParams<TPath> | null;
|
|
20
21
|
get isOpened(): boolean;
|
|
21
|
-
get isIndex(): boolean;
|
|
22
22
|
extend<TExtendPath extends string>(path: TExtendPath, config?: Omit<RouteConfiguration<any>, 'parent'>): Route<`${TPath}${TExtendPath}`, this>;
|
|
23
|
-
addChildren(...
|
|
24
|
-
removeChildren(...
|
|
23
|
+
addChildren(...routes: AnyRoute[]): void;
|
|
24
|
+
removeChildren(...routes: AnyRoute[]): void;
|
|
25
25
|
get hasOpenedChildren(): boolean;
|
|
26
26
|
protected processParams(params?: ExtractPathParams<TPath> | null | undefined): ParamData | undefined;
|
|
27
27
|
createUrl(...args: AllPropertiesOptional<ExtractPathParams<TPath>> extends true ? [params?: Maybe<ExtractPathParams<TPath>>, query?: AnyObject] : [params: ExtractPathParams<TPath>, query?: AnyObject]): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/core/route/route.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,YAAY,EACZ,aAAa,EACb,YAAY,EACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAkB,SAAS,EAAS,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAI9E,OAAO,EACL,QAAQ,EACR,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAE1B,qBAAa,KAAK,CAChB,KAAK,SAAS,MAAM,EACpB,YAAY,SAAS,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI;
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/core/route/route.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,YAAY,EACZ,aAAa,EACb,YAAY,EACb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAkB,SAAS,EAAS,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAI9E,OAAO,EACL,QAAQ,EACR,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAE1B,qBAAa,KAAK,CAChB,KAAK,SAAS,MAAM,EACpB,YAAY,SAAS,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI;IAiBzC,IAAI,EAAE,KAAK;IAClB,SAAS,CAAC,MAAM,EAAE,kBAAkB,CAAC,YAAY,CAAC;IAhBpD,SAAS,CAAC,OAAO,EAAE,YAAY,CAAC;IAChC,SAAS,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E,KAAK,CAAC,EAAE,SAAS,CAAC;IAiB3D,IAAI,CACF,GAAG,IAAI,EAAE,qBAAqB,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,SAAS,IAAI,GACjE;QACE,MAAM,CAAC,EAAE,iBAAiB,CAAC,KAAK,CAAC,GAAG,IAAI,GAAG,SAAS;QACpD,cAAc,CAAC,EAAE,mBAAmB;KACrC,GACD,CAAC,MAAM,EAAE,iBAAiB,CAAC,KAAK,CAAC,EAAE,cAAc,CAAC,EAAE,mBAAmB,CAAC,GAC3E,IAAI;IAEP,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,mBAAmB,GAAG,IAAI;IAc7D,SAAS,KAAK,SAAS,cAKtB;CACF"}
|
package/core/route/route.js
CHANGED
|
@@ -12,6 +12,7 @@ export class Route {
|
|
|
12
12
|
_tokenData;
|
|
13
13
|
_matcher;
|
|
14
14
|
_compiler;
|
|
15
|
+
isIndex;
|
|
15
16
|
children = [];
|
|
16
17
|
constructor(path, config = {}) {
|
|
17
18
|
this.path = path;
|
|
@@ -21,6 +22,7 @@ export class Route {
|
|
|
21
22
|
this.query = config.queryParams ?? routeConfig.get().queryParams;
|
|
22
23
|
const usedBaseUrl = this.config.baseUrl ?? routeConfig.get().baseUrl;
|
|
23
24
|
this.baseUrl = !usedBaseUrl || usedBaseUrl === '/' ? '' : usedBaseUrl;
|
|
25
|
+
this.isIndex = !!this.config.index;
|
|
24
26
|
computed.struct(this, 'isOpened');
|
|
25
27
|
computed.struct(this, 'data');
|
|
26
28
|
computed.struct(this, 'params');
|
|
@@ -59,23 +61,22 @@ export class Route {
|
|
|
59
61
|
get isOpened() {
|
|
60
62
|
return this.data !== null;
|
|
61
63
|
}
|
|
62
|
-
get isIndex() {
|
|
63
|
-
return !!this.config.index;
|
|
64
|
-
}
|
|
65
64
|
extend(path, config) {
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
66
|
+
const { index, ...configFromCurrentRoute } = this.config;
|
|
66
67
|
const extendedChild = new Route(`${this.path}${path}`, {
|
|
67
|
-
...
|
|
68
|
+
...configFromCurrentRoute,
|
|
68
69
|
...config,
|
|
69
70
|
parent: this,
|
|
70
71
|
});
|
|
71
72
|
this.addChildren(extendedChild);
|
|
72
73
|
return extendedChild;
|
|
73
74
|
}
|
|
74
|
-
addChildren(...
|
|
75
|
-
this.children.push(...
|
|
75
|
+
addChildren(...routes) {
|
|
76
|
+
this.children.push(...routes);
|
|
76
77
|
}
|
|
77
|
-
removeChildren(...
|
|
78
|
-
this.children = this.children.filter((child) => !
|
|
78
|
+
removeChildren(...routes) {
|
|
79
|
+
this.children = this.children.filter((child) => !routes.includes(child));
|
|
79
80
|
}
|
|
80
81
|
get hasOpenedChildren() {
|
|
81
82
|
return this.children.some((child) => child.isOpened);
|
|
@@ -26,17 +26,18 @@ export class VirtualRoute {
|
|
|
26
26
|
this.checkOpened = checkOpened;
|
|
27
27
|
}
|
|
28
28
|
open(...args) {
|
|
29
|
-
if (this.config.open != null) {
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
31
|
-
// @ts-ignore
|
|
32
|
-
this.checkOpened = this.config.open(...args);
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
29
|
this.params = args[0] ?? {};
|
|
36
30
|
if (args[1] != null) {
|
|
37
31
|
this.query.update(args[1]);
|
|
38
32
|
}
|
|
39
|
-
this.
|
|
33
|
+
if (this.config.open == null) {
|
|
34
|
+
this.checkOpened = true;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
38
|
+
// @ts-ignore
|
|
39
|
+
this.checkOpened = this.config.open(...args);
|
|
40
|
+
}
|
|
40
41
|
}
|
|
41
42
|
close() {
|
|
42
43
|
if (this.config.close != null) {
|