UNPKG

falcor

Version:

A JavaScript library for efficient data fetching.

21 lines (18 loc) 771 B
/** * Reconstructs the path for the current key, from currentPath (requestedPath) * state maintained during set/merge walk operations. * * During the walk, since the requestedPath array is updated after we attempt to * merge/insert nodes during a walk (it reflects the inserted node's parent branch) * we need to reconstitute a path from it. * * @param {Array} currentPath The current requestedPath state, during the walk * @param {String} key The current key value, during the walk * @return {Array} A new array, with the path which represents the node we're about * to insert */ module.exports = function reconstructPath(currentPath, key) { var path = currentPath.slice(0, currentPath.depth); path[path.length] = key; return path; };