Skip to content

Instantly share code, notes, and snippets.

@cdaringe
Created February 3, 2017 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdaringe/1f2aa8ee1adeef2a291b75870308022a to your computer and use it in GitHub Desktop.
Save cdaringe/1f2aa8ee1adeef2a291b75870308022a to your computer and use it in GitHub Desktop.
vscode-hover-wrong-variable-data.js
// install rxjs
// configure vscode to run this file
const Rx = require('rxjs')
const { Observable } = Rx
const EventEmitter = require('events')
const myEmitter = new EventEmitter()
const START_REGISTRATIONS_POLL = 'START_REGISTRATIONS_POLL'
const STOP_REGISTRATIONS_POLL = 'STOP_REGISTRATIONS_POLL'
function onPollRequest (observer) {
myEmitter.on(
START_REGISTRATIONS_POLL,
() => {
observer.next({ type: START_REGISTRATIONS_POLL })
}
)
myEmitter.on(
STOP_REGISTRATIONS_POLL,
() => {
observer.next({ type: STOP_REGISTRATIONS_POLL })
setTimeout(() => observer.complete())
}
)
}
// actions to actions
// START_POLL to SET_REG
//
const obs = Rx.Observable.create(onPollRequest)
.switchMap(action$ => {
return Observable.interval(2000) // 0, 1, 2
.startWith(-1)
// .subscribe() // -1, 0, 1, 2
.mergeMap(i => {
return Observable.of(null).delay(100)
.map(j => ({ i, type: 'FAKE_SET_REGISTRATIONS' }))
})
.takeWhile(action => {
debugger // hover `action$` below
return action$.type ?
action$.type !== STOP_REGISTRATIONS_POLL :
true
})
})
obs.subscribe(val => {
console.log(`value: ${JSON.stringify(val)}`)
})
myEmitter.emit(START_REGISTRATIONS_POLL)
setTimeout(() => {
myEmitter.emit(STOP_REGISTRATIONS_POLL)
}, 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment