How to use @sanity/mutator - 10 common examples

To help you get started, we’ve selected a few @sanity/mutator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github sanity-io / sanity / packages / @sanity / form-builder / examples / schema-testbed / components / SchemaForm.js View on Github external
function logPatch(patch) {
  const {type, path, ...rest} = patch
  console.log(
    // eslint-disable-line no-console
    '%c%s%c %s =>',
    'color:#2097ac',
    type,
    'color:inherit',
    arrayToJSONMatchPath(path || []),
    rest
  )
}
github sanity-io / sanity / packages / @sanity / base / src / datastores / document / buffered-doc / createObservableBufferedDocument.ts View on Github external
// we received a new snapshot and already got an old one. When we receive a snapshot again
          // it is usually because the connection has been down. Attempt to save pending changes (if any)
          bufferedDocument.commit()
        }
        return createInitialBufferedDocument(listenerEvent.document || null)
      }
      if (bufferedDocument === null) {
        // eslint-disable-next-line no-console
        console.warn(
          'Ignoring event of type "%s" since buffered document has not yet been set up with snapshot',
          listenerEvent.type
        )
        return null
      }
      if (listenerEvent.type === 'mutation') {
        bufferedDocument.arrive(new Mutation(listenerEvent))
      } else if (listenerEvent.type !== 'reconnect') {
        // eslint-disable-next-line no-console
        console.warn('Received unexpected server event of type "%s"', listenerEvent.type)
      }
      return bufferedDocument
    }, null),
    publishReplay(1),
github sanity-io / sanity / packages / @sanity / document-store / src / createObservableBufferedDocument.js View on Github external
// we received a new snapshot and already got an old one. When we receive a snapshot again
          // it is usually because the connection has been down. Attempt to save pending changes (if any)
          bufferedDocument.commit()
        }
        return createInitialBufferedDocument(serverEvent.document || null)
      }
      if (!bufferedDocument) {
        // eslint-disable-next-line no-console
        console.warn(
          'Ignoring event of type "%s" since buffered document has not yet been set up with snapshot',
          serverEvent.type
        )
        return bufferedDocument
      }
      if (serverEvent.type === 'mutation') {
        bufferedDocument.arrive(new Mutation(serverEvent))
      } else if (serverEvent.type !== 'reconnect') {
        // eslint-disable-next-line no-console
        console.warn('Received unexpected server event of type "%s"', serverEvent.type)
      }
      return bufferedDocument
    }, null),
    publishReplay(1),
github sanity-io / sanity / packages / test-studio / src / mockDocStateDatastore.js View on Github external
mutate: (id, mutations) => {
    const current = get(id)
    const target = current.isLiveEdit ? current.published : current.draft
    const nextDoc = new Mutation({
      mutations: mutations.map(setPatchId(target._id))
    }).apply(target)

    return update(id, {
      ...current,
      published: current.isLiveEdit ? nextDoc : current.published,
      draft: current.isLiveEdit ? current.draft : nextDoc,
      deleted: false
    })
  },
  duplicate: (id, dupeId, prepare) => {
github sanity-io / sanity / packages / @sanity / base / src / datastores / document / buffered-doc / createObservableBufferedDocument.ts View on Github external
tap(([action, bufferedDocument]) => {
      if (action.type === 'mutation') {
        bufferedDocument.add(new Mutation({mutations: action.mutations}))
      }
      if (action.type === 'commit') {
        bufferedDocument.commit()
      }
    }),
    mergeMapTo(NEVER),
github sanity-io / sanity / packages / @sanity / document-store / src / createObservableBufferedDocument.js View on Github external
map(([action, bufferedDocument]) => {
      if (action.type === 'mutation') {
        bufferedDocument.add(new Mutation({mutations: action.mutations}))
      }
      if (action.type === 'commit') {
        bufferedDocument.commit()
      }
      return null
    }),
    filter(Boolean),
github sanity-io / sanity / src / inputs / Reference / common / ValueContainer.js View on Github external
getAttribute(key) {
    return new ImmutableAccessor(this.value[key])
  }
github sanity-io / sanity / packages / @sanity / form-builder / src / inputs / Object / ObjectContainer.js View on Github external
getAttribute(key) {
    if (key === '_key') {
      return new ImmutableAccessor(this.key)
    }
    if (key === '_id') {
      return new ImmutableAccessor(this.value._id)
    }
    return this.value[key]
  }
github sanity-io / sanity / packages / @sanity / block-editor / src / accessors.js View on Github external
getAttribute(attr) {
    if (attr === '_type') {
      return new ImmutableAccessor('textspan')
    }
    if (attr === 'content') {
      return new ImmutableAccessor(this.content)
    }
    if (attr === 'marks') {
      return new ImmutableAccessor(this.marks)
    }
    throw new Error(`Unknown key "${attr}"`)
  }

@sanity/mutator

A set of models to make it easier to utilize the powerful real time collaborative features of Sanity

MIT
Latest version published 6 days ago

Package Health Score

98 / 100
Full package analysis