Skip to content

Commit

Permalink
Prevent ItemSearchResult from being recreated at every iteration
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrevryghem committed May 1, 2024
1 parent 27a83d6 commit da320b5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<ds-listable-object-component-loader
[object]="transformItemToItemSearchResult(object)"
[object]="itemSearchResult"
[viewMode]="viewMode"
[linkType]="linkType">
</ds-listable-object-component-loader>
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ describe('ItemListElementComponent', () => {
describe(`when the publication is rendered`, () => {
beforeEach(() => {
comp.object = mockItem;
comp.ngOnChanges();
fixture.detectChanges();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Component } from '@angular/core';
import {
Component,
OnChanges,
} from '@angular/core';

import { Item } from '../../../../../core/shared/item.model';
import { ViewMode } from '../../../../../core/shared/view-mode.model';
import { hasValue } from '../../../../empty.util';
import { ItemSearchResult } from '../../../../object-collection/shared/item-search-result.model';
import { listableObjectComponent } from '../../../../object-collection/shared/listable-object/listable-object.decorator';
import { ListableObjectComponentLoaderComponent } from '../../../../object-collection/shared/listable-object/listable-object-component-loader.component';
Expand All @@ -21,12 +25,16 @@ import { AbstractListableElementComponent } from '../../../../object-collection/
/**
* The component for displaying a list element for an item of the type Publication
*/
export class ItemListElementComponent extends AbstractListableElementComponent<Item> {
export class ItemListElementComponent extends AbstractListableElementComponent<Item> implements OnChanges {

transformItemToItemSearchResult(object: Item): ItemSearchResult {
const itemSearchResult = new ItemSearchResult();
itemSearchResult.indexableObject = object;
return itemSearchResult;
itemSearchResult: ItemSearchResult;

ngOnChanges(): void {
if (hasValue(this.object)) {
this.itemSearchResult = Object.assign(new ItemSearchResult(), {
indexableObject: this.object,
});
}
}

}

0 comments on commit da320b5

Please sign in to comment.