UNPKG

439 BJavaScriptView Raw
1/**
2 * Given a Path and a key, return a new Path containing the new key.
3 */
4export function addPath(prev, key, typename) {
5 return {
6 prev: prev,
7 key: key,
8 typename: typename
9 };
10}
11/**
12 * Given a Path, return an Array of the path keys.
13 */
14
15export function pathToArray(path) {
16 var flattened = [];
17 var curr = path;
18
19 while (curr) {
20 flattened.push(curr.key);
21 curr = curr.prev;
22 }
23
24 return flattened.reverse();
25}