@@ -131,15 +131,7 @@ export class SelectionModel<T> {
131
131
* Determines whether a value is selected.
132
132
*/
133
133
isSelected ( value : T ) : boolean {
134
- if ( this . compareWith ) {
135
- for ( const otherValue of this . _selection ) {
136
- if ( this . compareWith ( otherValue , value ) ) {
137
- return true ;
138
- }
139
- }
140
- return false ;
141
- }
142
- return this . _selection . has ( value ) ;
134
+ return this . _selection . has ( this . _getConcreteValue ( value ) ) ;
143
135
}
144
136
145
137
/**
@@ -191,6 +183,7 @@ export class SelectionModel<T> {
191
183
192
184
/** Selects a value. */
193
185
private _markSelected ( value : T ) {
186
+ value = this . _getConcreteValue ( value ) ;
194
187
if ( ! this . isSelected ( value ) ) {
195
188
if ( ! this . _multiple ) {
196
189
this . _unmarkAll ( ) ;
@@ -208,6 +201,7 @@ export class SelectionModel<T> {
208
201
209
202
/** Deselects a value. */
210
203
private _unmarkSelected ( value : T ) {
204
+ value = this . _getConcreteValue ( value ) ;
211
205
if ( this . isSelected ( value ) ) {
212
206
this . _selection . delete ( value ) ;
213
207
@@ -238,6 +232,20 @@ export class SelectionModel<T> {
238
232
private _hasQueuedChanges ( ) {
239
233
return ! ! ( this . _deselectedToEmit . length || this . _selectedToEmit . length ) ;
240
234
}
235
+
236
+ /** Returns a value that is comparable to inputValue by applying compareWith function, returns the same inputValue otherwise. */
237
+ private _getConcreteValue ( inputValue : T ) : T {
238
+ if ( ! this . compareWith ) {
239
+ return inputValue ;
240
+ } else {
241
+ for ( let selectedValue of this . _selection ) {
242
+ if ( this . compareWith ! ( inputValue , selectedValue ) ) {
243
+ return selectedValue ;
244
+ }
245
+ }
246
+ return inputValue ;
247
+ }
248
+ }
241
249
}
242
250
243
251
/**
0 commit comments