Skip to content

Commit

Permalink
Rename FeedbackLoop to Feedback. (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersio authored Oct 18, 2017
1 parent e1b6ced commit 70596cf
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
16 changes: 8 additions & 8 deletions Example/PaginationViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ final class PaginationViewModel {
}

enum Feedbacks {
static func loadNextFeedback(for nearBottomSignal: Signal<Void, NoError>) -> FeedbackLoop<State, Event> {
return FeedbackLoop(predicate: { !$0.paging }) { _ in
static func loadNextFeedback(for nearBottomSignal: Signal<Void, NoError>) -> Feedback<State, Event> {
return Feedback(predicate: { !$0.paging }) { _ in
return nearBottomSignal
.map { Event.startLoadingNextPage }
}
}

static func pagingFeedback() -> FeedbackLoop<State, Event> {
return FeedbackLoop<State, Event>(query: { $0.nextPage }) { (nextPage) -> SignalProducer<Event, NoError> in
static func pagingFeedback() -> Feedback<State, Event> {
return Feedback<State, Event>(query: { $0.nextPage }) { (nextPage) -> SignalProducer<Event, NoError> in
return URLSession.shared.fetchMovies(page: nextPage)
.map(Event.response)
.flatMapError { (error) -> SignalProducer<Event, NoError> in
Expand All @@ -128,14 +128,14 @@ final class PaginationViewModel {
}
}

static func retryFeedback(for retrySignal: Signal<Void, NoError>) -> FeedbackLoop<State, Event> {
return FeedbackLoop<State, Event>(query: { $0.lastError }) { _ -> Signal<Event, NoError> in
static func retryFeedback(for retrySignal: Signal<Void, NoError>) -> Feedback<State, Event> {
return Feedback<State, Event>(query: { $0.lastError }) { _ -> Signal<Event, NoError> in
return retrySignal.map { Event.retry }
}
}

static func retryPagingFeedback() -> FeedbackLoop<State, Event> {
return FeedbackLoop<State, Event>(query: { $0.retryPage }) { (nextPage) -> SignalProducer<Event, NoError> in
static func retryPagingFeedback() -> Feedback<State, Event> {
return Feedback<State, Event>(query: { $0.retryPage }) { (nextPage) -> SignalProducer<Event, NoError> in
return URLSession.shared.fetchMovies(page: nextPage)
.map(Event.response)
.flatMapError { (error) -> SignalProducer<Event, NoError> in
Expand Down
4 changes: 2 additions & 2 deletions Example/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ final class ViewModel {

init(increment: Signal<Void, NoError>, decrement: Signal<Void, NoError>) {

let incrementFeedback = FeedbackLoop<Int, Event>(predicate: {
let incrementFeedback = Feedback<Int, Event>(predicate: {
return $0 < 10
}) { state in
return increment.map { _ in Event.increment }
}

let decrementFeedback = FeedbackLoop<Int, Event>(predicate: { return $0 > -10 }) { _ in
let decrementFeedback = Feedback<Int, Event>(predicate: { return $0 > -10 }) { _ in
return decrement.map { _ in Event.decrement }
}

Expand Down
8 changes: 4 additions & 4 deletions ReactiveFeedback.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

/* Begin PBXBuildFile section */
25CC87BB1F92859800A6EBFC /* SignalProducer+System.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25E1D2331F54951100D90192 /* SignalProducer+System.swift */; };
25CC87BC1F92859800A6EBFC /* FeedbackLoops.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25E1D2351F54A20F00D90192 /* FeedbackLoops.swift */; };
25CC87BC1F92859800A6EBFC /* Feedback.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25E1D2351F54A20F00D90192 /* Feedback.swift */; };
25E1D2211F5493D000D90192 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25E1D2201F5493D000D90192 /* AppDelegate.swift */; };
25E1D2231F5493D000D90192 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 25E1D2221F5493D000D90192 /* ViewController.swift */; };
25E1D2261F5493D000D90192 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 25E1D2241F5493D000D90192 /* Main.storyboard */; };
Expand Down Expand Up @@ -96,7 +96,7 @@
25E1D22A1F5493D000D90192 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
25E1D22C1F5493D000D90192 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
25E1D2331F54951100D90192 /* SignalProducer+System.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SignalProducer+System.swift"; sourceTree = "<group>"; };
25E1D2351F54A20F00D90192 /* FeedbackLoops.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FeedbackLoops.swift; sourceTree = "<group>"; };
25E1D2351F54A20F00D90192 /* Feedback.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Feedback.swift; sourceTree = "<group>"; };
25E1D2371F56091A00D90192 /* PaginationViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaginationViewController.swift; sourceTree = "<group>"; };
9A4CCB0C1F95D5CA00ACF758 /* Nimble.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = Nimble.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9AE181B61F95A71B00A07551 /* ReactiveFeedbackTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ReactiveFeedbackTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -149,8 +149,8 @@
isa = PBXGroup;
children = (
25E1D2331F54951100D90192 /* SignalProducer+System.swift */,
25E1D2351F54A20F00D90192 /* FeedbackLoops.swift */,
25CC87B11F92855300A6EBFC /* Info.plist */,
25E1D2351F54A20F00D90192 /* Feedback.swift */,
);
path = ReactiveFeedback;
sourceTree = "<group>";
Expand Down Expand Up @@ -357,7 +357,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
25CC87BC1F92859800A6EBFC /* FeedbackLoops.swift in Sources */,
25CC87BC1F92859800A6EBFC /* Feedback.swift in Sources */,
25CC87BB1F92859800A6EBFC /* SignalProducer+System.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import Foundation
import ReactiveSwift
import enum Result.NoError

public struct FeedbackLoop<State, Event> {
public let loop: (Scheduler, Signal<State, NoError>) -> Signal<Event, NoError>
public struct Feedback<State, Event> {
public let events: (Scheduler, Signal<State, NoError>) -> Signal<Event, NoError>

public init<Control: Equatable, Effect: SignalProducerConvertible>(
query: @escaping (State) -> Control?,
effects: @escaping (Control) -> Effect
) where Effect.Value == Event, Effect.Error == NoError {
self.loop = { scheduler, state in
self.events = { scheduler, state in
return state
.map(query)
.skipRepeats { $0 == $1 }
Expand All @@ -25,7 +25,7 @@ public struct FeedbackLoop<State, Event> {
query: @escaping (State) -> Control?,
effects: @escaping (Control) -> Effect
) where Effect.Value == Event, Effect.Error == NoError {
self.loop = { scheduler, state in
self.events = { scheduler, state in
return state
.map(query)
.flatMap(.latest) { control -> SignalProducer<Event, NoError> in
Expand All @@ -40,7 +40,7 @@ public struct FeedbackLoop<State, Event> {
predicate: @escaping (State) -> Bool,
effects: @escaping (State) -> Effect
) where Effect.Value == Event, Effect.Error == NoError {
self.loop = { scheduler, state in
self.events = { scheduler, state in
return state
.flatMap(.latest) { state -> SignalProducer<Event, NoError> in
guard predicate(state) else { return .empty }
Expand All @@ -53,7 +53,7 @@ public struct FeedbackLoop<State, Event> {
public init<Effect: SignalProducerConvertible>(
effects: @escaping (State) -> Effect
) where Effect.Value == Event, Effect.Error == NoError {
self.loop = { scheduler, state in
self.events = { scheduler, state in
return state.flatMap(.latest) { state -> SignalProducer<Event, NoError> in
return effects(state).producer
.enqueue(on: scheduler)
Expand Down
6 changes: 3 additions & 3 deletions ReactiveFeedback/SignalProducer+System.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ extension SignalProducer where Error == NoError {
initial: Value,
scheduler: Scheduler = QueueScheduler.main,
reduce: @escaping (Value, Event) -> Value,
feedbacks: [FeedbackLoop<Value, Event>]
feedbacks: [Feedback<Value, Event>]
) -> SignalProducer<Value, NoError> {
return SignalProducer.deferred {
let (state, observer) = Signal<Value, NoError>.pipe()

let events = feedbacks.map { feedback in
return feedback.loop(scheduler, state)
return feedback.events(scheduler, state)
}

return SignalProducer<Event, NoError>(Signal.merge(events))
Expand All @@ -26,7 +26,7 @@ extension SignalProducer where Error == NoError {
public static func system<Event>(
initial: Value,
reduce: @escaping (Value, Event) -> Value,
feedbacks: FeedbackLoop<Value, Event>...
feedbacks: Feedback<Value, Event>...
) -> SignalProducer<Value, Error> {
return system(initial: initial, reduce: reduce, feedbacks: feedbacks)
}
Expand Down

0 comments on commit 70596cf

Please sign in to comment.