Skip to content

Commit

Permalink
changed change detection strategy to onpush (#224)
Browse files Browse the repository at this point in the history
* changed change detection strategy to onpush
* removed closedSubject
  • Loading branch information
Julian-Mueller-GIP authored Dec 20, 2024
1 parent 25fa8e9 commit 129ecea
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zeta",
"title": "Zeta",
"version": "17.0.14",
"version": "17.0.15",
"private": true,
"engines": {
"node": "^18.13.0 || ^20.9.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@
* limitations under the License.
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
import { AfterViewInit, Component, Injector, OnDestroy } from '@angular/core';
import { AfterViewInit, ChangeDetectionStrategy, ChangeDetectorRef, Component, Injector, OnDestroy } from '@angular/core';

import { environment } from '@environments/environment';
import { XcStackItemComponent, XcStackItemComponentData } from '../../../../xc-stack/xc-stack-item/xc-stack-item.component';

import { Observable, of, Subject, Subscription, throwError } from 'rxjs';
import { Observable, of, Subscription, throwError } from 'rxjs';
import { filter, map, switchMap, tap } from 'rxjs/operators';
import { XoFormDefinition } from '../../xo/containers.model';

import { ApiService, StartOrderOptionsBuilder, Xo, XoManagedFileID, XoXPRCRuntimeContext, XoXPRCRuntimeContextFromRuntimeContext } from '../../../../../api';
import { XcStackItem, XcStackItemInterface, XcStackItemObserver } from '../../../../xc-stack/xc-stack-item/xc-stack-item';
import { XoBaseDefinition, XoCloseDefinitionData, XoDefinition, XoDefinitionBundle, XoDefinitionObserver } from '../../xo/base-definition.model';
import { XcDialogService } from '../../../../xc-dialog/xc-dialog.service';
import { I18nService } from '../../../../../i18n';
import { XcDialogService } from '../../../../xc-dialog/xc-dialog.service';
import { XcStackItem, XcStackItemInterface, XcStackItemObserver } from '../../../../xc-stack/xc-stack-item/xc-stack-item';
import { XcStackItemComponent, XcStackItemComponentData } from '../../../../xc-stack/xc-stack-item/xc-stack-item.component';
import { XcComponentTemplate } from '../../../../xc-template/xc-template';
import { XoStartOrderButtonDefinition } from '../../xo/item-definition.model';
import { XcDialogDefinitionComponent } from '../../xc-dialog-definition/xc-dialog-definition.component';
import { XoBaseDefinition, XoCloseDefinitionData, XoDefinition, XoDefinitionBundle, XoDefinitionObserver } from '../../xo/base-definition.model';
import { XoFormDefinition } from '../../xo/containers.model';
import { XoStartOrderButtonDefinition } from '../../xo/item-definition.model';


export interface DefinitionStackItemComponentData extends XcStackItemComponentData {
Expand All @@ -46,16 +48,22 @@ interface DefinitionStackItem {

@Component({
templateUrl: './xc-definition-stack-item.component.html',
styleUrls: ['./xc-definition-stack-item.component.scss']
styleUrls: ['./xc-definition-stack-item.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class XcDefinitionStackItemComponent extends XcStackItemComponent<DefinitionStackItemComponentData> implements XoDefinitionObserver, AfterViewInit, OnDestroy {

private detailsItem: DefinitionStackItem;
private readonly closedSubject = new Subject<XoCloseDefinitionData>();
private readonly subscriptions: Subscription[] = [];


constructor(readonly injector: Injector, private readonly api: ApiService, private readonly dialogs: XcDialogService, private readonly i18n: I18nService) {
constructor(
readonly injector: Injector,
private readonly api: ApiService,
private readonly dialogs: XcDialogService,
private readonly i18n: I18nService,
private readonly cdr: ChangeDetectorRef
) {
super(injector);
}

Expand Down Expand Up @@ -97,7 +105,8 @@ export class XcDefinitionStackItemComponent extends XcStackItemComponent<Definit
XcDefinitionStackItemComponent,
<DefinitionStackItemComponentData>{ stackItem: this.detailsItem.item, definition: definition, data: data }
));
return this.stackItem.stack.open(this.detailsItem.item);
// markForCheck has to be called before stack.open to work propperly
return of(null).pipe(tap(() => this.cdr.markForCheck()), switchMap(() => this.stackItem.stack.open(this.detailsItem.item)));
};

// close current details item, if any
Expand All @@ -111,7 +120,7 @@ export class XcDefinitionStackItemComponent extends XcStackItemComponent<Definit


openDialog(definition: XoDefinition, data: Xo[]): Observable<Xo[]> {
return this.dialogs.custom(XcDialogDefinitionComponent, {definition: definition, data: data}).afterDismiss();
return this.dialogs.custom(XcDialogDefinitionComponent, { definition: definition, data: data }).afterDismiss();
}


Expand All @@ -123,8 +132,7 @@ export class XcDefinitionStackItemComponent extends XcStackItemComponent<Definit
return this.stackItem.stack.close(this.stackItem).pipe(
tap(closed => {
if (closed) {
this.closedSubject.next(data);
this.closedSubject.complete();
this.cdr.markForCheck();
}
})
);
Expand Down

0 comments on commit 129ecea

Please sign in to comment.