* Convert `treeData` into entity records.
(dataNodes)
| 120627 | */ |
| 120628 | |
| 120629 | function convertDataToEntities(dataNodes) { |
| 120630 | var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, |
| 120631 | initWrapper = _ref.initWrapper, |
| 120632 | processEntity = _ref.processEntity, |
| 120633 | onProcessFinished = _ref.onProcessFinished, |
| 120634 | externalGetKey = _ref.externalGetKey, |
| 120635 | childrenPropName = _ref.childrenPropName; |
| 120636 | |
| 120637 | var |
| 120638 | /** @deprecated Use `config.externalGetKey` instead */ |
| 120639 | legacyExternalGetKey = arguments.length > 2 ? arguments[2] : undefined; |
| 120640 | // Init config |
| 120641 | var mergedExternalGetKey = externalGetKey || legacyExternalGetKey; |
| 120642 | var posEntities = {}; |
| 120643 | var keyEntities = {}; |
| 120644 | var wrapper = { |
| 120645 | posEntities: posEntities, |
| 120646 | keyEntities: keyEntities |
| 120647 | }; |
| 120648 | |
| 120649 | if (initWrapper) { |
| 120650 | wrapper = initWrapper(wrapper) || wrapper; |
| 120651 | } |
| 120652 | |
| 120653 | traverseDataNodes(dataNodes, function (item) { |
| 120654 | var node = item.node, |
| 120655 | index = item.index, |
| 120656 | pos = item.pos, |
| 120657 | key = item.key, |
| 120658 | parentPos = item.parentPos, |
| 120659 | level = item.level; |
| 120660 | var entity = { |
| 120661 | node: node, |
| 120662 | index: index, |
| 120663 | key: key, |
| 120664 | pos: pos, |
| 120665 | level: level |
| 120666 | }; |
| 120667 | var mergedKey = getKey(key, pos); |
| 120668 | posEntities[pos] = entity; |
| 120669 | keyEntities[mergedKey] = entity; // Fill children |
| 120670 | |
| 120671 | entity.parent = posEntities[parentPos]; |
| 120672 | |
| 120673 | if (entity.parent) { |
| 120674 | entity.parent.children = entity.parent.children || []; |
| 120675 | entity.parent.children.push(entity); |
| 120676 | } |
| 120677 | |
| 120678 | if (processEntity) { |
| 120679 | processEntity(entity, wrapper); |
| 120680 | } |
| 120681 | }, { |
| 120682 | externalGetKey: mergedExternalGetKey, |
| 120683 | childrenPropName: childrenPropName |
| 120684 | }); |
| 120685 | |
| 120686 | if (onProcessFinished) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…