mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import { convertToParamMap, ParamMap, Params } from '@angular/router';
|
|
|
|
import { BehaviorSubject } from 'rxjs/BehaviorSubject';
|
|
|
|
export class ActivatedRouteStub {
|
|
|
|
private _testParams?: any;
|
|
private _testData?: any;
|
|
// ActivatedRoute.params is Observable
|
|
private subject?: BehaviorSubject<any> = new BehaviorSubject(this.testParams);
|
|
private dataSubject?: BehaviorSubject<any> = new BehaviorSubject(this.testData);
|
|
|
|
params = this.subject.asObservable();
|
|
queryParams = this.subject.asObservable();
|
|
queryParamMap = this.subject.asObservable().map((params: Params) => convertToParamMap(params));
|
|
data = this.dataSubject.asObservable();
|
|
|
|
constructor(params?: Params, data?: any) {
|
|
if (params) {
|
|
this.testParams = params;
|
|
} else {
|
|
this.testParams = {};
|
|
}
|
|
if (data) {
|
|
this.testData = data;
|
|
} else {
|
|
this.testData = {};
|
|
}
|
|
}
|
|
|
|
// Test parameters
|
|
get testParams() {
|
|
return this._testParams;
|
|
}
|
|
|
|
set testParams(params: {}) {
|
|
this._testParams = params;
|
|
this.subject.next(params);
|
|
}
|
|
|
|
// Test data
|
|
get testData() {
|
|
return this._testParams;
|
|
}
|
|
|
|
set testData(data: {}) {
|
|
this._testData = data;
|
|
this.dataSubject.next(data);
|
|
}
|
|
|
|
// ActivatedRoute.snapshot.params
|
|
get snapshot() {
|
|
return {
|
|
params: this.testParams,
|
|
queryParamMap: convertToParamMap(this.testParams)
|
|
}
|
|
}
|
|
}
|