UNPKG

1.83 kBJavaScriptView Raw
1/*
2 * Copyright 2018 Palantir Technologies, Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { Utils } from "@blueprintjs/core";
17/**
18 * Utility function for executing the {@link IListItemsProps#itemsEqual} prop to test
19 * for equality between two items.
20 *
21 * @return `true` if the two items are equivalent according to `itemsEqualProp`.
22 */
23export function executeItemsEqual(itemsEqualProp, itemA, itemB) {
24 // Use strict equality if:
25 // A) Default equality check is necessary because itemsEqualProp is undefined.
26 // OR
27 // B) Either item is null/undefined. Note that null represents "no item", while
28 // undefined represents an uncontrolled prop. This strict equality check ensures
29 // nothing will ever be considered equivalent to an uncontrolled prop.
30 if (itemsEqualProp === undefined || itemA == null || itemB == null) {
31 return itemA === itemB;
32 }
33 if (Utils.isFunction(itemsEqualProp)) {
34 // itemsEqualProp is an equality comparator function, so use it
35 return itemsEqualProp(itemA, itemB);
36 }
37 else {
38 // itemsEqualProp is a property name, so strictly compare the values of the property.
39 return itemA[itemsEqualProp] === itemB[itemsEqualProp];
40 }
41}
42//# sourceMappingURL=listItemsProps.js.map
\No newline at end of file