Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Commit

Permalink
Merge pull request ReactiveCocoa#1648 from jconst/swift-development
Browse files Browse the repository at this point in the history
More ways to merge HotSignals; Update to carthage 0.4
  • Loading branch information
jspahrsummers committed Dec 26, 2014
2 parents e94a432 + d7890e4 commit e93e2ac
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ xcuserdata
profile
*.moved-aside

Carthage.build
Carthage/Build
8 changes: 4 additions & 4 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[submodule "Carthage.checkout/Nimble"]
path = Carthage.checkout/Nimble
path = Carthage/Checkouts/Nimble
url = https://github.com/Quick/Nimble.git
[submodule "Carthage.checkout/Quick"]
path = Carthage.checkout/Quick
path = Carthage/Checkouts/Quick
url = https://github.com/Quick/Quick.git
[submodule "Carthage.checkout/xcconfigs"]
path = Carthage.checkout/xcconfigs
path = Carthage/Checkouts/xcconfigs
url = https://github.com/jspahrsummers/xcconfigs.git
[submodule "Carthage.checkout/LlamaKit"]
path = Carthage.checkout/LlamaKit
path = Carthage/Checkouts/LlamaKit
url = https://github.com/Carthage/LlamaKit.git
4 changes: 0 additions & 4 deletions Cartfile.lock

This file was deleted.

