Giter Site home page Giter Site logo

huoxudong125 / reactiveui Goto Github PK

View Code? Open in Web Editor NEW

This project forked from reactiveui/reactiveui

0.0 2.0 0.0 69.35 MB

A MVVM framework that integrates with the Reactive Extensions for .NET to create elegant, testable User Interfaces that run on any mobile or desktop platform. Supports Xamarin.iOS, Xamarin.Android, Xamarin.Mac, WPF, Windows Forms, Windows Phone 8 and Windows Store apps.

Home Page: http://www.reactiveui.net

License: Microsoft Public License

PowerShell 0.30% C# 99.14% Makefile 0.03% HTML 0.43% Ruby 0.04% Shell 0.07%

reactiveui's Introduction

ReactiveUI Logo ReactiveUI

Release Version NuGet Stats #yourfirstpr Issue Stats Pull Request Stats

Follow us on Twitter Visit our website

Use the Reactive Extensions for .NET to create elegant, testable User Interfaces that run on any mobile or desktop platform. Supports Xamarin.iOS, Xamarin.Android, Xamarin.Mac, Xamarin Forms, WPF, Windows Forms, Windows Phone 8, Windows Store and Universal Windows Platform (UWP).

If you’re already familiar with functional reactive programming or what ReactiveUI is about, check out the documentation for more in-depth information about how it all works or our comprehensive collection of samples.

If you have a question, please see if any discussions in our GitHub issues or Stack Overflow have already answered it. If not, please feel free to file your own!

We have our very own Slack organization which contains some of the best user interface/reactive extension developers in the industry. All software engineers, young and old, regardless of experience are welcome to join our campfire but you'll need to send an email to [email protected] with the email address you'd like to be invited, and we'll send you an invite. Sit tight, it's worth it.

Introduction

ReactiveUI is inspired by functional reactive programming and is the father of the ReactiveCocoa (Cocoa/Swift) framework. Rather than using mutable variables which are replaced and modified in-place, ReactiveUI offers "event streams", represented by the IObserver and IObserverable types, that send values over time.

If you are new to these concepts then we highly recommend watching the following videos before progressing too far:

Fundamentals

One of the most confusing aspects of the Reactive Extensions is that of "hot" and "cold" observables (event streams). In short, given just a method or function declaration like this:

IObservable<string> Search(string query)

It is impossible to tell whether subscribing to (observing) that IObservable will involve side effects. If it does involve side effects, it’s also impossible to tell whether each subscription has a side effect, or if only the first one does. Whilst this example is contrived, it demonstrates a real, pervasive problem that makes it harder at first for new comers to understand Rx code at first glance.

As such we also recommend watching this video, reading our documentation and playing with the marbles to familiarize yourself with the fundamentals.

A Compelling Example

Let’s say you have a text field, and whenever the user types something into it, you want to make a network request which searches for that query.

public interface ISearchViewModel
{
    ReactiveList<SearchResults> SearchResults { get; }
    string SearchQuery { get; }	 
    ReactiveCommand<List<SearchResults>> Search { get; }
    ISearchService SearchService { get; }
}

Define under what conditions a network request will be made

// Here we're describing here, in a *declarative way*, the conditions in
// which the Search command is enabled.  Now our Command IsEnabled is
// perfectly efficient, because we're only updating the UI in the scenario
// when it should change.
var canSearch = this.WhenAny(x => x.SearchQuery, x => !String.IsNullOrWhiteSpace(x.Value));

Make the network connection

// ReactiveCommand has built-in support for background operations and
// guarantees that this block will only run exactly once at a time, and
// that the CanExecute will auto-disable and that property IsExecuting will
// be set according whilst it is running.
Search = ReactiveCommand.CreateAsyncTask(canSearch, async _ => {
    return await searchService.Search(this.SearchQuery);
});

Update the user interface

// ReactiveCommands are themselves IObservables, whose value are the results
// from the async method, guaranteed to arrive on the UI thread. We're going
// to take the list of search results that the background operation loaded, 
// and them into our SearchResults.
Search.Subscribe(results => {
    SearchResults.Clear();
    SearchResults.AddRange(results);
});

Handling failures

// ThrownExceptions is any exception thrown from the CreateAsyncTask piped
// to this Observable. Subscribing to this allows you to handle errors on
// the UI thread. 
Search.ThrownExceptions
    .Subscribe(ex => {
        UserError.Throw("Potential Network Connectivity Error", ex);
    });

Throttling network requests and automatic search execution behaviour

// Whenever the Search query changes, we're going to wait for one second
// of "dead airtime", then automatically invoke the subscribe command.
this.WhenAnyValue(x => x.SearchQuery)
    .Throttle(TimeSpan.FromSeconds(1), RxApp.MainThreadScheduler)
    .InvokeCommand(this, x => x.Search);

Slack

We have our very own Slack organization which contains some of the best user interface/reactive extension developers in the industry. All software engineers, young and old, regardless of experience are welcome to join our campfire but you'll need to send an email to [email protected] with the Email address you'd like to be invited, and we'll send you an invite. Sit tight, it's worth it.

Support

ReactiveUI is an open source project that is community supported by people just like you. We keep a bunch of curated tasks specifically for new contributors which are a great way to get started with open source. They also provide a fantastic avenue for getting to know the ReactiveUI maintainers.

If you have a question, please see if any discussions in our GitHub issues or Stack Overflow have already answered it. If not, please feel free to file your own!

Contribute

Here are some pointers for anyone looking for mini-features and work items that would make a positive contribution to ReactiveUI.

We try not to be too OCD about coding style wars, but we do have our own convention and best design practices documented - please respect them and your pull-request experience will be much smoother. If you are using Visual Studio, please install the rebracer plugin which will automatically apply the correct source formatting settings.

Showcase

We encourage our community to showcase where and how they have used ReactiveUI in their applications, some members have even gone as far as open-sourcing their app and sharing their entire codebase. You are of course under no-obligation share these insights (or code) with us but it is greatly appreciated by the project maintainers and you'll usually get a retweet out of it.

Licensing

The ReactiveUI project is licensed under the MS-PL license.

Acknowledgements

reactiveui's People

Contributors

alanpog avatar ammeep avatar anaisbetts avatar arturire avatar asarium avatar bradtwurst avatar briansakhai avatar bsiegel avatar casnap avatar chrisbednarski avatar distantcam avatar flagbug avatar ghuntley avatar haacked avatar jlaanstra avatar justin-factory avatar kentcb avatar merickowa avatar meteficha avatar niik avatar npnelson avatar oliverw avatar robhorvath avatar shishkin avatar sillyotter avatar srimoyee-factory avatar stanislawswierc avatar tclem avatar thegranduser avatar wendazhou avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.