This file contains 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
// 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) |
This file contains 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
from(enable->RegisterAsyncFunction( | |
[](RoutedEventPattern) | |
{ | |
// background thread | |
// enable and disable commands will be disabled until this is finished | |
std::this_thread::sleep_for(std::chrono::seconds(2)); | |
return true; | |
})) // this is a subscription to the enable ReactiveCommand |
This file contains 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
template <class O> | |
struct OperationPattern | |
{ | |
typedef decltype(((O)nullptr)->GetDeferral()) D; | |
OperationPattern(O operation) : | |
operation(operation), | |
deferral(operation->GetDeferral()) | |
{ | |
} |
This file contains 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
[](SuspendingEventPattern ep) | |
{ | |
// defer this operation | |
return ep.EventArgs()->SuspendingOperation; | |
} |
This file contains 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
[](rxrt::OperationPattern<SuspendingOperation^>, SuspendingEventPattern) | |
{ | |
// do this while the operation is deferred | |
return SuspensionManager::ReactiveSave(); | |
} | |
This file contains 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
// must take the deferral early while the event is still on the stack. | |
auto op = make_operation_pattern(sop(t)); | |
typedef decltype(op) OP; | |
return Using( | |
// resource factory | |
[=]() | |
{ | |
return op; | |
}, |
This file contains 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
auto ct = std::make_shared<rx::CurrentThreadScheduler>(); | |
typedef rxrt::EventPattern<Platform::Object^, SuspendingEventArgs^> SuspendingEventPattern; | |
rx::from(suspending) | |
.chain<rxrt::defer_operation>( | |
[](SuspendingEventPattern ep) | |
{ | |
// defer this operation | |
return ep.EventArgs()->SuspendingOperation; | |
}, | |
[](rxrt::OperationPattern<SuspendingOperation^>, SuspendingEventPattern) |
This file contains 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
std::shared_ptr<rx::Observable<bool>> SuspensionManager::ReactiveSave(void) | |
{ | |
... | |
// Serialize the session state synchronously to avoid asynchronous access to shared | |
// state | |
auto sessionData = ref new InMemoryRandomAccessStream(); | |
auto sessionDataWriter = ref new DataWriter(sessionData->GetOutputStreamAt(0)); | |
WriteObject(sessionDataWriter, _sessionState); | |
// one-time construction of reactive functions needed to save. |
This file contains 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
typedef rxrt::EventPattern<Object^, Windows::UI::Xaml::RoutedEventArgs^> RoutedEventPattern; | |
// start out disabled | |
enabled = std::make_shared<rx::BehaviorSubject<bool>>(false); | |
// use enabled to control canExecute | |
disable = std::make_shared < rxrt::ReactiveCommand < RoutedEventPattern> >(observable(enabled)); | |
from(observable(disable)) | |
// stay on the ui thread |
NewerOlder