4 changes: 4 additions & 0 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github "Carthage/LlamaKit" "carthage-0.1.1"
github "Quick/Nimble" "v0.2.0"
github "Quick/Quick" "v0.2.0"
github "jspahrsummers/xcconfigs" "0.7"
1 change: 0 additions & 1 deletion Carthage.checkout/Nimble
Submodule Nimble deleted from 81a2d8
1 change: 0 additions & 1 deletion Carthage.checkout/xcconfigs
Submodule xcconfigs deleted from 6c7a02
1 change: 1 addition & 0 deletions Carthage/Checkouts/Nimble
Submodule Nimble added at 6f787e
1 change: 1 addition & 0 deletions Carthage/Checkouts/xcconfigs
Submodule xcconfigs added at 6c6423
4 changes: 3 additions & 1 deletion ReactiveCocoa.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
270DE4451A1EAB4600151031 /* ObservablePropertySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277F6A951A1EAA10003E0EC9 /* ObservablePropertySpec.swift */; };
270DE4461A1EACA200151031 /* ObservablePropertySpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 277F6A951A1EAA10003E0EC9 /* ObservablePropertySpec.swift */; };
5FABB3171A4BDE9700DF4DA1 /* HotSignalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = F63BBA321A02550A00DD140D /* HotSignalSpec.swift */; };
D00004091A46864E000E7D41 /* TupleExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00004081A46864E000E7D41 /* TupleExtensions.swift */; };
D000040A1A46864E000E7D41 /* TupleExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = D00004081A46864E000E7D41 /* TupleExtensions.swift */; };
D01792021A34D79100A7B229 /* ColdSignalSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = D01792011A34D79100A7B229 /* ColdSignalSpec.swift */; };
Expand Down Expand Up @@ -1204,7 +1205,7 @@
D047263C19E49FE8006002AA /* README.md */,
);
name = Configuration;
path = Carthage.checkout/xcconfigs;
path = Carthage/Checkouts/xcconfigs;
sourceTree = "<group>";
};
D047262619E49FE8006002AA /* Base */ = {
Expand Down Expand Up @@ -1903,6 +1904,7 @@
D037671A19EDA60000A782A9 /* UIActionSheetRACSupportSpec.m in Sources */,
D03766DA19EDA60000A782A9 /* RACChannelExamples.m in Sources */,
D03766F619EDA60000A782A9 /* RACSequenceExamples.m in Sources */,
5FABB3171A4BDE9700DF4DA1 /* HotSignalSpec.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
6 changes: 3 additions & 3 deletions ReactiveCocoa.xcworkspace/contents.xcworkspacedata

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ReactiveCocoa/Swift/ColdSignal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ extension ColdSignal {
}
}

/// Merges a signal of signals down into a single signal, biased toward the
/// Merges a ColdSignal of ColdSignals down into a single ColdSignal, biased toward the
/// signals added earlier.
///
/// evidence - Used to prove to the typechecker that the receiver is
Expand Down
23 changes: 21 additions & 2 deletions ReactiveCocoa/Swift/HotSignal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ extension HotSignal {
}
}

/// Merges a signal of signals down into a single signal, biased toward the
/// Merges a HotSignal of HotSignals down into a single HotSignal, biased toward the
/// signals added earlier.
///
/// The returned signal will automatically be destroyed when there are no
Expand All @@ -545,7 +545,7 @@ extension HotSignal {
/// evidence - Used to prove to the typechecker that the receiver is
/// a signal of signals. Simply pass in the `identity` function.
///
/// Returns a signal that will forward changes from the original signals
/// Returns a HotSignal that will forward changes from the original signals
/// as they arrive, starting with earlier ones.
public func merge<U>(evidence: HotSignal -> HotSignal<HotSignal<U>>) -> HotSignal<U> {
return HotSignal<U>.weak { sink in
Expand All @@ -561,6 +561,25 @@ extension HotSignal {
}
}

/// Merges a SequenceType of HotSignals down into a single HotSignal, biased toward the
/// signals appearing earlier in the sequence.
///
/// The returned signal will automatically be destroyed when there are no
/// more strong references to it, and no Disposables returned from observe()
/// are still around.
///
/// Returns a HotSignal that will forward changes from the original signals
/// in the sequence, starting with earlier ones.
public class func merge<S: SequenceType where S.Generator.Element == HotSignal<T>>(signals: S) -> HotSignal<T> {
let (signal, sink) = HotSignal<HotSignal<T>>.pipe()
let merged = signal.merge(identity)
var generator = signals.generate()
while let signal: HotSignal<T> = generator.next() {
sink.put(signal)
}
return merged
}

/// Maps each value that the receiver sends to a new signal, then merges the
/// resulting signals together.
///
Expand Down
54 changes: 54 additions & 0 deletions ReactiveCocoaTests/Swift/HotSignalSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,60 @@ class HotSignalSpec: QuickSpec {
}
}

describe("merge(SequenceType)") {
it("should forward values from any inner signals") {
let (firstSignal, firstSink) = HotSignal<Int>.pipe()
let (secondSignal, secondSink) = HotSignal<Int>.pipe()

let newSignal = HotSignal.merge([firstSignal, secondSignal])

var latestValue: Int?
newSignal.observe { latestValue = $0 }

expect(latestValue).to(beNil())

firstSink.put(1)
expect(latestValue).to(equal(1))

secondSink.put(2)
expect(latestValue).to(equal(2))

firstSink.put(3)
expect(latestValue).to(equal(3))

firstSink.put(4)
expect(latestValue).to(equal(4))
}

it("should release input signals when reference is lost") {
weak var innerSignal: HotSignal<Int>?
weak var mergedSignal: HotSignal<Int>?

let test: () -> () = {
let (firstSignal, firstSink) = HotSignal<Int>.pipe()
let newSignal = HotSignal.merge([firstSignal])

mergedSignal = newSignal
expect(mergedSignal).notTo(beNil())

var latestValue: Int?
newSignal.observe { latestValue = $0 }

expect(latestValue).to(beNil())

innerSignal = firstSignal
expect(innerSignal).notTo(beNil())

firstSink.put(0)
expect(latestValue).to(equal(0))
}

test()
expect(mergedSignal).toEventually(beNil())
expect(innerSignal).toEventually(beNil())
}
}

describe("switchToLatest") {
it("should forward values from the latest inner signal") {
let (signal, sink) = HotSignal<HotSignal<Int>>.pipe()
Expand Down

0 comments on commit e93e2ac

Please sign in to comment.