Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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})
})
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()
}))
})
}
const getGlobalListener = () => {
if (!_globalListener) {
_globalListener = Observable.from(
client.listen('*[!(_id in path("_.**"))]', {}, {includeResult: false})
).share()
}
return _globalListener
}
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) => {
({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