Browse Source

Clean some constructor injection to inject()

pull/18080/head
Mahmut Gundogdu 3 years ago
parent
commit
c8e97adb64
  1. 27
      npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts

27
npm/ng-packs/packages/components/extensible/src/lib/components/extensible-table/extensible-table.component.ts

@ -13,6 +13,7 @@ import {
ChangeDetectionStrategy, ChangeDetectionStrategy,
Component, Component,
EventEmitter, EventEmitter,
inject,
Inject, Inject,
Injector, Injector,
Input, Input,
@ -82,12 +83,8 @@ export class ExtensibleTableComponent<R = any> implements OnChanges {
@Output() tableActivate = new EventEmitter(); @Output() tableActivate = new EventEmitter();
getInjected: typeof this.injector.get;
hasAtLeastOnePermittedAction: boolean; hasAtLeastOnePermittedAction: boolean;
entityPropTypeClasses: EntityPropTypeClass;
readonly columnWidths!: number[]; readonly columnWidths!: number[];
readonly propList: EntityPropList<R>; readonly propList: EntityPropList<R>;
@ -96,20 +93,20 @@ export class ExtensibleTableComponent<R = any> implements OnChanges {
readonly trackByFn: TrackByFunction<EntityProp<R>> = (_, item) => item.name; readonly trackByFn: TrackByFunction<EntityProp<R>> = (_, item) => item.name;
constructor( locale = inject(LOCALE_ID);
@Inject(LOCALE_ID) private locale: string, private config = inject(ConfigStateService);
private config: ConfigStateService, entityPropTypeClasses = inject(ENTITY_PROP_TYPE_CLASSES);
private injector: Injector, #injector = inject(Injector);
) { getInjected = this.#injector.get.bind(this.#injector);
this.entityPropTypeClasses = injector.get(ENTITY_PROP_TYPE_CLASSES);
this.getInjected = injector.get.bind(injector); constructor() {
const extensions = injector.get(ExtensionsService); const extensions = this.#injector.get(ExtensionsService);
const name = injector.get(EXTENSIONS_IDENTIFIER); const name = this.#injector.get(EXTENSIONS_IDENTIFIER);
this.propList = extensions.entityProps.get(name).props; this.propList = extensions.entityProps.get(name).props;
this.actionList = extensions['entityActions'].get(name) this.actionList = extensions['entityActions'].get(name)
.actions as unknown as EntityActionList<R>; .actions as unknown as EntityActionList<R>;
const permissionService = injector.get(PermissionService); const permissionService = this.#injector.get(PermissionService);
this.hasAtLeastOnePermittedAction = this.hasAtLeastOnePermittedAction =
permissionService.filterItemsByPolicy( permissionService.filterItemsByPolicy(
this.actionList.toArray().map(action => ({ requiredPolicy: action.permission })), this.actionList.toArray().map(action => ({ requiredPolicy: action.permission })),
@ -188,7 +185,7 @@ export class ExtensibleTableComponent<R = any> implements OnChanges {
useValue: value, useValue: value,
}, },
], ],
parent: this.injector, parent: this.#injector,
}); });
record[propKey].component = prop.value.component; record[propKey].component = prop.value.component;
} }

Loading…
Cancel
Save