Skip to content

Commit

Permalink
Rename sink to observer
Browse files Browse the repository at this point in the history
  • Loading branch information
Srđan Rašić committed Nov 17, 2015
1 parent 9743ada commit 337f563
Show file tree
Hide file tree
Showing 15 changed files with 242 additions and 231 deletions.
4 changes: 2 additions & 2 deletions ReactiveKit.podspec
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Pod::Spec.new do |s|
s.name = "ReactiveKit"
s.version = "1.0.1"
s.version = "1.0.2"
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" => "[email protected]" }
s.source = { :git => "https://github.com/ReactiveKit/ReactiveKit.git", :tag => "v1.0.1" }
s.source = { :git => "https://github.com/ReactiveKit/ReactiveKit.git", :tag => "v1.0.2" }

s.ios.deployment_target = '8.0'
s.osx.deployment_target = '10.9'
Expand Down
4 changes: 2 additions & 2 deletions ReactiveKit/Observable/MutableObservable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public struct MutableObservable<Value>: ObservableType {
observable = Observable(value)
}

public func observe(on context: ExecutionContext, sink: Value -> ()) -> DisposableType {
return observable.observe(on: context, sink: sink)
public func observe(on context: ExecutionContext, observer: Value -> ()) -> DisposableType {
return observable.observe(on: context, observer: observer)
}
}
26 changes: 13 additions & 13 deletions ReactiveKit/Observable/Observable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ public class Observable<Value>: ActiveStream<Value>, ObservableType {
return try! lastEvent()
}
set {
capturedSink?(newValue)
capturedObserver?(newValue)
}
}

private var capturedSink: (Value -> ())? = nil
private var capturedObserver: (Value -> ())? = nil

