Verifies that no two options represent the same value under the compareWith function.
()
| 976 | |
| 977 | /** Verifies that no two options represent the same value under the compareWith function. */ |
| 978 | private _verifyNoOptionValueCollisions() { |
| 979 | this.options.changes.pipe(startWith(this.options), takeUntil(this.destroyed)).subscribe(() => { |
| 980 | const isEqual = this.compareWith ?? Object.is; |
| 981 | for (let i = 0; i < this.options.length; i++) { |
| 982 | const option = this.options.get(i)!; |
| 983 | let duplicate: CdkOption<T> | null = null; |
| 984 | for (let j = i + 1; j < this.options.length; j++) { |
| 985 | const other = this.options.get(j)!; |
| 986 | if (isEqual(option.value, other.value)) { |
| 987 | duplicate = other; |
| 988 | break; |
| 989 | } |
| 990 | } |
| 991 | if (duplicate) { |
| 992 | // TODO(mmalerba): Link to docs about this. |
| 993 | if (this.compareWith) { |
| 994 | console.warn( |
| 995 | `Found multiple CdkOption representing the same value under the given compareWith function`, |
| 996 | { |
| 997 | option1: option.element, |
| 998 | option2: duplicate.element, |
| 999 | compareWith: this.compareWith, |
| 1000 | }, |
| 1001 | ); |
| 1002 | } else { |
| 1003 | console.warn(`Found multiple CdkOption with the same value`, { |
| 1004 | option1: option.element, |
| 1005 | option2: duplicate.element, |
| 1006 | }); |
| 1007 | } |
| 1008 | return; |
| 1009 | } |
| 1010 | } |
| 1011 | }); |
| 1012 | } |
| 1013 | |
| 1014 | /** Verifies that the option values are valid. */ |
| 1015 | private _verifyOptionValues() { |
no test coverage detected