forked from DSpace/dspace-angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request DSpace#2897 from 4Science/DURACOM-247
Fixes for DSpace#2891 DSpace#2889
- Loading branch information
Showing
14 changed files
with
161 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { | ||
Injector, | ||
Type, | ||
} from '@angular/core'; | ||
import { | ||
defer, | ||
Observable, | ||
} from 'rxjs'; | ||
|
||
import { LazyDataServicesMap } from '../../config/app-config.interface'; | ||
import { HALDataService } from './data/base/hal-data-service.interface'; | ||
|
||
/** | ||
* Loads a service lazily. The service is loaded when the observable is subscribed to. | ||
* | ||
* @param dataServicesMap A map of promises returning the data services to load | ||
* @param key The key of the service | ||
* @param injector The injector to use to load the service. If not provided, the current injector is used. | ||
* @returns An observable of the service. | ||
* | ||
* @example | ||
* ```ts | ||
* const dataService$ = lazyDataService({ 'data-service': () => import('./data-service').then((m) => m.MyService)}, 'data-service', this.injector); | ||
* or | ||
* const dataService$ = lazyDataService({'data-service': () => import('./data-service')}, 'data-service', this.injector); | ||
* ``` | ||
*/ | ||
export function lazyDataService<T>( | ||
dataServicesMap: LazyDataServicesMap, | ||
key: string, | ||
injector: Injector, | ||
): Observable<T> { | ||
return defer(() => { | ||
if (dataServicesMap.has(key) && typeof dataServicesMap.get(key) === 'function') { | ||
const loader: () => Promise<Type<HALDataService<any>> | { default: HALDataService<any> }> = dataServicesMap.get(key); | ||
return loader() | ||
.then((serviceOrDefault) => { | ||
if ('default' in serviceOrDefault) { | ||
return injector!.get(serviceOrDefault.default); | ||
} | ||
return injector!.get(serviceOrDefault); | ||
}) | ||
.catch((error) => { | ||
throw error; | ||
}); | ||
} else { | ||
return null; | ||
} | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.