Skip to content

Commit

Permalink
[base] Previews: fetch document snapshot immediately, debounce subseq…
Browse files Browse the repository at this point in the history
…uent listener events instead
  • Loading branch information
bjoerge committed Oct 12, 2017
1 parent 655e652 commit 44667a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 31 deletions.
17 changes: 7 additions & 10 deletions packages/@sanity/base/src/preview/observeWithPaths.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,9 @@ const getGlobalListener = () => {
}

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

function fetchAllDocumentSnapshots(selections) {
Expand All @@ -45,6 +40,8 @@ const debouncedFetchDocumentSnapshot = debounceCollect(fetchAllDocumentSnapshots
// }

export default function observePaths(id, paths) {
return listen(id)
.switchMap(event => debouncedFetchDocumentSnapshot(id, paths))
return debouncedFetchDocumentSnapshot(id, paths)
.concat(listen(id)
.debounceTime(1000)
.switchMap(event => debouncedFetchDocumentSnapshot(id, paths)))
}
21 changes: 0 additions & 21 deletions packages/@sanity/form-builder/src/sanity/uploads/uploadImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,6 @@ type Exif = {
const setInitialUploadState$ = Observable.of(INIT_EVENT)
const unsetUploadState$ = Observable.of(CLEANUP_EVENT)

// function mockUpload() {
// return new Observable(observer => {
// let progress = 0
// observer.next({percent: 0})
// const interval = setInterval(next, 20)
//
// function next() {
// progress = Math.min(100, progress + (50 + (Math.random() * 10)))
// observer.next({type: 'progress', percent: progress})
// if (progress === 100) {
// clearInterval(interval)
// observer.next({type: 'complete', percent: progress, asset: {_id: 'image-LNxatfW7KD61pdBPKcgxC7qa-1419x1001-tiff'}})
// setTimeout(() => {
// observer.complete()
// }, 100)
// }
// return () => clearInterval(interval)
// }
// })
// }

export default function uploadImage(file: File): ObservableI<UploadEvent> {
const uploadId = createUploadId(file)

Expand Down

0 comments on commit 44667a0

Please sign in to comment.