Skip to content

Commit e11a112

Browse files
committed
feat(lib): enable overriding of the elements registry, fixes #9
- use LAZY_ELEMENTS_REGISTRY token (with LazyElementsRegistry interface) - can be used to share registry between multiple apps / elements - can prevent multiple downloads of the same javascript bundles
1 parent a186d20 commit e11a112

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

projects/elements/src/lib/lazy-elements/lazy-elements-loader.service.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { Injectable, Type, Optional, Inject } from '@angular/core';
22

33
import { LazyElementRootOptions } from './lazy-elements.module';
4-
import { LAZY_ELEMENT_ROOT_OPTIONS } from './lazy-elements.tokens';
4+
import {
5+
LAZY_ELEMENT_ROOT_OPTIONS,
6+
LAZY_ELEMENTS_REGISTRY,
7+
LazyElementsRegistry
8+
} from './lazy-elements.tokens';
59

610
const LOG_PREFIX = '@angular-extensions/elements';
711

@@ -18,10 +22,10 @@ export interface ElementConfig {
1822
providedIn: 'root'
1923
})
2024
export class LazyElementsLoaderService {
21-
registry: Map<string, Promise<void>> = new Map<string, Promise<void>>();
2225
configs: ElementConfig[] = [];
2326

2427
constructor(
28+
@Inject(LAZY_ELEMENTS_REGISTRY) private registry: LazyElementsRegistry,
2529
@Optional()
2630
@Inject(LAZY_ELEMENT_ROOT_OPTIONS)
2731
public options: LazyElementRootOptions

projects/elements/src/lib/lazy-elements/lazy-elements.tokens.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,17 @@ export const LAZY_ELEMENT_ROOT_OPTIONS = new InjectionToken<
1414
export const LAZY_ELEMENT_ROOT_GUARD = new InjectionToken<void>(
1515
'LAZY_ELEMENT_ROOT_GUARD'
1616
);
17+
18+
export const LAZY_ELEMENTS_REGISTRY = new InjectionToken<LazyElementsRegistry>(
19+
'Lazu elements registry',
20+
{
21+
providedIn: 'root',
22+
factory: () => new Map<string, Promise<void>>()
23+
}
24+
);
25+
26+
export interface LazyElementsRegistry {
27+
get: (url: string) => Promise<void>;
28+
set: (url: string, notifier: Promise<void>) => void;
29+
has: (url: string) => boolean;
30+
}

0 commit comments

Comments
 (0)