Created
September 20, 2018 02:49
-
-
Save Sawtaytoes/b342fc7fd8812d27ab6fdcc3cc0a7582 to your computer and use it in GitHub Desktop.
Introductory listener using an observable
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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