Pharmacist
Pharmacist copied to clipboard
feature: Add base interface
Describe the solution you'd like
Add an interface that event classes can inherit from.
// A better name may be something like IRx or IReactive?
public interface IEvent<T>
{
T Data { get; }
}
the implementation could then look like the following
public class RxUIControlEvents : IEvent<UIControl>
{
public UIControl Data => _data;
private readonly global::UIKit.UIControl _data;
/// <summary>
/// Initializes a new instance of the <see cref = "global::UIKit.UIControl"/> class.
/// </summary>
/// <param name = "data">The class that is being wrapped.</param>
public RxUIControlEvents(global::UIKit.UIControl data)
{
_data = data;
}
// Event bindings removed for brevity
}
Why would this be useful? This would then make it easy to create static helper methods for updating UI elements based on observables
public static Action<bool> Enabled(this IEvent<UIControl> reactive)
{
return (enabled) =>
{
reactive.Data.Enabled = enabled;
};
}
from the view code (e.g. UIViewController in iOS) this would enable
button = new UIButton();
ViewModel.Command
.CanExecute
.Subscribe(button.Events().Enabled())
.DisposeWith(disp);
Additional Considerations
-
I'm coming from an iOS/Android perspective, so understand that the interface might not apply to all situations; pharmacist is about creating observables from events, so the
IEventsidea might be a level on top of pharmacist? -
RxSwift uses
Rxwhere Pharmacist usesEventsby default; adding the base interface would mean that Pharmacist wouldn't just be for events
Using the example above
ViewModel.Command
.CanExecute
// Confusing as this isn't an event
.Subscribe(button.Events().Enabled())
.DisposeWith(disp);
the Rx naming now makes more sense?
ViewModel.Command
.CanExecute
// More like the RxSwift style
.Subscribe(button.Rx().Enabled())
.DisposeWith(disp);
Hey @FinHorsley :wave:,
Thank you for opening an issue. We will get back to you as soon as we can. Also, check out our Open Collective and consider contributing financially.
https://opencollective.com/reactiveui
PS.: We offer
prioritysupport for all financial contributors. Don't forget to addprioritylabel once you start contributing :smile:
An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms!