Skip to content

Instantly share code, notes, and snippets.

@kirkshoop
Created September 6, 2013 15:03
Show Gist options
  • Save kirkshoop/6465077 to your computer and use it in GitHub Desktop.
Save kirkshoop/6465077 to your computer and use it in GitHub Desktop.
Sync subscription to ReactiveCommand that subscribes to accelerometer readings and displays them.
// enable the scenario when enable is executed
from(observable(enable))
.where([this](RoutedEventPattern)
{
return accelerometer != nullptr;
})
.select_many([=](RoutedEventPattern)
{
return from(visible)
.select_many([=](bool)
{
// enable sensor input
return rx::from(readingChanged)
.take_until(invisible);
})
.take_until(endScenario); // this is a subscription to the disable ReactiveCommand
})
.subscribe([this](AccelerometerReading^ reading)
{
// on the ui thread
this->ScenarioOutput_X->Text = reading->AccelerationX.ToString();
this->ScenarioOutput_Y->Text = reading->AccelerationY.ToString();
this->ScenarioOutput_Z->Text = reading->AccelerationZ.ToString();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment