-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Changes from 1 commit
6be33d7
076c407
28a17e3
7210a37
7a62a6c
4955161
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,11 @@ export class SelectionModel<T> { | |
return this._selected; | ||
} | ||
|
||
/** Whether multiple values can be selected. */ | ||
get multiple() { | ||
return this._multiple; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a function |
||
|
||
/** Event emitted when the value has changed. */ | ||
onChange: Subject<SelectionChange<T>> | null = this._emitChanges ? new Subject() : null; | ||
|
||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that for usage of the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
this._selected.sort(predicate); | ||
} | ||
} | ||
|
@@ -138,7 +143,7 @@ export class SelectionModel<T> { | |
/** Selects a value. */ | ||
private _markSelected(value: T) { | ||
if (!this.isSelected(value)) { | ||
if (!this._multiple) { | ||
if (!this.multiple) { | ||
this._unmarkAll(); | ||
} | ||
|
||
|
@@ -173,7 +178,7 @@ export class SelectionModel<T> { | |
* including multiple values while the selection model is not supporting multiple values. | ||
*/ | ||
private _verifyValueAssignment(values: T[]) { | ||
if (values.length > 1 && !this._multiple) { | ||
if (values.length > 1 && !this.multiple) { | ||
throw getMultipleValuesInSingleSelectionError(); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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