Git Product home page Git Product logo

rxcookbook's Introduction

RxCookbook

Collection of recipes and snippets helping you create useful Rx code

Testing Rx

Before we get too excited with Rx, it is a good idea to know how to verify your code first.

Testing Rx

Rx in your Model

See how you can use Rx in your regular domain.

Property Change notifications
Collection Change notifications

Rx for Instrumentation

Use Rx to help instrument your code, or analyse instrumented data from other systems.

Logging

Rx in your repositories

There are common patterns that I see occurring in the repository "layer" in reactive applications.

Polling with Rx
Lazy Connect

Rx with IO

Here we look at different ways to use Rx with various forms in Input/Output.

Disk

Rx can help stream data to and from the disk. I have found that it can greatly reduce complexity while also delivering impressive performance benefits.

Rx Disk IO

Communications

Rx can provide a useful abstraction over numerous communications layers. Here we look at various implementations for different technologies.

TIBCO Rendevous

rxcookbook's People

Contributors

jrsconfitto avatar keichinger avatar leecampbell avatar qooroo avatar smithsoniandsp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxcookbook's Issues

Provide deeper reasoning for SubscribeOn/ObserverOn/Subscribe pattern guidance

There is a fair challenge of the guidance on stackoverflow.
http://stackoverflow.com/questions/34675045/should-subscribeon-and-observeon-only-be-invoked-by-the-final-subscriber/34699242?noredirect=1#comment57305296_34699242

Perhaps showing the work executed on the threads as swimlanes or sequence diagrams might help explain the issue. It may also help illuminate when the guidance can be ignored.

Other resources - http://introtorx.com/Content/v1.0.10621.0/15_SchedulingAndThreading.html

Async Gates and Continuations with Rx

Show how to wait for one event to occur before attempting another event.
Give examples of when this is useful.

  • Waiting for Config/Permissions to be loaded
    • Re-executing when config/permissions change
  • Login before execution
    • Renewing token before expected expiry
  • Getting dependent data for another method call
  • Starting (and Stopping) a service before subscribing to it (leveraging a RefCounted observable, as a field on a singleton, with a finally to call remote/async stop?)

Operators that should be showcased:

  • SelectMany
  • Switch
  • Replay(1) & RefCount()

Unnecessary Observable.Create() in OnPropertyChanges extension method

In one of your recipes, you define an extension method to create an observer for property changes:

public static IObservable<TProperty> OnPropertyChanges<T, TProperty>(this T source, Expression<Func<T, TProperty>> property)
    where T : INotifyPropertyChanged
{
    return  Observable.Create<TProperty>(o=>
    {
        var propertyName = property.GetPropertyInfo().Name;
        var propertySelector = property.Compile();

        return Observable.FromEventPattern<PropertyChangedEventHandler, PropertyChangedEventArgs>(
                        handler => handler.Invoke,
                        h => source.PropertyChanged += h,
                        h => source.PropertyChanged -= h)
                    .Where(e => e.EventArgs.PropertyName == propertyName)
                    .Select(e => propertySelector(source))
                    .Subscribe(o);
    });
}

Is there a reason why you wrap this in a call to Observable.Create() ? If I understand correctly, the only difference this will make is that the two lines of code that get the property name and compile the property selector will be executed for every subscriber, which is not necessary and even hurts performance.

The following code does the same thing and prevents the calls to GetPropertyInfo() and .Compile() for every subscriber:

public static IObservable<TProperty> OnPropertyChanges<T, TProperty>(this T source, Expression<Func<T, TProperty>> property)
    where T : INotifyPropertyChanged
{
    var propertyName = property.GetPropertyInfo().Name;
    var propertySelector = property.Compile();

    return Observable.FromEventPattern<PropertyChangedEventHandler, PropertyChangedEventArgs>(
                    handler => handler.Invoke,
                    h => source.PropertyChanged += h,
                    h => source.PropertyChanged -= h)
                .Where(e => e.EventArgs.PropertyName == propertyName)
                .Select(e => propertySelector(source));
}

Am I missing something obvious?

Create a UnitTesting recipe

Walk a user through various uses of the TestSchedulers:

  • Advancing time By/To. Create an ExtMeth to take a TimeSpan so we dont always convert to ticks
  • Show the CreateObserver
  • Show the difference between the Create Hot/Cold sequence
  • Experiment with Timers/Buffer/Recursive scheduling

Last-Value cache

The ever popular last value cache.
Often required, poorly implemented.

Potential implementations should/could:

  • Take a single sequence and partition it with group by and cache the last value of each
  • Only cache the last shared value
  • Provide an GetOrAdd(TKey, Func<TKey, IObservable>) method.
  • Allow disposal to trash the whole thing.

ObserveLatestOn

Complete the partially written Model/ObserveLatestOn.md recipe.

FileWatcher sample

Provide help to questions like [http://codereview.stackexchange.com/questions/89961/rx-net-file-watcher]

Walk through the issues with FileSystemWatcher and then link back to polling solution from #22

Stream of bytes/frames to Messages

This question in SO (http://stackoverflow.com/questions/37687605/rx-net-message-parser) asks a very valid question of how do I parse some stream of bytes into messages based on a set of rules. The rules however require knowledge of where you are in parsing logic

  • are you in the header, the body or in between messages?
  • was the previous byte and escape/control character?
  • if you are in the body, was the previous byte that is a control character itself escaped?

Thus basic Rx operators are not enough. You can get so far with Buffer(2,1) but it fails in some edge cases.

It would be good to really clean up the example into a recipe. Perhaps using Stateless as the state machine?

Deep property change notification with the Switch operator

Either show how to build a query that allows a user to observe ObjA.PropB.SubPropC by leaveraging Switch e.g.

ObjA.WhenPropertyChanges(vm=>vm.PropB)
    .Select(b=>b.WhenPropertyChanges(vm=>vm.SubPropC))
    .Switch()  

We could potentially extend this to build an Expression builder so you could just

ObjA.WhenPropertyChanges(vm=>vm.PropB.SubPropC)

Roslyn Analysers for Rx

It would be great to finally create the static code analysis tools that help enforce/catch the Rx Guidelines.

  • Implementing IObservable<T> or IObserver<T>
  • Not disposing
  • Not providing and OnError handler

How to ask an Rx question

Create a post that provides a template of how to ask a CMVE question regarding Rx.

  • Marble diagram
  • input source via testObservables
  • some attempt at the query
  • the expectations

PropertyChanges with Initial value

Extend the INPC samples to also allow for getting the initial value. The difficulty here is providing a thread-safe implementation.
Trying to get the current value and subscribing to the change sequence has an unavoidable race condition.

EventStore

Show an example of using Rx over EventStore

TibRv

Complete the partially completed TibRv recipe

Reference ObserveLatestOn CAS version

James World with Wilka Hudson has produced a CAS implementation of ObserveLatestOn here [http://www.zerobugbuild.com/?p=192].

Add it to the perf tests too

TWAP/VWAP

Create an implementation of TWAP and VWAP. This could be linked to from IntroToRx 17_SequencesOfCoincidence.html#GroupJoin

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.