Skip to content

feat(collections): add isMultipleSelection function to SelectionModel #11560

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

Merged
merged 6 commits into from
Jun 7, 2018
Merged

feat(collections): add isMultipleSelection function to SelectionModel #11560

merged 6 commits into from
Jun 7, 2018

Conversation

glenstaes
Copy link
Contributor

@glenstaes glenstaes commented May 29, 2018

If your component receives a SelectionModel instance through Input, it was previously not possible to have different behavior based on whether multiple selected items is allowed (e.g.: rendering radio buttons instead of checkboxes). You had to use a second Input property to the component. This pull request allows developers to check the SelectionModel isMultipleSelection function.

If your component receives a SelectionModel instance through Input, it was previously not possible to have different behavior based on whether multiple selected items is allowed (e.g.: rendering radio buttons instead of checkboxes). You had to use a second Input property to the component. This pull request allows developers to check the SelectionModel instance property.
@googlebot googlebot added the cla: yes PR author has agreed to Google's Contributor License Agreement label May 29, 2018
Copy link
Member

@josephperrott josephperrott left a comment

Choose a reason for hiding this comment

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

Just to the one comment but overall, LGTM.

@@ -111,7 +116,7 @@ export class SelectionModel<T> {
* Sorts the selected values based on a predicate function.
*/
sort(predicate?: (a: T, b: T) => number): void {
if (this._multiple && this._selected) {
if (this.multiple && this._selected) {
Copy link
Member

Choose a reason for hiding this comment

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

I think that for usage of the multiple value within the class that we can continue to just use the internal _multiple reference. This would leave the multiple value as a just a getter

Copy link
Contributor Author

@glenstaes glenstaes May 29, 2018

Choose a reason for hiding this comment

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

Do you want me to revert them? One could also argue that in the future the getter will have a more complex implementation so this change would make it future proof.

Copy link
Member

Choose a reason for hiding this comment

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

For now, yes, it should reference the internal property. If the behavior changes then it could be updated

@josephperrott josephperrott added the target: minor This PR is targeted for the next minor release label May 29, 2018
/** Whether multiple values can be selected. */
get multiple() {
return this._multiple;
}
Copy link
Member

Choose a reason for hiding this comment

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

This should be a function isMultipleSelection instead of a getter; TypeScript generates more code for a getter, so it's preferrable to use a function if you aren't required to use a getter/setter (like with a directive binding)

@@ -33,6 +33,11 @@ export class SelectionModel<T> {
return this._selected;
}

/** Whether multiple values can be selected. */
get multiple() {
Copy link
Member

Choose a reason for hiding this comment

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

There should be a unit test that runs against this public API

@glenstaes glenstaes changed the title feat(collections): Add public getter for _multiple on SelectionModel feat(collections): Add isMultipleSelection function to SelectionModel May 29, 2018
@josephperrott
Copy link
Member

Looks like there are a couple lint errors showing up.

@josephperrott josephperrott added pr: lgtm action: merge The PR is ready for merge by the caretaker labels May 30, 2018
@@ -116,6 +116,13 @@ export class SelectionModel<T> {
}
}

/**
* Determines whether multiple values can be selected.
Copy link
Member

Choose a reason for hiding this comment

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

One last nit: the description should be "Gets whether multiple values can be selected."

Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

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

LGTM

@andrewseguin
Copy link
Contributor

If you can, could you push some new hash so that CircleCI tries to re-run? Would like it to be green before we merge

@glenstaes glenstaes changed the title feat(collections): Add isMultipleSelection function to SelectionModel feat(collections): add isMultipleSelection function to SelectionModel Jun 7, 2018
@glenstaes
Copy link
Contributor Author

@andrewseguin All green now.

@andrewseguin andrewseguin merged commit 0675e05 into angular:master Jun 7, 2018
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes PR author has agreed to Google's Contributor License Agreement target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants