ReactiveCocoa/Loop sits at 76 stars on GitHub, written primarily in Swift. Composable unidirectional data flow with ReactiveSwift.
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
Unidirectional Reactive Architecture. This is a ReactiveSwift counterpart of RxFeedback.
Documentation
Motivation
Requirements for iOS apps have become huge. Our code has to manage a lot of state e.g. server responses, cached data, UI state, routing etc. Some may say that Reactive Programming can help us a lot but, in the wrong hands, it can do even more harm to your code base.
The goal of this library is to provide a simple and intuitive approach to designing reactive state machines.
Core Concepts
State
State is the single source of truth. It represents a state of your system and is usually a plain Swift type (which doesn't contain any ReactiveSwift primitives). Your state is immutable. The only way to transition from one State to another is to emit an Event.
struct Results<T: JSONSerializable> {
let page: Int
let totalResults: Int
let totalPages: Int
let results: [T]
static func empty() -> Results<T> {
return Results<T>(page: 0, totalResults: 0, totalPages: 0, results: [])
}
}
struct Context {
var batch: Results<Movie>
var movies: [Movie]
static var empty: Context {
return Context(batch: Results.empty(), movies: [])
}
}
enum State {
case initial
case paging(context: Context)
case loadedPage(context: Context)
case refreshing(context: Context)
case refreshed(context: Context)
case error(error: NSError, context: Context)
case retry(context: Context)
}
Event
Represents all possible events that can happen in your system which can cause a transition to a new State.
enum Event {
case startLoadingNextPage
case response(Results<Movie>)
case failed(NSError)
case retry
}
Reducer
A Reducer is a pure function with a signature of (State, Event) -> State. While Event represents an action that results in a State change, it's actually not what causes the change. An Event is just that, a representation of the intention to transition from one state to another. What actually causes the State to change, the embodiment of the corresponding Event, is a Reducer. A Reducer is the only place where a State can be changed.
static func reduce(state: State, event: Event) -> State {
switch event {
case .startLoadingNextPage:
return .paging(context: state.context)
case .response(let batch):
var copy = state.context
copy.batch = batch
copy.movies += batch.results
return .loadedPage(context: copy)
case .failed(let error):
return .error(error: error, context: state.context)
case .retry:
return .retry(context: state.context)
}
}
Feedback
While State represents where the system is at a given time, Event represents a trigger for state change, and a Reducer is the pure function that changes the state depending on current state and type of event received, there is not as of yet any type to emit events given a particular current state. That's the job of the Feedback. It's essentially a "processing engine", listening to changes in the current State and emitting the corresponding next events to take place. It's represented by a pure function with a signature of Signal<State, NoError> -> Signal<Event, NoError>. Feedbacks don't directly mutate states. Instead, they only emit events which then cause states to change in reducers.
As you can see from the diagram above we always start with an initial state.
Every change to the State will be then delivered to all Feedback loops that were added to the system.
Feedback then decides whether any action should be performed with a subset of the State (e.g calling API, observe UI events) by dispatching an Event, or ignoring it by returning SignalProducer.empty.
Dispatched Event then goes to the Reducer which applies it and returns a new value of the State.
And then cycle starts all over (see 2).
Example
let increment = Feedback<Int, Event> { _ in
return self.plusButton.reactive
.controlEvents(.touchUpInside)
.map { _ in Event.increment }
}
let decrement = Feedback<Int, Event> { _ in
return self.minusButton.reactive
.controlEvents(.touchUpInside)
.map { _ in Event.decrement }
}
let system = SignalProducer<Int, NoError>.system(initial: 0,
reduce: { (count, event) -> Int in
switch event {
case .increment:
return count + 1
case .decrement:
return count - 1
}
},
feedbacks: [increment, decrement])
label.reactive.text <~ system.map(String.init)
Advantages
TODO
Acknowledgements
This is a community fork of the ReactiveFeedback project (with the MIT license) from Babylon Health.
The most recent commit recorded on ReactiveCocoa/Loop was 8 months ago, based on the GitHub push timestamp. The repository has 5 forks — one of the better signals of community interest.
How many stars does ReactiveCocoa/Loop have?
ReactiveCocoa/Loop has 76 GitHub stars — refresh the page for the live number, or check github.com/ReactiveCocoa/Loop. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What else is in the Mobile space?
ReactiveCocoa/Loop is tracked by TopGit under the Mobile category, alongside 7 GitHub-tagged topics. Trending and Topics pages list peer repositories of comparable stars and language.
What language is ReactiveCocoa/Loop written in?
ReactiveCocoa/Loop is written primarily in Swift. GitHub's language field is based on the largest share of bytes in the default branch.
What topics is ReactiveCocoa/Loop associated with?
GitHub's repository topics for ReactiveCocoa/Loop: "ios", "rac", "reactivecocoa", "reactiveswift", "swift", "swiftui", "unidirectional-data-flow". TopGit's editorial category is Mobile.
Where do I read more about ReactiveCocoa/Loop?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/ReactiveCocoa/Loop is the definitive source.
Why is ReactiveCocoa/Loop categorized under Mobile?
TopGit places ReactiveCocoa/Loop in the Mobile category based on its GitHub topics and description (tagged: "ios", "rac", "reactivecocoa"). Categories are assigned from real repository metadata, not editorial guesswork.
Read full README in the tab above.
Still deciding about Loop?
One click hands the question to an AI along with this page — see what it says about Loop.