const equals = (itemA, itemB) => Object.keys(itemA).every(key => itemA[key] === itemB[key])

const get = (doc, path, defValue) => {
  const result = path.reduce((item, segment) => {
    if (!item) {
      return item
    }

    if (typeof segment !== 'object') {
      return item[segment]
    }

    return Array.isArray(item) ? item.find(curr => equals(segment, curr)) : undefined
  }, doc)

  return typeof result === 'undefined' ? defValue : result
}

export default {
  name: 'experiment',
  type: 'object',
  fields: [
    {
      name: 'title',
      title: 'Title',
      type: 'string'
    },
    {
      name: 'slug',
      title: 'Slug',
      type: 'slug',
      options: {
        source: (doc, {parentPath}) => get(doc, parentPath, {}).title
      }
    }
  ]
}

@@ -1,460 +1,4 @@
-const equals = (itemA, itemB) =%3E Object.keys(itemA).every(key =%3E itemA%5Bkey%5D === itemB%5Bkey%5D)%0A%0Aconst get = (doc, path, defValue) =%3E %7B%0A  const result = path.reduce((item, segment) =%3E %7B%0A    if (!item) %7B%0A      return item%0A    %7D%0A%0A    if (typeof segment !== 'object') %7B%0A      return item%5Bsegment%5D%0A    %7D%0A%0A    return Array.isArray(item) ? item.find(curr =%3E equals(segment, curr)) : undefined%0A  %7D, doc)%0A%0A  return typeof result === 'undefined' ? defValue : result%0A%7D%0A%0A
 expo
@@ -256,42 +256,30 @@
 rent
-Path
 %7D) =%3E 
-get(doc, parentPath, %7B%7D)
+parent && parent
 .tit

Simplify experiment slug schema