How to use the @sanity/observable.from function in @sanity/observable

To help you get started, we’ve selected a few @sanity/observable 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 / desk-tool / src / pane / EditorWrapper.js View on Github external
handleUnpublish = () => {
    const {documentId} = this.props
    const {published} = this.state

    let tx = client.observable.transaction().delete(getPublishedId(documentId))

    if (published.snapshot) {
      tx = tx.createIfNotExists({
        ...omit(published.snapshot, '_updatedAt'),
        _id: getDraftId(documentId)
      })
    }

    Observable.from(tx.commit())
      .map(result => ({
        type: 'success',
        result: result
      }))
      .catch(error =>
        Observable.of({
          type: 'error',
          message: `An error occurred while attempting to unpublish document.
        This usually means that you attempted to unpublish a document that other documents
        refers to.`,
          error
        })
      )
      .subscribe(result => {
        this.setStateIfMounted({transactionResult: result})
      })
github sanity-io / sanity / packages / @sanity / form-builder / src / sanity / inputs / ReferenceSelect.js View on Github external
function fetchAllForPreview(referenceType) {
  return Observable.from(search('*', referenceType))
    .switchMap(items => {
      return Observable.forkJoin(items.map(item => {
        const memberType = referenceType.to.find(ofType => ofType.type.name === item._type)
        return observeForPreview(item, memberType)
          .map(result => result.snapshot)
          .first()
      }))
    })
}
github sanity-io / sanity / packages / @sanity / preview / src / observeWithPaths.js View on Github external
const getGlobalListener = () => {
  if (!_globalListener) {
    _globalListener = Observable.from(
      client.listen('*[!(_id in path("_.**"))]', {}, {includeResult: false})
    ).share()
  }
  return _globalListener
}
github sanity-io / sanity / packages / @sanity / base / src / preview / observeWithPaths.js View on Github external
import client from 'part:@sanity/base/client'
import Observable from '@sanity/observable'
import debounceCollect from './utils/debounceCollect'

const globalListener = Observable
  .from(client.listen('*[!(_id in path("_.**"))]', {}, {includeResult: false}))
  .share()

function listen(id) {
  return new Observable(observer => {
    observer.next({type: 'welcome', documentId: id})
    return globalListener
      .filter(event => event.documentId === id)
      .debounceTime(2000)
      .subscribe(observer)
  })
}

function fetchAllDocumentSnapshots(selections) {
  const optimizedParams = {}
  const queryParts = selections.map(([id, paths], queryIndex) => {
github sanity-io / sanity / packages / @sanity / form-builder / src / sanity / uploads / uploadQueue.js View on Github external
({uploadId, file}) => new Observable(observer => {
      const upload = Observable.from(uploadImageAsset(file)).share()
      const registrySubscription = upload.subscribe(registry[uploadId]._multicast)
      const uploadSubscription = upload.subscribe(observer)
      return () => {
        registrySubscription.unsubscribe()
        uploadSubscription.unsubscribe()
      }
    }),
    CONCURRENCY

@sanity/observable

[deprecated] This package exists for legacy reasons only

MIT
Latest version published 4 years ago

Package Health Score

78 / 100
Full package analysis