Skip to content

Commit

Permalink
+Mᐁ includes
Browse files Browse the repository at this point in the history
  • Loading branch information
devlooped-bot authored and kzu committed Aug 8, 2022
1 parent 48b15d8 commit 555590f
Showing 1 changed file with 88 additions and 1 deletion.
89 changes: 88 additions & 1 deletion src/RxFree/readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,90 @@
<!-- include ../../readme.md#content -->
<!-- #content -->
An ultra-lightweight Rx source-only (C#) nuget to avoid depending on the full
[System.Reactive](https://www.nuget.org/packages/System.Reactive) for `IObservable<T>`
producers.

<!-- include ../../docs/footer.md -->
100% dependency-free (source-based) support for library authors exposing IObservable&lt;T&gt; leveraging
Subject&lt;T&gt;, CompositeDisposable, IObservable&lt;T&gt;.Subscribe extension method overloads,
IObservable&lt;T&gt;.Select/Where/OfType LINQ operators, and others.

# Usage

All of the documentation and samples for `Subject<T>` and the provided extension methods
(i.e. `Subscribe` overloads) that are officially available for `System.Reactive` apply to
this project as well, since the implementations are heavily based on it (taking them to
the bare essentials for source-only inclusion, with `Subject<T>` being pretty much exactly
the same).
For example: [Using Subjects](https://docs.microsoft.com/en-us/previous-versions/dotnet/reactive-extensions/hh242970(v=vs.103)).

```csharp
using System;
using System.Reactive.Subjects;

var subject = new Subject<string>();

subject.Subscribe(x => Console.WriteLine($"Got raw value {x}"));

subject.Where(x => int.TryParse(x, out _))
.Select(x => int.Parse(x))
.Subscribe(x => Console.WriteLine($"Got number {x} (squared is {x * x})"));

subject.Where(x => bool.TryParse(x, out var value) && value)
.Subscribe(x => Console.WriteLine($"Got a boolean True"));

while (Console.ReadLine() is var line && !string.IsNullOrEmpty(line))
subject.OnNext(line);
```

This package is a drop-in replacement for `System.Reactive` if you are only using the
most common subset of features in it that are also provided in this project.

# Why

For the most part, a producer needs the `Subject<T>` (read more about
[using subjects](https://docs.microsoft.com/en-us/previous-versions/dotnet/reactive-extensions/hh242970(v=vs.103)))
and maybe the `ObservableExtensions` that provide `Subscribe` overloads to provide
lambdas instead of an `IObserver<T>`. Taking the somewhat large and heavy dependency
on the full [System.Reactive](https://www.nuget.org/packages/System.Reactive) to consume
just the basics a reusable library needs is overkill in most cases.

In addition to `Subject<T>`, typical activities of a producer are to handle disposables
and potentially filter/query/convert other observables they consume themselves.
So the following simple features are provided:

- `Disposable.Empty` and `Disposable.Create(Action)`
- `CompositeDisposable`: allows disposing subscriptions as a group
- `Subject<T>`: for producing observable sequences
- Extension methods for `IObservable<T>`:
* `Subscribe` overloads receiving delegates for onNext, onError and onCompleted
* `Select`/`Where`/`OfType` LINQ operators

This is what this project provides at the moment, in source form, in your project, as internal
classes for your own implementation usage, with no external dependencies. They are not even
visible in the project since NuGet provides them automatically to the compiler, embedded into
your own assembly, and which you can fully debug as any other code in your project.

<!-- #content -->
<!-- ../../readme.md#content -->

<!-- include ../../docs/footer.md -->
# Sponsors

<!-- sponsors.md -->
[![Kirill Osenkov](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/KirillOsenkov.png "Kirill Osenkov")](https://github.com/KirillOsenkov)
[![C. Augusto Proiete](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/augustoproiete.png "C. Augusto Proiete")](https://github.com/augustoproiete)
[![SandRock](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/sandrock.png "SandRock")](https://github.com/sandrock)
[![Amazon Web Services](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/aws.png "Amazon Web Services")](https://github.com/aws)
[![Christian Findlay](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/MelbourneDeveloper.png "Christian Findlay")](https://github.com/MelbourneDeveloper)
[![Clarius Org](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/clarius.png "Clarius Org")](https://github.com/clarius)
[![MFB Technologies, Inc.](https://raw.githubusercontent.com/devlooped/sponsors/main/.github/avatars/MFB-Technologies-Inc.png "MFB Technologies, Inc.")](https://github.com/MFB-Technologies-Inc)


<!-- sponsors.md -->

[![Sponsor this project](https://raw.githubusercontent.com/devlooped/sponsors/main/sponsor.png "Sponsor this project")](https://github.com/sponsors/devlooped)
&nbsp;

[Learn more about GitHub Sponsors](https://github.com/sponsors)

<!-- ../../docs/footer.md -->

0 comments on commit 555590f

Please sign in to comment.