Skip to content

Instantly share code, notes, and snippets.

@Sawtaytoes
Created September 20, 2018 02:49
Show Gist options
  • Save Sawtaytoes/b342fc7fd8812d27ab6fdcc3cc0a7582 to your computer and use it in GitHub Desktop.
Save Sawtaytoes/b342fc7fd8812d27ab6fdcc3cc0a7582 to your computer and use it in GitHub Desktop.
Introductory listener using an observable
import {
BUTTON_DOWN,
singlePressAction,
} from './actions'
const createButtonObserver = bluetoothAddress => observer => (
new FlicConnectionChannel(bluetoothAddress)
.on(
'buttonUpOrDown',
buttonPressState => observer.next(buttonPressState)
)
)
const listenForButtonPress = bluetoothAddress => {
Rx.Observable
.create(
createButtonObserver(bluetoothAddress)
)
.filter(buttonState => buttonState === BUTTON_DOWN)
.subscribe(singlePressAction)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment