From 3584c0e4c664aa056b5bc244381cc2583cfa97ef Mon Sep 17 00:00:00 2001 From: Srdan Rasic Date: Mon, 23 May 2016 12:22:29 +0200 Subject: [PATCH] Fix Property method ambiguity issues. --- ReactiveKit.podspec | 4 ++-- ReactiveKit/Info.plist | 2 +- Sources/CollectionProperty.swift | 9 ++++++++- Sources/Property.swift | 4 ++++ Sources/Subjects.swift | 16 +++++++++------- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/ReactiveKit.podspec b/ReactiveKit.podspec index 9e04164..841e200 100644 --- a/ReactiveKit.podspec +++ b/ReactiveKit.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |s| s.name = "ReactiveKit" - s.version = "2.0.0" + s.version = "2.0.1" s.summary = "A Swift Reactive Programming Framework" s.description = "ReactiveKit is a collection of Swift frameworks for reactive and functional reactive programming." s.homepage = "https://github.com/ReactiveKit/ReactiveKit" s.license = 'MIT' s.author = { "Srdan Rasic" => "srdan.rasic@gmail.com" } - s.source = { :git => "https://github.com/ReactiveKit/ReactiveKit.git", :tag => "v2.0.0" } + s.source = { :git => "https://github.com/ReactiveKit/ReactiveKit.git", :tag => "v2.0.1" } s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.9' diff --git a/ReactiveKit/Info.plist b/ReactiveKit/Info.plist index 7e7479f..783e22e 100644 --- a/ReactiveKit/Info.plist +++ b/ReactiveKit/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 2.0.0 + 2.0.1 CFBundleSignature ???? CFBundleVersion diff --git a/Sources/CollectionProperty.swift b/Sources/CollectionProperty.swift index 9fe24d5..39a71a1 100644 --- a/Sources/CollectionProperty.swift +++ b/Sources/CollectionProperty.swift @@ -130,7 +130,7 @@ public extension CollectionChangesetType where Collection.Index: Equatable { } } -public protocol CollectionPropertyType: CollectionType, StreamType, PropertyType { +public protocol CollectionPropertyType: CollectionType, StreamType, PropertyType, SubjectType { associatedtype Collection: CollectionType associatedtype Index = Collection.Index associatedtype Member = Collection.Generator.Element @@ -202,6 +202,13 @@ public class CollectionProperty: CollectionPropertyType { collection = changeset.collection subject.on(.Next(changeset)) } + + public func on(event: StreamEvent>) { + if let changeset = event.element { + collection = changeset.collection + } + subject.on(event) + } } public extension CollectionPropertyType { diff --git a/Sources/Property.swift b/Sources/Property.swift index b0721ee..144e86c 100644 --- a/Sources/Property.swift +++ b/Sources/Property.swift @@ -65,6 +65,10 @@ public final class Property: PropertyType, StreamType, SubjectType { _value = value } + public func silentUpdate(value: T) { + _value = value + } + deinit { subject.completed() } diff --git a/Sources/Subjects.swift b/Sources/Subjects.swift index ca19f63..77cbc7b 100644 --- a/Sources/Subjects.swift +++ b/Sources/Subjects.swift @@ -49,11 +49,13 @@ internal class ObserverRegister { } } -public protocol SubjectType: ObserverType, RawStreamType { - func on(event: Event) +public protocol SubjectType: ObserverType, _StreamType { } -public final class PublishSubject: ObserverRegister, SubjectType { +public protocol RawSubjectType: ObserverType, RawStreamType { +} + +public final class PublishSubject: ObserverRegister, RawSubjectType { private let lock = RecursiveLock(name: "ReactiveKit.PublishSubject") private var completed = false @@ -77,7 +79,7 @@ public final class PublishSubject: ObserverRegister, SubjectTyp } } -public final class ReplaySubject: ObserverRegister, SubjectType { +public final class ReplaySubject: ObserverRegister, RawSubjectType { public let bufferSize: Int private var buffer: ArraySlice = [] @@ -119,7 +121,7 @@ public final class ReplaySubject: ObserverRegister, SubjectType } } -public final class ReplayOneSubject: ObserverRegister, SubjectType { +public final class ReplayOneSubject: ObserverRegister, RawSubjectType { private var event: E? = nil private let lock = RecursiveLock(name: "ReactiveKit.ReplayOneSubject") @@ -156,11 +158,11 @@ public final class ReplayOneSubject: ObserverRegister, SubjectT } } -public final class AnySubject: SubjectType { +public final class AnySubject: RawSubjectType { private let baseObserve: (E -> Void) -> Disposable private let baseOn: E -> Void - public init(base: S) { + public init(base: S) { baseObserve = base.observe baseOn = base.on }