question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Action on multiple views

See original GitHub issue

It is a suggestion/question to get feedback on idea of applying action onto multiple views instead of a single right now. Sometimes it is needed to disable/enable multiple views based on a property change (e.g. Observable<Boolean>). If we have 3-4 views to control it we would need to write setEnabled for each one, instead of listing what views to disable.

We could do something like this:

@SafeVarargs
public static Action1<? super Boolean> allOf(Action1<? super Boolean>... actions) {
    return t -> {
        for (Action1<? super Boolean> action : actions) {
            action.call(t);
        }
    };
}

Then we have following:

// before
viewModel.isLoading.subscribe(isLoading -> {
    email.setEnabled(!isLoading);
    password.setEnabled(!isLoading);
});

// after
viewModel.isLoading.map(isLoading -> !isLoading).subscribe(allOf(RxView.enabled(email), RxView.enabled(password)));

Any thoughts/feedback?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
JakeWhartoncommented, Mar 18, 2016

I’ll be very resistant adding it to RxBinding since it seems more appropriate as a generic thing for combining any RxJava Actions bounded by the same type. The advantages there are that you can optimize implementations for low counts and avoid the loop in the implementation as well as the array allocation for making the varargs method call. It also would allow you to combine multiple actions from unrelated views into a single stream (like two enabled’s, a checked, and a selected, for example).

I would encourage you (or someone) to pursue this as a standalone project whose sole goal was the combination of the various Action1 interfaces into helpers like Action1s.combine(a, b, c) or something.

0reactions
Zhuindencommented, Mar 20, 2016

Well they are similar, but @VladimirLichonos 's library handles more cases. Mostly multi-parameter generic support seems to be the primary difference.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Asp.Net MVC can have one action method for multiple views?
No you cant have multiple views returned from single action. In case you want in that way then, you can do it like...
Read more >
MVC Action Method - Multiple Views - Stack Overflow
Yes, completely possible. And, it can be multiple views, or even a FileResult or other result type.
Read more >
Create a View in ASP.NET MVC - TutorialsTeacher
A controller can have one or more action methods, and each action method can return a different view. In short, a controller can...
Read more >
MVC Action Method - Multiple Views - CodeProject
hi to all, i am having same view with two different names i.e ContactUs, Enquirenow. for ContactUs View having layout,other one is no....
Read more >
Multiple Models in Single View in MVC - C# Corner
There are many ways to use multiple models with a single view. ... We can render some part of a view by calling...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found