Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dduan/Relay

Stateless alternatives to Combine.Subject
https://github.com/dduan/Relay

combine reactive-programming swiftui

Last synced: about 2 months ago
JSON representation

Stateless alternatives to Combine.Subject

Awesome Lists containing this project

README

        

# Relay

A `Relay` is a `Combine.Subject` without the interface for sending completion
signal.

## Why

A `Subject`, like a `Publisher`, is stateful. Once the complete signal is sent,
subscriber will stop receiving values. In practice, this is rarely desirable:
anyone with a reference to a subject can terminate the data stream for all
subscribers, and that becomes a source of bugs.

`Relay`s take away the mutability of the "completion" state, making it safer to
share.

## Install

### Xcode:

Add package `https://github.com/dduan/Relay.git`.

### [Swift Package Manager](https://swift.org/package-manager)

```swift
.package(url: "http://github.com/dduan/Relay", from: "0.1.2")
```

### [CocoaPods](http://cocoapods.org/):

```ruby
use_frameworks!

pod "CombineRelay"
```

### [Carthage](https://github.com/Carthage/Carthage)

```
github "dduan/Relay"
```

## Usage

Relay provides types that thinly wraps around subject types in Combine:

| Relay | Combine |
|- |- |
| Relay | [Subject][] |
| PassthroughRelay | [PassthroughSubject][] |
| CurrentValueRelay | [CurrentValueSubject][] |

Each type has identical interface and behavior to its Combine counterpart. Except it's impossible to send a
complete signal.

[Subject]: https://developer.apple.com/documentation/combine/subject
[PassthroughSubject]: https://developer.apple.com/documentation/combine/passthroughsubject
[CurrentValueSubject]: https://developer.apple.com/documentation/combine/currentvaluesubject
[AnySubject]: https://developer.apple.com/documentation/combine/anysubject

## License

MIT. See `LICENSE.md`