Path.mjs 439 B

12345678910111213141516171819202122232425
  1. /**
  2. * Given a Path and a key, return a new Path containing the new key.
  3. */
  4. export 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. export function pathToArray(path) {
  15. var flattened = [];
  16. var curr = path;
  17. while (curr) {
  18. flattened.push(curr.key);
  19. curr = curr.prev;
  20. }
  21. return flattened.reverse();
  22. }