Skip to content
This repository was archived by the owner on Nov 12, 2025. It is now read-only.

Conversation

@riccardo-forina
Copy link
Contributor

It is now possible to set a custom trackBy function to be used in the underlying ngFor directive, which by default tracks changes in the items by identity.

This is useful in scenarios where the items passed to the component are periodically polled, and components with state (eg. a pfng-action component) are used in the item's template.

This should help fixing syndesisio/syndesis/issues/3121 where we have exactly this problem.

@patternfly-build
Copy link
Contributor

patternfly-build commented Jul 31, 2018

Deploy preview for patternfly-ng ready!

Built with commit 57cdca0

https://deploy-preview-435--patternfly-ng.netlify.com

@riccardo-forina riccardo-forina force-pushed the fix-list-items-polling branch from 0b187e5 to 6ec1ac8 Compare July 31, 2018 16:20
@riccardo-forina riccardo-forina force-pushed the fix-list-items-polling branch from 6ec1ac8 to 36895b7 Compare July 31, 2018 16:24

protected getTrackBy(index: number, item: any): string {
return `track-${index}`;
}
Copy link
Member

Choose a reason for hiding this comment

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

This function appears to be unused.

OnInit,
Output,
TemplateRef,
TemplateRef, TrackByFunction,
Copy link
Member

Choose a reason for hiding this comment

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

own line?

showCheckbox: false,
useExpandingRows: false
} as ListConfig;
}
Copy link
Member

Choose a reason for hiding this comment

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

Much of this config is duplicated, top of the spec. Can we reuse any of that?

getTrackBy(index: number, item: any): any {
return index;
}

Copy link
Member

Choose a reason for hiding this comment

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

I'd like to see a new trackBy example created instead of altering the basic one. Want to ensure our basic use-case continues to work for existing applications

getTrackBy(index: number, item: any): any {
return index;
}

Copy link
Member

Choose a reason for hiding this comment

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

Please create one, new example for "trackBy". That will help ensure existing applications continue to work as is.

@seanforyou23
Copy link
Contributor

Tested this against Syndesis UI and it works like a charm - nice enhancement

@riccardo-forina
Copy link
Contributor Author

Thanks for the review @dlabrecq! I have made some changes to the code, restored the examples and added a new one.

Copy link
Member

@dlabrecq dlabrecq left a comment

Choose a reason for hiding this comment

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

Thank you for creating a new example. Just a couple nits left

<include-content src="src/app/list/basic-list/example/list-basic-example.component.html"></include-content>
</tab>
<tab heading="typescript">
<include-content src="src/app/list/basic-list/example/list-basic-example.component.ts"></include-content>
Copy link
Member

Choose a reason for hiding this comment

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

In order to show the correct example, these two links should use list-polling-example.component.ts instead of list-basic-example.component.ts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah! Good catch, thanks!

useExpandItems: true
} as ListConfig;

this.updateItemsInterval = setInterval(() => this.updateItems(), 2500);
Copy link
Member

Choose a reason for hiding this comment

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

I'm seeing an error in my IDE, which states "Type 'Timer' is not assignable to type 'number'. However, using this seems to work:

updateItemsInterval: number = <any>setInterval(() => {});

See TypeStrong/atom-typescript#1053

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had it too but assumed it was something specific to my IDE (WebStorm). I'll update this to use any then.

Copy link
Member

@dlabrecq dlabrecq left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for the contribution!

@dlabrecq dlabrecq merged commit 1ad5101 into patternfly:master Aug 3, 2018
@riccardo-forina riccardo-forina deleted the fix-list-items-polling branch August 6, 2018 07:27
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants