Latest updates from IceHrmPro
This commit is contained in:
35
web/node_modules/antd/es/table/hooks/useLazyKVMap.js
generated
vendored
Normal file
35
web/node_modules/antd/es/table/hooks/useLazyKVMap.js
generated
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
import * as React from 'react';
|
||||
export default function useLazyKVMap(data, childrenColumnName, getRowKey) {
|
||||
var mapCacheRef = React.useRef({});
|
||||
|
||||
function getRecordByKey(key) {
|
||||
if (!mapCacheRef.current || mapCacheRef.current.data !== data || mapCacheRef.current.childrenColumnName !== childrenColumnName || mapCacheRef.current.getRowKey !== getRowKey) {
|
||||
/* eslint-disable no-inner-declarations */
|
||||
var dig = function dig(records) {
|
||||
records.forEach(function (record, index) {
|
||||
var rowKey = getRowKey(record, index);
|
||||
kvMap.set(rowKey, record);
|
||||
|
||||
if (childrenColumnName in record) {
|
||||
dig(record[childrenColumnName] || []);
|
||||
}
|
||||
});
|
||||
};
|
||||
/* eslint-enable */
|
||||
|
||||
|
||||
var kvMap = new Map();
|
||||
dig(data);
|
||||
mapCacheRef.current = {
|
||||
data: data,
|
||||
childrenColumnName: childrenColumnName,
|
||||
kvMap: kvMap,
|
||||
getRowKey: getRowKey
|
||||
};
|
||||
}
|
||||
|
||||
return mapCacheRef.current.kvMap.get(key);
|
||||
}
|
||||
|
||||
return [getRecordByKey];
|
||||
}
|
||||
Reference in New Issue
Block a user