Skip to content

Commit 7530626

Browse files
committed
chore(release): 0.8.0
1 parent 084e1da commit 7530626

26 files changed

+346
-37
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,21 @@
22

33
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
44

5+
<a name="0.8.0"></a>
6+
# [0.8.0](https://github.com/fkleuver/aurelia-router-metadata/compare/v0.7.0...v0.8.0) (2018-03-03)
7+
8+
9+
### Bug Fixes
10+
11+
* **router-resource:** also check the .isRoot property on the router when deciding whether to merge the RouterConfiguration ([c9711ec](https://github.com/fkleuver/aurelia-router-metadata/commit/c9711ec))
12+
13+
14+
### Features
15+
16+
* add lifeCycleArgs and additional configuration hooks for centralized control over app-wide router configuration ([084e1da](https://github.com/fkleuver/aurelia-router-metadata/commit/084e1da))
17+
18+
19+
520
<a name="0.7.0"></a>
621
# [0.7.0](https://github.com/fkleuver/aurelia-router-metadata/compare/v0.6.0...v0.7.0) (2018-03-02)
722

dist/amd/router-metadata-configuration.d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Container } from "aurelia-dependency-injection";
2+
import { Router, RouterConfiguration } from "aurelia-router";
23
import { ICompleteRouteConfig, IConfigureRouterInstruction, ICreateRouteConfigInstruction, IResourceLoader, IRouteConfig, IRouterConfiguration } from "./interfaces";
34
import { RouteConfigFactory } from "./route-config-factory";
5+
import { RouterResource } from "./router-resource";
46
/**
57
* Class used to configure behavior of [[RouterResource]]
68
*/
@@ -73,5 +75,27 @@ export declare class RouterMetadataSettings {
7375
* Specify RouterConfiguration properties that need to be set on the AppRouter
7476
*/
7577
routerConfiguration: IRouterConfiguration;
78+
/**
79+
* Called first when inside `configureRouter()`: childRoutes are not loaded, and no changes have
80+
* been made to the router, config or viewmodel yet.
81+
*/
82+
onBeforeLoadChildRoutes: (viewModelInstance: any, config: RouterConfiguration, router: Router, resource: RouterResource, ...lifeCycleArgs: any[]) => void | Promise<void> | PromiseLike<void>;
83+
/**
84+
* Called directly after `loadChildRoutes()` and before `config.map(routes)`
85+
*/
86+
onBeforeConfigMap: (viewModelInstance: any, config: RouterConfiguration, router: Router, resource: RouterResource, childRoutes: ICompleteRouteConfig[], ...lifeCycleArgs: any[]) => void | Promise<void> | PromiseLike<void>;
87+
/**
88+
* If true, target class will have its "router" property assigned from the proxied `configureRouter()` method.
89+
*
90+
* If a string is provided, the router will be assigned to the property with that name (implies true).
91+
*
92+
* If a function is provided, that function will be called during `configureRouter()` when normally the router would be assigned.
93+
* This is directly after `config.map(routes)` and before the RouterConfigurations are merged (if it's the root)
94+
*/
95+
assignRouterToViewModel: boolean | string | ((viewModelInstance: any, config: RouterConfiguration, router: Router, resource: RouterResource, childRoutes: ICompleteRouteConfig[], ...lifeCycleArgs: any[]) => void | Promise<void> | PromiseLike<void>);
96+
/**
97+
* Called directly after the RouterConfigurations are merged (if it's the root)
98+
*/
99+
onAfterMergeRouterConfiguration: (viewModelInstance: any, config: RouterConfiguration, router: Router, resource: RouterResource, childRoutes: ICompleteRouteConfig[], ...lifeCycleArgs: any[]) => void | Promise<void> | PromiseLike<void>;
76100
constructor();
77101
}

dist/amd/router-metadata-configuration.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ define(["require", "exports", "aurelia-dependency-injection", "aurelia-router",
8080
this.filterChildRoutes = noFilter;
8181
this.enableEagerLoading = true;
8282
this.routerConfiguration = new aurelia_router_1.RouterConfiguration();
83+
this.onBeforeLoadChildRoutes = null;
84+
this.onBeforeConfigMap = null;
85+
this.assignRouterToViewModel = false;
86+
this.onAfterMergeRouterConfiguration = null;
8387
}
8488
}
8589
exports.RouterMetadataSettings = RouterMetadataSettings;

dist/amd/router-resource.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export declare class RouterResource {
163163
* If `target.prototype.configureRouter` already exists, a reference to that original method will be kept
164164
* and called at the end of this `configureRouter()` method.
165165
*/
166-
configureRouter(config: RouterConfiguration, router: Router): Promise<void>;
166+
configureRouter(config: RouterConfiguration, router: Router, ...args: any[]): Promise<void>;
167167
protected getSettings(instruction?: IRouteConfigInstruction | IConfigureRouterInstruction): RouterMetadataSettings;
168168
protected getConfigFactory(): RouteConfigFactory;
169169
protected getResourceLoader(): IResourceLoader;

dist/amd/router-resource.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,43 @@ define(["require", "exports", "aurelia-logging", "aurelia-router", "./router-met
193193
* If `target.prototype.configureRouter` already exists, a reference to that original method will be kept
194194
* and called at the end of this `configureRouter()` method.
195195
*/
196-
configureRouter(config, router) {
196+
configureRouter(config, router, ...args) {
197197
return __awaiter(this, void 0, void 0, function* () {
198+
const viewModel = router.container.viewModel;
199+
const settings = this.getSettings();
200+
if (typeof settings.onBeforeLoadChildRoutes === "function") {
201+
yield settings.onBeforeLoadChildRoutes(viewModel, config, router, this, ...args);
202+
}
198203
this.isConfiguringRouter = true;
199204
const routes = yield this.loadChildRoutes();
200205
assignPaths(routes);
206+
if (typeof settings.onBeforeConfigMap === "function") {
207+
yield settings.onBeforeConfigMap(viewModel, config, router, this, routes, ...args);
208+
}
201209
config.map(routes);
202210
this.router = router;
203-
if (router instanceof aurelia_router_1.AppRouter) {
211+
if (router instanceof aurelia_router_1.AppRouter || router.isRoot) {
212+
const assign = settings.assignRouterToViewModel;
213+
if (assign === true) {
214+
viewModel.router = router;
215+
}
216+
else if (Object.prototype.toString.call(assign) === "[object String]") {
217+
viewModel[assign] = router;
218+
}
219+
else if (typeof assign === "function") {
220+
yield assign(viewModel, config, router, this, routes, ...args);
221+
}
204222
const settingsConfig = this.getSettings().routerConfiguration || {};
205223
mergeRouterConfiguration(config, settingsConfig);
224+
if (typeof settings.onAfterMergeRouterConfiguration === "function") {
225+
yield settings.onAfterMergeRouterConfiguration(viewModel, config, router, this, routes, ...args);
226+
}
206227
}
207228
this.isRouterConfigured = true;
208229
this.isConfiguringRouter = false;
209230
const originalConfigureRouter = this.target.prototype[configureRouterSymbol];
210231
if (originalConfigureRouter !== undefined) {
211-
return originalConfigureRouter.call(router.container.viewModel, config, router);
232+
return originalConfigureRouter.call(viewModel, config, router);
212233
}
213234
});
214235
}
@@ -257,11 +278,11 @@ define(["require", "exports", "aurelia-logging", "aurelia-router", "./router-met
257278
proto[name] = value;
258279
}
259280
// tslint:disable:no-invalid-this
260-
function configureRouter(config, router) {
281+
function configureRouter(config, router, ...args) {
261282
return __awaiter(this, void 0, void 0, function* () {
262283
const target = Object.getPrototypeOf(this).constructor;
263284
const resource = router_metadata_1.routerMetadata.getOwn(target);
264-
yield resource.configureRouter(config, router);
285+
yield resource.configureRouter(config, router, ...args);
265286
});
266287
}
267288
// tslint:enable:no-invalid-this

dist/commonjs/router-metadata-configuration.d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Container } from "aurelia-dependency-injection";
2+
import { Router, RouterConfiguration } from "aurelia-router";
23
import { ICompleteRouteConfig, IConfigureRouterInstruction, ICreateRouteConfigInstruction, IResourceLoader, IRouteConfig, IRouterConfiguration } from "./interfaces";
34
import { RouteConfigFactory } from "./route-config-factory";
5+
import { RouterResource } from "./router-resource";
46
/**
57
* Class used to configure behavior of [[RouterResource]]
68
*/
@@ -73,5 +75,27 @@ export declare class RouterMetadataSettings {
7375
* Specify RouterConfiguration properties that need to be set on the AppRouter
7476
*/
7577
routerConfiguration: IRouterConfiguration;
78+
/**
79+
* Called first when inside `configureRouter()`: childRoutes are not loaded, and no changes have
80+
* been made to the router, config or viewmodel yet.
81+
*/
82+
onBeforeLoadChildRoutes: (viewModelInstance: any, config: RouterConfiguration, router: Router, resource: RouterResource, ...lifeCycleArgs: any[]) => void | Promise<void> | PromiseLike<void>;
83+
/**
84+
* Called directly after `loadChildRoutes()` and before `config.map(routes)`
85+
*/
86+
onBeforeConfigMap: (viewModelInstance: any, config: RouterConfiguration, router: Router, resource: RouterResource, childRoutes: ICompleteRouteConfig[], ...lifeCycleArgs: any[]) => void | Promise<void> | PromiseLike<void>;
87+
/**
88+
* If true, target class will have its "router" property assigned from the proxied `configureRouter()` method.
89+
*
90+
* If a string is provided, the router will be assigned to the property with that name (implies true).
91+
*
92+
* If a function is provided, that function will be called during `configureRouter()` when normally the router would be assigned.
93+
* This is directly after `config.map(routes)` and before the RouterConfigurations are merged (if it's the root)
94+
*/
95+
assignRouterToViewModel: boolean | string | ((viewModelInstance: any, config: RouterConfiguration, router: Router, resource: RouterResource, childRoutes: ICompleteRouteConfig[], ...lifeCycleArgs: any[]) => void | Promise<void> | PromiseLike<void>);
96+
/**
97+
* Called directly after the RouterConfigurations are merged (if it's the root)
98+
*/
99+
onAfterMergeRouterConfiguration: (viewModelInstance: any, config: RouterConfiguration, router: Router, resource: RouterResource, childRoutes: ICompleteRouteConfig[], ...lifeCycleArgs: any[]) => void | Promise<void> | PromiseLike<void>;
76100
constructor();
77101
}

dist/commonjs/router-metadata-configuration.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ class RouterMetadataSettings {
8383
this.filterChildRoutes = noFilter;
8484
this.enableEagerLoading = true;
8585
this.routerConfiguration = new aurelia_router_1.RouterConfiguration();
86+
this.onBeforeLoadChildRoutes = null;
87+
this.onBeforeConfigMap = null;
88+
this.assignRouterToViewModel = false;
89+
this.onAfterMergeRouterConfiguration = null;
8690
}
8791
}
8892
exports.RouterMetadataSettings = RouterMetadataSettings;

dist/commonjs/router-resource.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export declare class RouterResource {
163163
* If `target.prototype.configureRouter` already exists, a reference to that original method will be kept
164164
* and called at the end of this `configureRouter()` method.
165165
*/
166-
configureRouter(config: RouterConfiguration, router: Router): Promise<void>;
166+
configureRouter(config: RouterConfiguration, router: Router, ...args: any[]): Promise<void>;
167167
protected getSettings(instruction?: IRouteConfigInstruction | IConfigureRouterInstruction): RouterMetadataSettings;
168168
protected getConfigFactory(): RouteConfigFactory;
169169
protected getResourceLoader(): IResourceLoader;

dist/commonjs/router-resource.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,22 +196,43 @@ class RouterResource {
196196
* If `target.prototype.configureRouter` already exists, a reference to that original method will be kept
197197
* and called at the end of this `configureRouter()` method.
198198
*/
199-
configureRouter(config, router) {
199+
configureRouter(config, router, ...args) {
200200
return __awaiter(this, void 0, void 0, function* () {
201+
const viewModel = router.container.viewModel;
202+
const settings = this.getSettings();
203+
if (typeof settings.onBeforeLoadChildRoutes === "function") {
204+
yield settings.onBeforeLoadChildRoutes(viewModel, config, router, this, ...args);
205+
}
201206
this.isConfiguringRouter = true;
202207
const routes = yield this.loadChildRoutes();
203208
assignPaths(routes);
209+
if (typeof settings.onBeforeConfigMap === "function") {
210+
yield settings.onBeforeConfigMap(viewModel, config, router, this, routes, ...args);
211+
}
204212
config.map(routes);
205213
this.router = router;
206-
if (router instanceof aurelia_router_1.AppRouter) {
214+
if (router instanceof aurelia_router_1.AppRouter || router.isRoot) {
215+
const assign = settings.assignRouterToViewModel;
216+
if (assign === true) {
217+
viewModel.router = router;
218+
}
219+
else if (Object.prototype.toString.call(assign) === "[object String]") {
220+
viewModel[assign] = router;
221+
}
222+
else if (typeof assign === "function") {
223+
yield assign(viewModel, config, router, this, routes, ...args);
224+
}
207225
const settingsConfig = this.getSettings().routerConfiguration || {};
208226
mergeRouterConfiguration(config, settingsConfig);
227+
if (typeof settings.onAfterMergeRouterConfiguration === "function") {
228+
yield settings.onAfterMergeRouterConfiguration(viewModel, config, router, this, routes, ...args);
229+
}
209230
}
210231
this.isRouterConfigured = true;
211232
this.isConfiguringRouter = false;
212233
const originalConfigureRouter = this.target.prototype[configureRouterSymbol];
213234
if (originalConfigureRouter !== undefined) {
214-
return originalConfigureRouter.call(router.container.viewModel, config, router);
235+
return originalConfigureRouter.call(viewModel, config, router);
215236
}
216237
});
217238
}
@@ -260,11 +281,11 @@ function assignOrProxyPrototypeProperty(proto, name, refSymbol, value) {
260281
proto[name] = value;
261282
}
262283
// tslint:disable:no-invalid-this
263-
function configureRouter(config, router) {
284+
function configureRouter(config, router, ...args) {
264285
return __awaiter(this, void 0, void 0, function* () {
265286
const target = Object.getPrototypeOf(this).constructor;
266287
const resource = router_metadata_1.routerMetadata.getOwn(target);
267-
yield resource.configureRouter(config, router);
288+
yield resource.configureRouter(config, router, ...args);
268289
});
269290
}
270291
// tslint:enable:no-invalid-this

dist/es2015/router-metadata-configuration.d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Container } from "aurelia-dependency-injection";
2+
import { Router, RouterConfiguration } from "aurelia-router";
23
import { ICompleteRouteConfig, IConfigureRouterInstruction, ICreateRouteConfigInstruction, IResourceLoader, IRouteConfig, IRouterConfiguration } from "./interfaces";
34
import { RouteConfigFactory } from "./route-config-factory";
5+
import { RouterResource } from "./router-resource";
46
/**
57
* Class used to configure behavior of [[RouterResource]]
68
*/
@@ -73,5 +75,27 @@ export declare class RouterMetadataSettings {
7375
* Specify RouterConfiguration properties that need to be set on the AppRouter
7476
*/
7577
routerConfiguration: IRouterConfiguration;
78+
/**
79+
* Called first when inside `configureRouter()`: childRoutes are not loaded, and no changes have
80+
* been made to the router, config or viewmodel yet.
81+
*/
82+
onBeforeLoadChildRoutes: (viewModelInstance: any, config: RouterConfiguration, router: Router, resource: RouterResource, ...lifeCycleArgs: any[]) => void | Promise<void> | PromiseLike<void>;
83+
/**
84+
* Called directly after `loadChildRoutes()` and before `config.map(routes)`
85+
*/
86+
onBeforeConfigMap: (viewModelInstance: any, config: RouterConfiguration, router: Router, resource: RouterResource, childRoutes: ICompleteRouteConfig[], ...lifeCycleArgs: any[]) => void | Promise<void> | PromiseLike<void>;
87+
/**
88+
* If true, target class will have its "router" property assigned from the proxied `configureRouter()` method.
89+
*
90+
* If a string is provided, the router will be assigned to the property with that name (implies true).
91+
*
92+
* If a function is provided, that function will be called during `configureRouter()` when normally the router would be assigned.
93+
* This is directly after `config.map(routes)` and before the RouterConfigurations are merged (if it's the root)
94+
*/
95+
assignRouterToViewModel: boolean | string | ((viewModelInstance: any, config: RouterConfiguration, router: Router, resource: RouterResource, childRoutes: ICompleteRouteConfig[], ...lifeCycleArgs: any[]) => void | Promise<void> | PromiseLike<void>);
96+
/**
97+
* Called directly after the RouterConfigurations are merged (if it's the root)
98+
*/
99+
onAfterMergeRouterConfiguration: (viewModelInstance: any, config: RouterConfiguration, router: Router, resource: RouterResource, childRoutes: ICompleteRouteConfig[], ...lifeCycleArgs: any[]) => void | Promise<void> | PromiseLike<void>;
76100
constructor();
77101
}

0 commit comments

Comments
 (0)