A compendium of Reactive-like utilities to help build better Apple platform apps in Swift.
Currently features a minimalistic API for generalized Swift publish/subscribe, further development will be based on needs and demand.
MiniRex is currently being developed on Xcode 10.2, using Apple's latest SDK and Swift 5.
It's been used and tested on latest versions of macOS 10.14 and iOS 12, but should work without changes on top of any other apple platform SDK since it only depends on Foundation. It's also currently being deployed on at least one mac app store released product that supports macOS 10.11 and up.
It should also work with minimal changes on any older Apple OS which supports Swift deployment (currently macOS 10.9+ and iOS 7+).
Carthage is the recommended approach to integrate MiniRex on an existing project. It works fine if set up with the project's github URL.
Or just get it through CocoaPods if that's your thing. Pod name is "MiniRex"
One can also just clone the repo whenever it works best for your project setup, either as a submodule or as a sibling repository.
MiniRex only depends on Foundation and the Swift standard library so you can easily add the framework straight to your project. You'll need to perform the following steps:
The whole API is based on the Publisher template protocol, which has a single method that takes in a callback that gets called with a parameter of type Publisher.Update and returns a Subscription object.
The Subscription objects are used to manage the lifetime of the subscription. They will either end the subscription when deallocated or when its invalidate() method is called.
A few basic rules on further usage:
Broadcaster<Update>Offer no guarantees for when updates are called. Examples are notification publishers. event publishers or publishers that update subscribers on a repeating timer. Examples include notification broadcaster adapters and the
Published<Value>These are vending a specific type of value. Subscribing to them will always trigger an initial update callback with the value current at the time of subscription (this call need not be synchronous although it could be). Further update calls will happen as the published value changes.
Equatablevalues will only update subscribers when their value change, non-equatable reference types when their identity changes. Examples include KVO publishers which include the .initial KVO observation option, and the PublishedProperty class'
A number of pre-built Utilities are also included for ease of adoption:
Published<Value>will preserve equality/identity semantics when possible. The ones for
Broadcaster<Update>will just post the transformed update values.
Broadcaster, to easily adapt traditional Foundation notifications into MiniRex API.
Published<Value>types), to easily adapt KVO observation into MiniRex API.
Published<Value>that just sends back an immutable value to new subscribers. Useful for testing purposes and stub implementation of published value-vending protocols.
Published<Value>that updates its subscribers when it changes. The semantics of Publish/Subscribe imply reference, and besides the act of subscribing/unsubscribing require modification of the ultimate publisher source, so it has to be a class instead of a struct.
While this framework is not based on particularly revolutionary ideas, I would love for it to be useful to a wide variety of developers. If you feel a particular improvement would make it more so please let me know.
Equatableand reference types.
Copyright 2018-2019 Óscar Morales Vivó
Licensed under the MIT License: http://www.opensource.org/licenses/mit-license.php
|Last commit: 6 days ago|
Turns out both for testing and degenerate cases we ought to have an easy way to create a task that just returns a predefined result (not unlike