public init(_ value: Value) {
var capturedSink: (Value -> ())!
super.init(limit: 1, producer: { sink in
capturedSink = sink
sink(value)
var capturedObserver: (Value -> ())!
super.init(limit: 1, producer: { observer in
capturedObserver = observer
observer(value)
return nil
})
self.capturedSink = capturedSink
self.capturedObserver = capturedObserver
}

public init(@noescape producer: (Value -> ()) -> DisposableType?) {
super.init(limit: 1, producer: { sink in
return producer(sink)
super.init(limit: 1, producer: { observer in
return producer(observer)
})
}
}
Expand All @@ -66,19 +66,19 @@ public extension Observable {

@warn_unused_result
public func map<U>(transform: Value -> U) -> Observable<U> {
return create { sink in
return create { observer in
return self.observe(on: ImmediateExecutionContext) { event in
sink(transform(event))
observer(transform(event))
}
}
}

@warn_unused_result
public func zipPrevious() -> Observable<(Value?, Value)> {
return create { sink in
return create { observer in
var previous: Value? = nil
return self.observe(on: ImmediateExecutionContext) { event in
sink(previous, event)
observer(previous, event)
previous = event
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public struct MutableObservableCollection<Collection: CollectionType>: Observabl
observableCollection.dispatch(event)
}

public func observe(on context: ExecutionContext, sink: ObservableCollectionEvent<Collection> -> ()) -> DisposableType {
return observableCollection.observe(on: context, sink: sink)
public func observe(on context: ExecutionContext, observer: ObservableCollectionEvent<Collection> -> ()) -> DisposableType {
return observableCollection.observe(on: context, observer: observer)
}

// MARK: CollectionType conformance
Expand Down
44 changes: 22 additions & 22 deletions ReactiveKit/ObservableCollection/ObservableCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public protocol ObservableCollectionType: CollectionType, StreamType {
var collection: Collection { get }
mutating func dispatch(event: ObservableCollectionEvent<Collection>)

func observe(on context: ExecutionContext, sink: ObservableCollectionEvent<Collection> -> ()) -> DisposableType
func observe(on context: ExecutionContext, observer: ObservableCollectionEvent<Collection> -> ()) -> DisposableType
}

public class ObservableCollection<Collection: CollectionType>: ActiveStream<ObservableCollectionEvent<Collection>>, ObservableCollectionType {
Expand All @@ -44,28 +44,28 @@ public class ObservableCollection<Collection: CollectionType>: ActiveStream<Obse
}
}

private var capturedSink: (ObservableCollectionEvent<Collection> -> ())? = nil
private var capturedObserver: (ObservableCollectionEvent<Collection> -> ())? = nil

public convenience init(_ collection: Collection) {
var capturedSink: (ObservableCollectionEvent<Collection> -> ())!
var capturedObserver: (ObservableCollectionEvent<Collection> -> ())!

self.init() { sink in
capturedSink = sink
sink(ObservableCollectionEvent.initial(collection))
self.init() { observer in
capturedObserver = observer
observer(ObservableCollectionEvent.initial(collection))
return nil
}

self.capturedSink = capturedSink
self.capturedObserver = capturedObserver
}

public init(@noescape producer: (ObservableCollectionEvent<Collection> -> ()) -> DisposableType?) {
super.init(limit: 1, producer: { sink in
return producer(sink)
super.init(limit: 1, producer: { observer in
return producer(observer)
})
}

public func dispatch(event: ObservableCollectionEvent<Collection>) {
capturedSink?(event)
capturedObserver?(event)
}

// MARK: CollectionType conformance
Expand Down Expand Up @@ -116,10 +116,10 @@ public extension ObservableCollectionType {

@warn_unused_result
public func zipPrevious() -> Observable<(ObservableCollectionEvent<Collection>?, ObservableCollectionEvent<Collection>)> {
return create { sink in
return create { observer in
var previous: ObservableCollectionEvent<Collection>? = nil
return self.observe(on: ImmediateExecutionContext) { event in
sink(previous, event)
observer(previous, event)
previous = event
}
}
Expand All @@ -131,19 +131,19 @@ public extension ObservableCollectionType where Collection.Index == Int {
/// Each event costs O(n)
@warn_unused_result
public func map<U>(transform: Collection.Generator.Element -> U) -> ObservableCollection<Array<U>> {
return create { sink in
return create { observer in
return self.observe(on: ImmediateExecutionContext) { event in
sink(event.map(transform))
observer(event.map(transform))
}
}
}

/// Each event costs O(1)
@warn_unused_result
public func lazyMap<U>(transform: Collection.Generator.Element -> U) -> ObservableCollection<LazyMapCollection<Collection, U>> {
return create { sink in
return create { observer in
return self.observe(on: ImmediateExecutionContext) { event in
sink(event.lazyMap(transform))
observer(event.lazyMap(transform))
}
}
}
Expand All @@ -154,9 +154,9 @@ public extension ObservableCollectionType where Collection.Index == Int {
/// Each event costs O(n)
@warn_unused_result
public func filter(include: Collection.Generator.Element -> Bool) -> ObservableCollection<Array<Collection.Generator.Element>> {
return create { sink in
return create { observer in
return self.observe(on: ImmediateExecutionContext) { event in
sink(event.filter(include))
observer(event.filter(include))
}
}
}
Expand All @@ -167,9 +167,9 @@ public extension ObservableCollectionType where Collection.Index: Hashable {
/// Each event costs O(n*logn)
@warn_unused_result
public func sort(isOrderedBefore: (Collection.Generator.Element, Collection.Generator.Element) -> Bool) -> ObservableCollection<Array<Collection.Generator.Element>> {
return create { sink in
return create { observer in
return self.observe(on: ImmediateExecutionContext) { event in
sink(event.sort(isOrderedBefore))
observer(event.sort(isOrderedBefore))
}
}
}
Expand All @@ -180,9 +180,9 @@ public extension ObservableCollectionType where Collection.Index: Equatable {
/// Each event costs O(n^2)
@warn_unused_result
public func sort(isOrderedBefore: (Collection.Generator.Element, Collection.Generator.Element) -> Bool) -> ObservableCollection<Array<Collection.Generator.Element>> {
return create { sink in
return create { observer in
return self.observe(on: ImmediateExecutionContext) { event in
sink(event.sort(isOrderedBefore))
observer(event.sort(isOrderedBefore))
}
}
}
Expand Down
Loading

0 comments on commit 337f563

Please sign in to comment.