Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor DI into inject() methods #3954

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions projects/aca-content/ms-office/src/effects/aos.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { Injectable } from '@angular/core';
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { inject, Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { map } from 'rxjs/operators';

import { AOS_ACTION, AosAction } from '../actions/aos.actions';
import { AosEditOnlineService } from '../aos-extension.service';

@Injectable()
export class AosEffects {
constructor(private actions$: Actions, private aosEditOnlineService: AosEditOnlineService) {}
private actions$ = inject(Actions);
private aosEditOnlineService = inject(AosEditOnlineService);

openOffice$ = createEffect(
() =>
Expand Down
9 changes: 6 additions & 3 deletions projects/aca-content/src/lib/store/effects/app.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { Actions, ofType, createEffect } from '@ngrx/effects';
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { inject, Injectable } from '@angular/core';
import { map } from 'rxjs/operators';
import { AppActionTypes, LogoutAction, ReloadDocumentListAction, ResetSelectionAction } from '@alfresco/aca-shared/store';
import { AuthenticationService } from '@alfresco/adf-core';
Expand All @@ -32,7 +32,10 @@ import { AppHookService } from '@alfresco/aca-shared';

@Injectable()
export class AppEffects {
constructor(private actions$: Actions, private auth: AuthenticationService, private router: Router, private appHookService: AppHookService) {}
actions$ = inject(Actions);
auth = inject(AuthenticationService);
router = inject(Router);
appHookService = inject(AppHookService);

reload = createEffect(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { ContextMenuActionTypes, ContextMenu } from '@alfresco/aca-shared/store';
import { Injectable } from '@angular/core';
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { ContextMenu, ContextMenuActionTypes } from '@alfresco/aca-shared/store';
import { inject, Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { map } from 'rxjs/operators';
import { ContextMenuOverlayRef } from '../../components/context-menu/context-menu-overlay';
import { ContextMenuService } from '../../components/context-menu/context-menu.service';
Expand All @@ -33,7 +33,8 @@ import { ContextMenuService } from '../../components/context-menu/context-menu.s
export class ContextMenuEffects {
private overlayRef: ContextMenuOverlayRef = null;

constructor(private contextMenuService: ContextMenuService, private actions$: Actions) {}
contextMenuService = inject(ContextMenuService);
actions$ = inject(Actions);

contextMenu$ = createEffect(
() =>
Expand Down
18 changes: 8 additions & 10 deletions projects/aca-content/src/lib/store/effects/download.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,24 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { AppStore, DownloadNodesAction, NodeActionTypes, NodeInfo, getAppSelection, getCurrentVersion } from '@alfresco/aca-shared/store';
import { AppStore, DownloadNodesAction, getAppSelection, getCurrentVersion, NodeActionTypes, NodeInfo } from '@alfresco/aca-shared/store';
import { DownloadZipDialogComponent } from '@alfresco/adf-content-services';
import { NodeEntry, Version } from '@alfresco/js-api';
import { Injectable } from '@angular/core';
import { inject, Injectable } from '@angular/core';
import { MatDialog } from '@angular/material/dialog';
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import { map, take } from 'rxjs/operators';
import { ContentApiService } from '@alfresco/aca-shared';
import { ContentUrlService } from '../../services/content-url.service';

@Injectable()
export class DownloadEffects {
constructor(
private store: Store<AppStore>,
private actions$: Actions,
private contentApi: ContentApiService,
private dialog: MatDialog,
private contentUrlService: ContentUrlService
) {}
private store = inject(Store<AppStore>);
private actions$ = inject(Actions);
private contentApi = inject(ContentApiService);
private dialog = inject(MatDialog);
private contentUrlService = inject(ContentUrlService);

downloadNode$ = createEffect(
() =>
Expand Down
10 changes: 6 additions & 4 deletions projects/aca-content/src/lib/store/effects/favorite.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { Actions, ofType, createEffect } from '@ngrx/effects';
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { inject, Injectable } from '@angular/core';
import { map, take } from 'rxjs/operators';
import { AppStore, NodeActionTypes, AddFavoriteAction, RemoveFavoriteAction, getAppSelection } from '@alfresco/aca-shared/store';
import { AddFavoriteAction, AppStore, getAppSelection, NodeActionTypes, RemoveFavoriteAction } from '@alfresco/aca-shared/store';
import { Store } from '@ngrx/store';
import { ContentManagementService } from '../../services/content-management.service';

@Injectable()
export class FavoriteEffects {
constructor(private store: Store<AppStore>, private actions$: Actions, private content: ContentManagementService) {}
private store = inject(Store<AppStore>);
private actions$ = inject(Actions);
private content = inject(ContentManagementService);

addFavorite$ = createEffect(
() =>
Expand Down
18 changes: 8 additions & 10 deletions projects/aca-content/src/lib/store/effects/library.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,27 @@ import {
AppStore,
CreateLibraryAction,
DeleteLibraryAction,
getAppSelection,
LeaveLibraryAction,
LibraryActionTypes,
NavigateLibraryAction,
NavigateRouteAction,
SnackbarErrorAction,
UpdateLibraryAction,
getAppSelection
UpdateLibraryAction
} from '@alfresco/aca-shared/store';
import { Injectable } from '@angular/core';
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { inject, Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import { map, mergeMap, take } from 'rxjs/operators';
import { ContentApiService } from '@alfresco/aca-shared';
import { ContentManagementService } from '../../services/content-management.service';

@Injectable()
export class LibraryEffects {
constructor(
private store: Store<AppStore>,
private actions$: Actions,
private content: ContentManagementService,
private contentApi: ContentApiService
) {}
private store = inject(Store<AppStore>);
private actions$ = inject(Actions);
private content = inject(ContentManagementService);
private contentApi = inject(ContentApiService);

deleteLibrary$ = createEffect(
() =>
Expand Down
52 changes: 25 additions & 27 deletions projects/aca-content/src/lib/store/effects/node.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,50 +22,48 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { Actions, ofType, createEffect } from '@ngrx/effects';
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { inject, Injectable } from '@angular/core';
import { first, map, take } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import {
AppStore,
NodeActionTypes,
PurgeDeletedNodesAction,
DeleteNodesAction,
UndoDeleteNodesAction,
CopyNodesAction,
CreateFolderAction,
DeleteNodesAction,
EditFolderAction,
RestoreDeletedNodesAction,
ShareNodeAction,
ManageVersionsAction,
UnlockWriteAction,
UnshareNodesAction,
CopyNodesAction,
MoveNodesAction,
ManagePermissionsAction,
PrintFileAction,
getCurrentFolder,
ExpandInfoDrawerAction,
getAppSelection,
getCurrentFolder,
ManageAspectsAction,
NavigateRouteAction,
ExpandInfoDrawerAction,
ManagePermissionsAction,
ManageRulesAction,
ShowLoaderAction,
ManageVersionsAction,
MoveNodesAction,
NavigateRouteAction,
NavigateUrlAction,
NodeActionTypes,
PrintFileAction,
PurgeDeletedNodesAction,
RestoreDeletedNodesAction,
SetInfoDrawerStateAction,
NavigateUrlAction
ShareNodeAction,
ShowLoaderAction,
UndoDeleteNodesAction,
UnlockWriteAction,
UnshareNodesAction
} from '@alfresco/aca-shared/store';
import { ContentManagementService } from '../../services/content-management.service';
import { RenditionService } from '@alfresco/adf-content-services';
import { NavigationEnd, Router } from '@angular/router';

@Injectable()
export class NodeEffects {
constructor(
private store: Store<AppStore>,
private actions$: Actions,
private router: Router,
private contentService: ContentManagementService,
private renditionViewer: RenditionService
) {}
store = inject(Store<AppStore>);
actions$ = inject(Actions);
router = inject(Router);
contentService = inject(ContentManagementService);
renditionViewer = inject(RenditionService);

shareNode$ = createEffect(
() =>
Expand Down
8 changes: 5 additions & 3 deletions projects/aca-content/src/lib/store/effects/search.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { Actions, ofType, createEffect } from '@ngrx/effects';
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { inject, Injectable } from '@angular/core';
import { map } from 'rxjs/operators';
import { SearchAction, SearchActionTypes, SearchByTermAction, SearchOptionIds } from '@alfresco/aca-shared/store';
import { Router } from '@angular/router';
import { SearchNavigationService } from '../../components/search/search-navigation.service';

@Injectable()
export class SearchEffects {
constructor(private actions$: Actions, private router: Router, private searchNavigationService: SearchNavigationService) {}
private actions$ = inject(Actions);
private router = inject(Router);
private searchNavigationService = inject(SearchNavigationService);

search$ = createEffect(
() =>
Expand Down
32 changes: 15 additions & 17 deletions projects/aca-content/src/lib/store/effects/template.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@
* from Hyland Software. If not, see <http://www.gnu.org/licenses/>.
*/

import { Actions, ofType, createEffect } from '@ngrx/effects';
import { Injectable } from '@angular/core';
import { map, switchMap, debounceTime, take, catchError } from 'rxjs/operators';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { inject, Injectable } from '@angular/core';
import { catchError, debounceTime, map, switchMap, take } from 'rxjs/operators';
import { Store } from '@ngrx/store';
import {
FileFromTemplate,
FolderFromTemplate,
AppStore,
CreateFromTemplate,
CreateFromTemplateSuccess,
TemplateActionTypes,
FileFromTemplate,
FolderFromTemplate,
getCurrentFolder,
AppStore,
SnackbarErrorAction
SnackbarErrorAction,
TemplateActionTypes
} from '@alfresco/aca-shared/store';
import { NodeTemplateService, TemplateDialogConfig } from '../../services/node-template.service';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { AppHookService } from '@alfresco/aca-shared';
import { from, Observable, of } from 'rxjs';
import { NodeEntry, NodeBodyUpdate, Node, NodesApi } from '@alfresco/js-api';
import { Node, NodeBodyUpdate, NodeEntry, NodesApi } from '@alfresco/js-api';
import { MatDialog } from '@angular/material/dialog';

@Injectable()
Expand All @@ -51,14 +51,12 @@ export class TemplateEffects {
return this._nodesApi;
}

constructor(
private matDialog: MatDialog,
private appHookService: AppHookService,
private store: Store<AppStore>,
private apiService: AlfrescoApiService,
private actions$: Actions,
private nodeTemplateService: NodeTemplateService
) {}
private matDialog = inject(MatDialog);
private appHookService = inject(AppHookService);
private store = inject(Store<AppStore>);
private apiService = inject(AlfrescoApiService);
private actions$ = inject(Actions);
private nodeTemplateService = inject(NodeTemplateService);

fileFromTemplate$ = createEffect(
() =>
Expand Down
27 changes: 13 additions & 14 deletions projects/aca-content/src/lib/store/effects/upload.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@

import {
AppStore,
getCurrentFolder,
SnackbarErrorAction,
UnlockWriteAction,
UploadActionTypes,
UploadFilesAction,
UploadFileVersionAction,
UploadFolderAction,
getCurrentFolder
UploadFolderAction
} from '@alfresco/aca-shared/store';
import { FileUtils } from '@alfresco/adf-core';
import { Injectable, NgZone, RendererFactory2 } from '@angular/core';
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { inject, Injectable, NgZone, RendererFactory2 } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { Store } from '@ngrx/store';
import { of } from 'rxjs';
import { catchError, map, take } from 'rxjs/operators';
import { ContentManagementService } from '../../services/content-management.service';
import { Node } from '@alfresco/js-api';
import { UploadService, FileModel } from '@alfresco/adf-content-services';
import { FileModel, UploadService } from '@alfresco/adf-content-services';

@Injectable()
export class UploadEffects {
Expand All @@ -49,15 +49,14 @@ export class UploadEffects {
private readonly fileVersionInput: HTMLInputElement;
private readonly uploadMenuButtonSelector = 'app-toolbar-menu button[id="app.toolbar.upload"]';

constructor(
private store: Store<AppStore>,
private actions$: Actions,
private ngZone: NgZone,
private uploadService: UploadService,
rendererFactory: RendererFactory2,
private contentService: ContentManagementService
) {
const renderer = rendererFactory.createRenderer(null, null);
private store = inject(Store<AppStore>);
private actions$ = inject(Actions);
private ngZone = inject(NgZone);
private uploadService = inject(UploadService);
rendererFactory = inject(RendererFactory2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you verify if moving the rendererFactory inject to inside the constructor still works? According to the previous implementation, the rendererFactory instance was only available inside the constructor, and would free up its occupied memory after constructor code execution. However, with the current implementation, it would keep occupying its memory, as long as the service/component/etc is alive, even though its only really being used inside the constructor

private contentService = inject(ContentManagementService);
constructor() {
const renderer = this.rendererFactory.createRenderer(null, null);

this.fileInput = renderer.createElement('input') as HTMLInputElement;
this.fileInput.id = 'app-upload-files';
Expand Down
Loading
Loading