Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Add base interface #123

Open
FinHorsley opened this issue Mar 30, 2020 · 1 comment
Open

feature: Add base interface #123

FinHorsley opened this issue Mar 30, 2020 · 1 comment

Comments

@FinHorsley
Copy link

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

  1. 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 IEvents idea might be a level on top of pharmacist?

  2. RxSwift uses Rx where Pharmacist uses Events by 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);
@open-collective-bot
Copy link

open-collective-bot bot commented Mar 30, 2020

Hey @FinHorsley 👋,

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 priority support for all financial contributors. Don't forget to add priority label once you start contributing 😄

An advanced, composable, functional reactive model-view-viewmodel framework for all .NET platforms!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant