mobx-route 2.1.2 → 2.1.3
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/package.json +2 -2
- package/view-model.cjs +5 -1
- package/view-model.cjs.map +1 -1
- package/view-model.js +6 -2
- package/view-model.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mobx-route",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"mobx",
|
|
6
6
|
"react",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"mobx": "^6.12.4",
|
|
31
31
|
"mobx-react-lite": "^4.0.7",
|
|
32
|
-
"mobx-view-model": "^8.10.0 || ^9.0.0 || ^10.0.0",
|
|
32
|
+
"mobx-view-model": "^8.10.0 || ^9.0.0 || ^10.0.0 || ^11.0.0",
|
|
33
33
|
"react": "^18.0.0 || ^19.0.0",
|
|
34
34
|
"react-dom": "^18.0.0 || ^19.0.0"
|
|
35
35
|
},
|
package/view-model.cjs
CHANGED
|
@@ -22,7 +22,11 @@ function withRoute(route) {
|
|
|
22
22
|
_lastPayload = {};
|
|
23
23
|
constructor(...args) {
|
|
24
24
|
super(...args);
|
|
25
|
-
|
|
25
|
+
const observableConfig = this.vmConfig?.observable?.viewModels ?? {
|
|
26
|
+
...mobxViewModel.viewModelsConfig.observable.viewModels,
|
|
27
|
+
...args[0]?.vmConfig?.observable?.viewModels
|
|
28
|
+
};
|
|
29
|
+
mobxViewModel.applyObservable(this, annotations, observableConfig);
|
|
26
30
|
}
|
|
27
31
|
/**
|
|
28
32
|
* Current route params with fallback to the last cached value.
|
package/view-model.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view-model.cjs","sources":["../src/view-model/route-view-model.ts"],"sourcesContent":["import { computed } from 'mobx';\nimport type { IQueryParams } from 'mobx-location-history';\nimport {\n applyObservable,\n type ViewModel,\n ViewModelBase,\n} from 'mobx-view-model';\nimport type { ObservableAnnotationsArray } from 'yummies/mobx';\nimport type { Class } from 'yummies/types';\nimport {\n type AnyAbstractRouteEntity,\n type RouteParams,\n routeConfig,\n} from '../core/index.js';\n\nconst annotations: ObservableAnnotationsArray<any> = [\n [computed.struct, 'pathParams'],\n [computed, 'query'],\n];\n\n/**\n * Public interface added by `withRouteViewModel` mixin.\n */\ntype RouteViewModelMixinPublic<TRoute extends AnyAbstractRouteEntity> = {\n readonly route: TRoute;\n _lastPayload: RouteParams<TRoute>;\n payload: RouteParams<TRoute>;\n query: IQueryParams;\n pathParams: RouteParams<TRoute>;\n isMounted: boolean;\n};\n\n/**\n * Mixin function that enhances any `ViewModelBase` subclass with route-related properties.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel)\n *\n * @param route - Route entity to bind to the view model.\n * @returns A class enhancer that takes a base class and returns a new class with route properties.\n *\n * @example\n * ```ts\n * // With ViewModelBase directly\n * class MyVM extends withRoute(someRoute)(ViewModelBase) {}\n *\n * // With a custom base class\n * class ProductPageVM extends withRoute(productRoute)(AppVM) {}\n * ```\n */\nexport function withRoute<TRoute extends AnyAbstractRouteEntity>(\n route: TRoute,\n) {\n return <TBase extends Class<ViewModel<any, any>>>(\n Base: TBase,\n ): TBase & Class<InstanceType<TBase> & RouteViewModelMixinPublic<TRoute>> => {\n class RouteViewModelMixin extends Base {\n /**\n * Route entity bound to this view model.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel#route)\n */\n readonly route: TRoute = route;\n\n /**\n * Caches the latest known route params.\n */\n _lastPayload: RouteParams<TRoute> = {} as RouteParams<TRoute>;\n\n constructor(...args: any[]) {\n super(...args);\n\n
|
|
1
|
+
{"version":3,"file":"view-model.cjs","sources":["../src/view-model/route-view-model.ts"],"sourcesContent":["import { computed } from 'mobx';\nimport type { IQueryParams } from 'mobx-location-history';\nimport {\n applyObservable,\n type ViewModel,\n ViewModelBase,\n viewModelsConfig,\n} from 'mobx-view-model';\nimport type { ObservableAnnotationsArray } from 'yummies/mobx';\nimport type { Class } from 'yummies/types';\nimport {\n type AnyAbstractRouteEntity,\n type RouteParams,\n routeConfig,\n} from '../core/index.js';\n\nconst annotations: ObservableAnnotationsArray<any> = [\n [computed.struct, 'pathParams'],\n [computed, 'query'],\n];\n\n/**\n * Public interface added by `withRouteViewModel` mixin.\n */\ntype RouteViewModelMixinPublic<TRoute extends AnyAbstractRouteEntity> = {\n readonly route: TRoute;\n _lastPayload: RouteParams<TRoute>;\n payload: RouteParams<TRoute>;\n query: IQueryParams;\n pathParams: RouteParams<TRoute>;\n isMounted: boolean;\n};\n\n/**\n * Mixin function that enhances any `ViewModelBase` subclass with route-related properties.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel)\n *\n * @param route - Route entity to bind to the view model.\n * @returns A class enhancer that takes a base class and returns a new class with route properties.\n *\n * @example\n * ```ts\n * // With ViewModelBase directly\n * class MyVM extends withRoute(someRoute)(ViewModelBase) {}\n *\n * // With a custom base class\n * class ProductPageVM extends withRoute(productRoute)(AppVM) {}\n * ```\n */\nexport function withRoute<TRoute extends AnyAbstractRouteEntity>(\n route: TRoute,\n) {\n return <TBase extends Class<ViewModel<any, any>>>(\n Base: TBase,\n ): TBase & Class<InstanceType<TBase> & RouteViewModelMixinPublic<TRoute>> => {\n class RouteViewModelMixin extends Base {\n /**\n * Route entity bound to this view model.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel#route)\n */\n readonly route: TRoute = route;\n\n /**\n * Caches the latest known route params.\n */\n _lastPayload: RouteParams<TRoute> = {} as RouteParams<TRoute>;\n\n constructor(...args: any[]) {\n super(...args);\n\n // v11 keeps vmConfig internal; the exported config supplies its defaults.\n const observableConfig = (this as any).vmConfig?.observable\n ?.viewModels ?? {\n ...viewModelsConfig.observable.viewModels,\n ...args[0]?.vmConfig?.observable?.viewModels,\n };\n\n applyObservable(this, annotations, observableConfig);\n }\n\n /**\n * Current route params with fallback to the last cached value.\n */\n override get payload(): RouteParams<TRoute> {\n if ('params' in this.route && this.route.params != null) {\n this._lastPayload = this.route.params as RouteParams<TRoute>;\n }\n\n return this._lastPayload;\n }\n\n /**\n * Current query params from route or global route config.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel#query)\n */\n get query(): IQueryParams {\n if ('query' in this.route) {\n return this.route.query as IQueryParams;\n }\n\n return routeConfig.get().queryParams;\n }\n\n /**\n * Alias for `payload`.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel#pathparams)\n */\n get pathParams() {\n return this.payload;\n }\n\n /**\n * Mounted state including the route opened status.\n */\n override get isMounted() {\n return super.isMounted && this.route.isOpened;\n }\n }\n\n return RouteViewModelMixin as any;\n };\n}\n\n/**\n * Base class created by the mixin with a dummy route.\n * Used internally by `RouteViewModel` to avoid duplicating the mixin logic.\n */\nconst _RouteViewModelBase = withRoute({} as any)(ViewModelBase);\n\n/**\n * Abstract route-aware view model that extends `ViewModelBase<EmptyObject>`.\n *\n * Provides `route`, `payload`, `pathParams`, `query`, and `isMounted` properties.\n * Subclasses must declare `route = someRoute`.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel)\n *\n * @example\n * ```ts\n * class MyVM extends RouteViewModel<typeof myRoute> {\n * route = myRoute;\n * }\n * ```\n */\nexport abstract class RouteViewModel<\n TRoute extends AnyAbstractRouteEntity = AnyAbstractRouteEntity,\n> extends _RouteViewModelBase {\n abstract override readonly route: TRoute;\n}\n"],"names":["computed","viewModelsConfig","applyObservable","routeConfig","ViewModelBase"],"mappings":";;;;;AAgBA,MAAM,cAA+C;AAAA,EACnD,CAACA,KAAAA,SAAS,QAAQ,YAAY;AAAA,EAC9B,CAACA,KAAAA,UAAU,OAAO;AACpB;AA+BO,SAAS,UACd,OACA;AACA,SAAO,CACL,SAC2E;AAAA,IAC3E,MAAM,4BAA4B,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAM5B,QAAgB;AAAA;AAAA;AAAA;AAAA,MAKzB,eAAoC,CAAA;AAAA,MAEpC,eAAe,MAAa;AAC1B,cAAM,GAAG,IAAI;AAGb,cAAM,mBAAoB,KAAa,UAAU,YAC7C,cAAc;AAAA,UAChB,GAAGC,cAAAA,iBAAiB,WAAW;AAAA,UAC/B,GAAG,KAAK,CAAC,GAAG,UAAU,YAAY;AAAA,QAAA;AAGpCC,sCAAgB,MAAM,aAAa,gBAAgB;AAAA,MACrD;AAAA;AAAA;AAAA;AAAA,MAKA,IAAa,UAA+B;AAC1C,YAAI,YAAY,KAAK,SAAS,KAAK,MAAM,UAAU,MAAM;AACvD,eAAK,eAAe,KAAK,MAAM;AAAA,QACjC;AAEA,eAAO,KAAK;AAAA,MACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOA,IAAI,QAAsB;AACxB,YAAI,WAAW,KAAK,OAAO;AACzB,iBAAO,KAAK,MAAM;AAAA,QACpB;AAEA,eAAOC,aAAAA,YAAY,MAAM;AAAA,MAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOA,IAAI,aAAa;AACf,eAAO,KAAK;AAAA,MACd;AAAA;AAAA;AAAA;AAAA,MAKA,IAAa,YAAY;AACvB,eAAO,MAAM,aAAa,KAAK,MAAM;AAAA,MACvC;AAAA,IAAA;AAGF,WAAO;AAAA,EACT;AACF;AAMA,MAAM,sBAAsB,UAAU,EAAS,EAAEC,2BAAa;AAiBvD,MAAe,uBAEZ,oBAAoB;AAE9B;;;"}
|
package/view-model.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { computed } from "mobx";
|
|
2
|
-
import { ViewModelBase, applyObservable } from "mobx-view-model";
|
|
2
|
+
import { ViewModelBase, viewModelsConfig, applyObservable } from "mobx-view-model";
|
|
3
3
|
import { r as routeConfig } from "./virtual-route-C3nG6mQb.js";
|
|
4
4
|
const annotations = [
|
|
5
5
|
[computed.struct, "pathParams"],
|
|
@@ -20,7 +20,11 @@ function withRoute(route) {
|
|
|
20
20
|
_lastPayload = {};
|
|
21
21
|
constructor(...args) {
|
|
22
22
|
super(...args);
|
|
23
|
-
|
|
23
|
+
const observableConfig = this.vmConfig?.observable?.viewModels ?? {
|
|
24
|
+
...viewModelsConfig.observable.viewModels,
|
|
25
|
+
...args[0]?.vmConfig?.observable?.viewModels
|
|
26
|
+
};
|
|
27
|
+
applyObservable(this, annotations, observableConfig);
|
|
24
28
|
}
|
|
25
29
|
/**
|
|
26
30
|
* Current route params with fallback to the last cached value.
|
package/view-model.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view-model.js","sources":["../src/view-model/route-view-model.ts"],"sourcesContent":["import { computed } from 'mobx';\nimport type { IQueryParams } from 'mobx-location-history';\nimport {\n applyObservable,\n type ViewModel,\n ViewModelBase,\n} from 'mobx-view-model';\nimport type { ObservableAnnotationsArray } from 'yummies/mobx';\nimport type { Class } from 'yummies/types';\nimport {\n type AnyAbstractRouteEntity,\n type RouteParams,\n routeConfig,\n} from '../core/index.js';\n\nconst annotations: ObservableAnnotationsArray<any> = [\n [computed.struct, 'pathParams'],\n [computed, 'query'],\n];\n\n/**\n * Public interface added by `withRouteViewModel` mixin.\n */\ntype RouteViewModelMixinPublic<TRoute extends AnyAbstractRouteEntity> = {\n readonly route: TRoute;\n _lastPayload: RouteParams<TRoute>;\n payload: RouteParams<TRoute>;\n query: IQueryParams;\n pathParams: RouteParams<TRoute>;\n isMounted: boolean;\n};\n\n/**\n * Mixin function that enhances any `ViewModelBase` subclass with route-related properties.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel)\n *\n * @param route - Route entity to bind to the view model.\n * @returns A class enhancer that takes a base class and returns a new class with route properties.\n *\n * @example\n * ```ts\n * // With ViewModelBase directly\n * class MyVM extends withRoute(someRoute)(ViewModelBase) {}\n *\n * // With a custom base class\n * class ProductPageVM extends withRoute(productRoute)(AppVM) {}\n * ```\n */\nexport function withRoute<TRoute extends AnyAbstractRouteEntity>(\n route: TRoute,\n) {\n return <TBase extends Class<ViewModel<any, any>>>(\n Base: TBase,\n ): TBase & Class<InstanceType<TBase> & RouteViewModelMixinPublic<TRoute>> => {\n class RouteViewModelMixin extends Base {\n /**\n * Route entity bound to this view model.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel#route)\n */\n readonly route: TRoute = route;\n\n /**\n * Caches the latest known route params.\n */\n _lastPayload: RouteParams<TRoute> = {} as RouteParams<TRoute>;\n\n constructor(...args: any[]) {\n super(...args);\n\n
|
|
1
|
+
{"version":3,"file":"view-model.js","sources":["../src/view-model/route-view-model.ts"],"sourcesContent":["import { computed } from 'mobx';\nimport type { IQueryParams } from 'mobx-location-history';\nimport {\n applyObservable,\n type ViewModel,\n ViewModelBase,\n viewModelsConfig,\n} from 'mobx-view-model';\nimport type { ObservableAnnotationsArray } from 'yummies/mobx';\nimport type { Class } from 'yummies/types';\nimport {\n type AnyAbstractRouteEntity,\n type RouteParams,\n routeConfig,\n} from '../core/index.js';\n\nconst annotations: ObservableAnnotationsArray<any> = [\n [computed.struct, 'pathParams'],\n [computed, 'query'],\n];\n\n/**\n * Public interface added by `withRouteViewModel` mixin.\n */\ntype RouteViewModelMixinPublic<TRoute extends AnyAbstractRouteEntity> = {\n readonly route: TRoute;\n _lastPayload: RouteParams<TRoute>;\n payload: RouteParams<TRoute>;\n query: IQueryParams;\n pathParams: RouteParams<TRoute>;\n isMounted: boolean;\n};\n\n/**\n * Mixin function that enhances any `ViewModelBase` subclass with route-related properties.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel)\n *\n * @param route - Route entity to bind to the view model.\n * @returns A class enhancer that takes a base class and returns a new class with route properties.\n *\n * @example\n * ```ts\n * // With ViewModelBase directly\n * class MyVM extends withRoute(someRoute)(ViewModelBase) {}\n *\n * // With a custom base class\n * class ProductPageVM extends withRoute(productRoute)(AppVM) {}\n * ```\n */\nexport function withRoute<TRoute extends AnyAbstractRouteEntity>(\n route: TRoute,\n) {\n return <TBase extends Class<ViewModel<any, any>>>(\n Base: TBase,\n ): TBase & Class<InstanceType<TBase> & RouteViewModelMixinPublic<TRoute>> => {\n class RouteViewModelMixin extends Base {\n /**\n * Route entity bound to this view model.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel#route)\n */\n readonly route: TRoute = route;\n\n /**\n * Caches the latest known route params.\n */\n _lastPayload: RouteParams<TRoute> = {} as RouteParams<TRoute>;\n\n constructor(...args: any[]) {\n super(...args);\n\n // v11 keeps vmConfig internal; the exported config supplies its defaults.\n const observableConfig = (this as any).vmConfig?.observable\n ?.viewModels ?? {\n ...viewModelsConfig.observable.viewModels,\n ...args[0]?.vmConfig?.observable?.viewModels,\n };\n\n applyObservable(this, annotations, observableConfig);\n }\n\n /**\n * Current route params with fallback to the last cached value.\n */\n override get payload(): RouteParams<TRoute> {\n if ('params' in this.route && this.route.params != null) {\n this._lastPayload = this.route.params as RouteParams<TRoute>;\n }\n\n return this._lastPayload;\n }\n\n /**\n * Current query params from route or global route config.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel#query)\n */\n get query(): IQueryParams {\n if ('query' in this.route) {\n return this.route.query as IQueryParams;\n }\n\n return routeConfig.get().queryParams;\n }\n\n /**\n * Alias for `payload`.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel#pathparams)\n */\n get pathParams() {\n return this.payload;\n }\n\n /**\n * Mounted state including the route opened status.\n */\n override get isMounted() {\n return super.isMounted && this.route.isOpened;\n }\n }\n\n return RouteViewModelMixin as any;\n };\n}\n\n/**\n * Base class created by the mixin with a dummy route.\n * Used internally by `RouteViewModel` to avoid duplicating the mixin logic.\n */\nconst _RouteViewModelBase = withRoute({} as any)(ViewModelBase);\n\n/**\n * Abstract route-aware view model that extends `ViewModelBase<EmptyObject>`.\n *\n * Provides `route`, `payload`, `pathParams`, `query`, and `isMounted` properties.\n * Subclasses must declare `route = someRoute`.\n *\n * [**Documentation**](https://js2me.github.io/mobx-route/view-model/RouteViewModel)\n *\n * @example\n * ```ts\n * class MyVM extends RouteViewModel<typeof myRoute> {\n * route = myRoute;\n * }\n * ```\n */\nexport abstract class RouteViewModel<\n TRoute extends AnyAbstractRouteEntity = AnyAbstractRouteEntity,\n> extends _RouteViewModelBase {\n abstract override readonly route: TRoute;\n}\n"],"names":[],"mappings":";;;AAgBA,MAAM,cAA+C;AAAA,EACnD,CAAC,SAAS,QAAQ,YAAY;AAAA,EAC9B,CAAC,UAAU,OAAO;AACpB;AA+BO,SAAS,UACd,OACA;AACA,SAAO,CACL,SAC2E;AAAA,IAC3E,MAAM,4BAA4B,KAAK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAM5B,QAAgB;AAAA;AAAA;AAAA;AAAA,MAKzB,eAAoC,CAAA;AAAA,MAEpC,eAAe,MAAa;AAC1B,cAAM,GAAG,IAAI;AAGb,cAAM,mBAAoB,KAAa,UAAU,YAC7C,cAAc;AAAA,UAChB,GAAG,iBAAiB,WAAW;AAAA,UAC/B,GAAG,KAAK,CAAC,GAAG,UAAU,YAAY;AAAA,QAAA;AAGpC,wBAAgB,MAAM,aAAa,gBAAgB;AAAA,MACrD;AAAA;AAAA;AAAA;AAAA,MAKA,IAAa,UAA+B;AAC1C,YAAI,YAAY,KAAK,SAAS,KAAK,MAAM,UAAU,MAAM;AACvD,eAAK,eAAe,KAAK,MAAM;AAAA,QACjC;AAEA,eAAO,KAAK;AAAA,MACd;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOA,IAAI,QAAsB;AACxB,YAAI,WAAW,KAAK,OAAO;AACzB,iBAAO,KAAK,MAAM;AAAA,QACpB;AAEA,eAAO,YAAY,MAAM;AAAA,MAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAOA,IAAI,aAAa;AACf,eAAO,KAAK;AAAA,MACd;AAAA;AAAA;AAAA;AAAA,MAKA,IAAa,YAAY;AACvB,eAAO,MAAM,aAAa,KAAK,MAAM;AAAA,MACvC;AAAA,IAAA;AAGF,WAAO;AAAA,EACT;AACF;AAMA,MAAM,sBAAsB,UAAU,EAAS,EAAE,aAAa;AAiBvD,MAAe,uBAEZ,oBAAoB;AAE9B;"}
|