-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): expose WindowRef and ReflectRef services as public api
This will allow users to configure/customise the access to global Window object and from where Reflect API is loaded
- Loading branch information
Showing
5 changed files
with
47 additions
and
16 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
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 |
---|---|---|
@@ -1 +1,3 @@ | ||
export * from './window-ref.service'; | ||
export * from './window-ref-browser'; | ||
export * from './reflect-ref.service'; |
39 changes: 39 additions & 0 deletions
39
projects/ng-dynamic-component/src/lib/window-ref/reflect-ref.service.ts
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,39 @@ | ||
import { Injectable, Type } from '@angular/core'; | ||
|
||
import { WindowRefService } from './window-ref.service'; | ||
|
||
/** | ||
* Reflect API subsystem required for lib to work | ||
*/ | ||
export interface ReflectRef { | ||
getMetadata: (type: string, obj: unknown) => unknown[]; | ||
} | ||
|
||
/** | ||
* Retrieves Reflect API from global Window object | ||
* of {@link WindowRefService} as a `Reflect` property | ||
*/ | ||
export function windowReflectFactory(windowRef: WindowRefService) { | ||
return (windowRef.nativeWindow as any).Reflect; | ||
} | ||
|
||
/** | ||
* Holds {@link ReflectRef} that is used by {@link ReflectRefService} | ||
*/ | ||
@Injectable({ | ||
providedIn: 'root', | ||
useFactory: windowReflectFactory, | ||
deps: [WindowRefService], | ||
}) | ||
export class ReflectRefToken extends ((class {} as any) as Type<ReflectRef>) {} | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class ReflectRefService { | ||
readonly reflect: ReflectRef = this.reflectRefToken; | ||
|
||
constructor(private reflectRefToken: ReflectRefToken) {} | ||
|
||
getCtorParamTypes(ctor: Type<unknown>): unknown[] { | ||
return this.reflect.getMetadata('design:paramtypes', ctor); | ||
} | ||
} |
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