Skip to content

Commit

Permalink
.replace(sources: ...) and .manual(event:)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxvol committed Jul 10, 2017
1 parent b185282 commit 7a785b8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 25 deletions.
8 changes: 0 additions & 8 deletions RaspSwift.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
objects = {

/* Begin PBXBuildFile section */
9424AAAF1EF27CC100E8646D /* RxSwift.framework.dSYM in Carthage */ = {isa = PBXBuildFile; fileRef = 9424AAAE1EF27CC100E8646D /* RxSwift.framework.dSYM */; };
9424AAB01EF27DFF00E8646D /* RxSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9465525A1EF26828001AD6AC /* RxSwift.framework */; };
9446ADBC1EF05B160036A603 /* RaspSwift.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9446ADB21EF05B150036A603 /* RaspSwift.framework */; };
9446ADD41EF05D3F0036A603 /* RaspReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9446ADD31EF05D3F0036A603 /* RaspReducer.swift */; };
Expand Down Expand Up @@ -55,16 +54,13 @@
dstPath = "";
dstSubfolderSpec = 16;
files = (
9424AAAF1EF27CC100E8646D /* RxSwift.framework.dSYM in Carthage */,
);
name = Carthage;
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
9424AAAC1EF2763500E8646D /* RxSwift.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = RxSwift.framework.dSYM; path = Carthage/Build/Mac/RxSwift.framework.dSYM; sourceTree = "<group>"; };
9424AAAE1EF27CC100E8646D /* RxSwift.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = RxSwift.framework.dSYM; path = Carthage/Build/Mac/RxSwift.framework.dSYM; sourceTree = "<group>"; };
9446ADB21EF05B150036A603 /* RaspSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RaspSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
9446ADBB1EF05B160036A603 /* iOS_RaspSwiftTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = iOS_RaspSwiftTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
9446ADCC1EF05B370036A603 /* Cartfile.resolved */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Cartfile.resolved; sourceTree = "<group>"; };
Expand All @@ -89,7 +85,6 @@
946552491EF267F9001AD6AC /* macOS_RaspSwiftTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = macOS_RaspSwiftTests.swift; sourceTree = "<group>"; };
9465524B1EF267F9001AD6AC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9465525A1EF26828001AD6AC /* RxSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = RxSwift.framework; path = Carthage/Build/Mac/RxSwift.framework; sourceTree = "<group>"; };
9465525D1EF2685F001AD6AC /* RxSwift.framework.dSYM */ = {isa = PBXFileReference; lastKnownFileType = wrapper.dsym; name = RxSwift.framework.dSYM; path = Carthage/Build/Mac/RxSwift.framework.dSYM; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -131,9 +126,6 @@
9446ADA81EF05B150036A603 = {
isa = PBXGroup;
children = (
9424AAAE1EF27CC100E8646D /* RxSwift.framework.dSYM */,
9424AAAC1EF2763500E8646D /* RxSwift.framework.dSYM */,
9465525D1EF2685F001AD6AC /* RxSwift.framework.dSYM */,
9446ADD11EF05CE20036A603 /* README.md */,
9446ADCC1EF05B370036A603 /* Cartfile.resolved */,
9446ADCD1EF05B370036A603 /* Cartfile */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9446ADB11EF05B150036A603"
BuildableName = "iOS_RaspSwift.framework"
BuildableName = "RaspSwift.framework"
BlueprintName = "iOS_RaspSwift"
ReferencedContainer = "container:RaspSwift.xcodeproj">
</BuildableReference>
Expand Down Expand Up @@ -43,7 +43,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9446ADB11EF05B150036A603"
BuildableName = "iOS_RaspSwift.framework"
BuildableName = "RaspSwift.framework"
BlueprintName = "iOS_RaspSwift"
ReferencedContainer = "container:RaspSwift.xcodeproj">
</BuildableReference>
Expand All @@ -65,7 +65,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9446ADB11EF05B150036A603"
BuildableName = "iOS_RaspSwift.framework"
BuildableName = "RaspSwift.framework"
BlueprintName = "iOS_RaspSwift"
ReferencedContainer = "container:RaspSwift.xcodeproj">
</BuildableReference>
Expand All @@ -83,7 +83,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9446ADB11EF05B150036A603"
BuildableName = "iOS_RaspSwift.framework"
BuildableName = "RaspSwift.framework"
BlueprintName = "iOS_RaspSwift"
ReferencedContainer = "container:RaspSwift.xcodeproj">
</BuildableReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9465523B1EF267F8001AD6AC"
BuildableName = "macOS_RaspSwift.framework"
BuildableName = "RaspSwift.framework"
BlueprintName = "macOS_RaspSwift"
ReferencedContainer = "container:RaspSwift.xcodeproj">
</BuildableReference>
Expand Down Expand Up @@ -43,7 +43,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9465523B1EF267F8001AD6AC"
BuildableName = "macOS_RaspSwift.framework"
BuildableName = "RaspSwift.framework"
BlueprintName = "macOS_RaspSwift"
ReferencedContainer = "container:RaspSwift.xcodeproj">
</BuildableReference>
Expand All @@ -65,7 +65,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9465523B1EF267F8001AD6AC"
BuildableName = "macOS_RaspSwift.framework"
BuildableName = "RaspSwift.framework"
BlueprintName = "macOS_RaspSwift"
ReferencedContainer = "container:RaspSwift.xcodeproj">
</BuildableReference>
Expand All @@ -83,7 +83,7 @@
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "9465523B1EF267F8001AD6AC"
BuildableName = "macOS_RaspSwift.framework"
BuildableName = "RaspSwift.framework"
BlueprintName = "macOS_RaspSwift"
ReferencedContainer = "container:RaspSwift.xcodeproj">
</BuildableReference>
Expand Down
29 changes: 20 additions & 9 deletions RaspSwift/RaspAggregator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,41 @@ import Foundation
import RxSwift

public class RaspAggregator<S: RaspState> {

public let events: Observable<RaspEvent>
public let state: Observable<S>

public static var defaultReducer: RaspReducer<S> {
return RaspReducer<S> { (state, event) throws -> S in
var newState = state
newState.apply(event: event)
return newState
}
}


private let eventSwitch: BehaviorSubject<Observable<RaspEvent>>
private let eventSink: PublishSubject<RaspEvent> = PublishSubject()

public init(initial state: S, reducer: RaspReducer<S> = RaspAggregator<S>.defaultReducer, sources: Observable<RaspEvent>...) {
self.events = Observable.merge(sources)
self.eventSwitch = BehaviorSubject(value: Observable.merge(sources))
self.events = Observable.merge(self.eventSwitch.switchLatest(), self.eventSink)
self.state = self.events.scan(state, accumulator: reducer.reduce)
}

public func select<R: Comparable>(selector: RaspSelector<S, R>) -> Observable<R> {
return self.state.map { state in
return selector.select(state)
}.distinctUntilChanged { (value) -> R in
return value
}.distinctUntilChanged { (value) -> R in
return value
}
}



public func replace(sources: Observable<RaspEvent>...) {
self.eventSwitch.onNext(Observable.merge(sources))
}

public func manual(event: RaspEvent) {
self.eventSink.onNext(event)
}

}

0 comments on commit 7a785b8

Please sign in to comment.