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