Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function timer(initialDelay, period) {
return new Observable(observer => {
let n = 0
let intervalId = -1
const timeoutId = setTimeout(() => {
emitNext()
if (period !== undefined) {
intervalId = setInterval(emitNext, period)
}
}, initialDelay)
function emitNext() {
observer.next(n++)
}
return function dispose() {
clearTimeout(timeoutId)
clearInterval(intervalId)
function listen(id) {
return new Observable(observer => {
observer.next({type: 'welcome', documentId: id})
return globalListener
.filter(event => event.documentId === id)
.debounceTime(2000)
.subscribe(observer)
})
}
import Observable from '@sanity/observable'
function getWindowDimensions() {
return {
height: window.innerHeight,
width: window.innerWidth
}
}
const EVENTS = ['scroll', 'resize']
const scrollObserver = new Observable(observer => {
const listener = () => observer.next(getWindowDimensions())
EVENTS.forEach(eventType => {
document.body.addEventListener(eventType, listener, true)
})
return () => {
EVENTS.forEach(eventType => {
document.body.removeEventListener(eventType, listener, true)
})
}
})
.debounceTime(100)
.share()
export default new Observable(observer => {
observer.next(getWindowDimensions())