How to use the @sanity/mutator.Mutation function in @sanity/mutator

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 / 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),

@sanity/mutator

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

MIT
Latest version published 3 days ago

Package Health Score

98 / 100
Full package analysis