Skip to content

Commit

Permalink
Merge branch 'master' into timeline
Browse files Browse the repository at this point in the history
  • Loading branch information
srdanrasic committed Mar 6, 2020
2 parents 713ae0d + 0e553b1 commit 12b359d
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ReactiveKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
objects = {

/* Begin PBXBuildFile section */
08788B2E2411609D0011CB5E /* Deferred.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08788B2D2411609D0011CB5E /* Deferred.swift */; };
08788B2F2411609D0011CB5E /* Deferred.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08788B2D2411609D0011CB5E /* Deferred.swift */; };
08788B302411609D0011CB5E /* Deferred.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08788B2D2411609D0011CB5E /* Deferred.swift */; };
08788B312411609D0011CB5E /* Deferred.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08788B2D2411609D0011CB5E /* Deferred.swift */; };
08788B392411C5D00011CB5E /* Empty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08788B382411C5D00011CB5E /* Empty.swift */; };
08788B3A2411C5F30011CB5E /* Empty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08788B382411C5D00011CB5E /* Empty.swift */; };
08788B3B2411C5F30011CB5E /* Empty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08788B382411C5D00011CB5E /* Empty.swift */; };
08788B3C2411C5F40011CB5E /* Empty.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08788B382411C5D00011CB5E /* Empty.swift */; };
08B5D54E23A68647000AE983 /* PublishedTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 08B5D54C23A68618000AE983 /* PublishedTests.swift */; };
16C33B841BEFBAC900A0DBE0 /* ReactiveKit.h in Headers */ = {isa = PBXBuildFile; fileRef = ECBCCDD31BEB6B9A00723476 /* ReactiveKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
16C33B851BEFBAC900A0DBE0 /* ReactiveKit.h in Headers */ = {isa = PBXBuildFile; fileRef = ECBCCDD31BEB6B9A00723476 /* ReactiveKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand Down Expand Up @@ -200,6 +208,8 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
08788B2D2411609D0011CB5E /* Deferred.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Deferred.swift; sourceTree = "<group>"; };
08788B382411C5D00011CB5E /* Empty.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Empty.swift; sourceTree = "<group>"; };
08B5D54C23A68618000AE983 /* PublishedTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublishedTests.swift; sourceTree = "<group>"; };
162CB7461CB451D200FB6375 /* Package.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Package.swift; sourceTree = "<group>"; };
1671707E1BF4F62A001786CE /* ReactiveKit.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = ReactiveKit.podspec; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -306,6 +316,7 @@
EC48D2F0224FB5C400284EA0 /* Sources */ = {
isa = PBXGroup;
children = (
EC4A95E72412E90A00362F60 /* Publishers */,
EC7717E923BE23440036A609 /* Subscribers */,
EC75487D2351E2AC002D869C /* Scheduler.swift */,
EC912A5D23BCAD2600701259 /* Subscriber.swift */,
Expand Down Expand Up @@ -372,6 +383,15 @@
path = ReactiveKitTests;
sourceTree = "<group>";
};
EC4A95E72412E90A00362F60 /* Publishers */ = {
isa = PBXGroup;
children = (
08788B2D2411609D0011CB5E /* Deferred.swift */,
08788B382411C5D00011CB5E /* Empty.swift */,
);
path = Publishers;
sourceTree = "<group>";
};
EC7717E923BE23440036A609 /* Subscribers */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -659,6 +679,7 @@
EC48D356224FB5C400284EA0 /* Reactive.swift in Sources */,
EC75487F2351E2AC002D869C /* Scheduler.swift in Sources */,
EC912A6E23BCB00500701259 /* Subscription.swift in Sources */,
08788B3A2411C5F30011CB5E /* Empty.swift in Sources */,
EC48D35A224FB5C400284EA0 /* LoadingSignal.swift in Sources */,
EC48D376224FB5C400284EA0 /* Signal.swift in Sources */,
ECF2EB7D240A6E4100BD5E67 /* TimelaneCore.swift in Sources */,
Expand All @@ -673,6 +694,7 @@
EC7717ED23BE33650036A609 /* Sink.swift in Sources */,
EC48D36A224FB5C400284EA0 /* SignalProtocol+Result.swift in Sources */,
ECDFDCB322BD7E9500B85C5E /* Completion.swift in Sources */,
08788B2F2411609D0011CB5E /* Deferred.swift in Sources */,
EC48D32A224FB5C400284EA0 /* SignalProtocol+Threading.swift in Sources */,
EC48D366224FB5C400284EA0 /* SignalProtocol+Transforming.swift in Sources */,
EC48D346224FB5C400284EA0 /* Bindable.swift in Sources */,
Expand Down Expand Up @@ -708,6 +730,7 @@
EC48D357224FB5C400284EA0 /* Reactive.swift in Sources */,
EC7548802351E2AC002D869C /* Scheduler.swift in Sources */,
EC912A6F23BCB00500701259 /* Subscription.swift in Sources */,
08788B3B2411C5F30011CB5E /* Empty.swift in Sources */,
EC48D35B224FB5C400284EA0 /* LoadingSignal.swift in Sources */,
EC48D377224FB5C400284EA0 /* Signal.swift in Sources */,
ECF2EB7E240A6E4100BD5E67 /* TimelaneCore.swift in Sources */,
Expand All @@ -722,6 +745,7 @@
EC7717EE23BE33650036A609 /* Sink.swift in Sources */,
EC48D36B224FB5C400284EA0 /* SignalProtocol+Result.swift in Sources */,
ECDFDCB422BD7E9500B85C5E /* Completion.swift in Sources */,
08788B302411609D0011CB5E /* Deferred.swift in Sources */,
EC48D32B224FB5C400284EA0 /* SignalProtocol+Threading.swift in Sources */,
EC48D367224FB5C400284EA0 /* SignalProtocol+Transforming.swift in Sources */,
EC48D347224FB5C400284EA0 /* Bindable.swift in Sources */,
Expand Down Expand Up @@ -757,6 +781,7 @@
EC48D358224FB5C400284EA0 /* Reactive.swift in Sources */,
EC7548812351E2AC002D869C /* Scheduler.swift in Sources */,
EC912A7023BCB00500701259 /* Subscription.swift in Sources */,
08788B3C2411C5F40011CB5E /* Empty.swift in Sources */,
EC48D35C224FB5C400284EA0 /* LoadingSignal.swift in Sources */,
EC48D378224FB5C400284EA0 /* Signal.swift in Sources */,
ECF2EB7F240A6E4100BD5E67 /* TimelaneCore.swift in Sources */,
Expand All @@ -771,6 +796,7 @@
EC7717EF23BE33650036A609 /* Sink.swift in Sources */,
EC48D36C224FB5C400284EA0 /* SignalProtocol+Result.swift in Sources */,
ECDFDCB522BD7E9500B85C5E /* Completion.swift in Sources */,
08788B312411609D0011CB5E /* Deferred.swift in Sources */,
EC48D32C224FB5C400284EA0 /* SignalProtocol+Threading.swift in Sources */,
EC48D368224FB5C400284EA0 /* SignalProtocol+Transforming.swift in Sources */,
EC48D348224FB5C400284EA0 /* Bindable.swift in Sources */,
Expand Down Expand Up @@ -806,6 +832,7 @@
EC48D355224FB5C400284EA0 /* Reactive.swift in Sources */,
EC75487E2351E2AC002D869C /* Scheduler.swift in Sources */,
EC912A6D23BCB00500701259 /* Subscription.swift in Sources */,
08788B392411C5D00011CB5E /* Empty.swift in Sources */,
EC48D359224FB5C400284EA0 /* LoadingSignal.swift in Sources */,
EC48D375224FB5C400284EA0 /* Signal.swift in Sources */,
ECF2EB7C240A6E4100BD5E67 /* TimelaneCore.swift in Sources */,
Expand All @@ -820,6 +847,7 @@
EC7717EC23BE33650036A609 /* Sink.swift in Sources */,
EC48D369224FB5C400284EA0 /* SignalProtocol+Result.swift in Sources */,
ECDFDCB222BD7E9500B85C5E /* Completion.swift in Sources */,
08788B2E2411609D0011CB5E /* Deferred.swift in Sources */,
EC48D329224FB5C400284EA0 /* SignalProtocol+Threading.swift in Sources */,
EC48D365224FB5C400284EA0 /* SignalProtocol+Transforming.swift in Sources */,
EC48D345224FB5C400284EA0 /* Bindable.swift in Sources */,
Expand Down
50 changes: 50 additions & 0 deletions Sources/Publishers/Deferred.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//
// Deferred.swift
// GlovoCourier
//
// Created by Ibrahim Koteish on 01/12/2019.
// Copyright © 2019 Glovo. All rights reserved.
//

import Foundation

/// A signal that awaits subscription before running the supplied closure
/// to create a signal for the new subscriber.
public struct Deferred<DeferredSignal: SignalProtocol>: SignalProtocol {

/// The kind of values published by this signal.
public typealias Element = DeferredSignal.Element

/// The kind of errors this signal might publish.
///
/// Use `Never` if this `signal` does not publish errors.
public typealias Error = DeferredSignal.Error

/// The closure to execute when it receives a subscription.
///
/// The signal returned by this closure immediately
/// receives the incoming subscription.
public let signalFactory: () -> DeferredSignal

/// Creates a deferred signal.
///
/// - Parameter signalFactory: The closure to execute
/// when calling `observe(with:)`.
public init(signalFactory: @escaping () -> DeferredSignal) {
self.signalFactory = signalFactory
}

/// This function is called to attach the specified `Observer`
/// to this `Signal` by `observe(with:)`
///
/// - Parameters:
/// - observer: The observer to attach to this `Signal`.
/// once attached it can begin to receive values.
public func observe(
with observer: @escaping (Signal<DeferredSignal.Element, DeferredSignal.Error>.Event) -> Void)
-> Disposable
{
let deferredSignal = signalFactory()
return deferredSignal.observe(with: observer)
}
}
63 changes: 63 additions & 0 deletions Sources/Publishers/Empty.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// Empty.swift
// ReactiveKit-iOS
//
// Created by Ibrahim Koteish on 06/03/2020.
// Copyright © 2020 DeclarativeHub. All rights reserved.
//

import Foundation

/// A signal that never publishes any values, and optionally finishes immediately.
///
/// You can create a ”Never” signal — one which never sends values and never
/// finishes or fails — with the initializer `Empty(completeImmediately: false)`.
public struct Empty<Element, Error: Swift.Error>: SignalProtocol, Equatable {

/// The kind of values published by this signal.
public typealias Element = Element

/// The kind of errors this signal might publish.
///
/// Use `Never` if this `signal` does not publish errors.
public typealias Error = Error

/// Creates an empty signal.
///
/// - Parameter completeImmediately: A Boolean value that indicates whether
/// the signal should immediately finish.
public init(completeImmediately: Bool = true) {
self.completeImmediately = completeImmediately
}

/// Creates an empty signal with the given completion behavior and output and
/// failure types.
///
/// Use this initializer to connect the empty signal to observers or other
/// signals that have specific output and failure types.
/// - Parameters:
/// - completeImmediately: A Boolean value that indicates whether the signal
/// should immediately finish.
/// - outputType: The output type exposed by this signal.
/// - failureType: The failure type exposed by this signal.
public init(completeImmediately: Bool = true,
outputType: Element.Type,
failureType: Error.Type) {
self.init(completeImmediately: completeImmediately)
}

/// A Boolean value that indicates whether the signal immediately sends
/// a completion.
///
/// If `true`, the signal finishes immediately after sending an event
/// to the observer. If `false`, it never completes.
public let completeImmediately: Bool

public func observe(with observer: @escaping (Signal<Element, Error>.Event) -> Void) -> Disposable {

if completeImmediately {
return Signal<Element, Error>.completed().observe(with: observer)
}
return Signal<Element, Error>.never().observe(with: observer)
}
}

0 comments on commit 12b359d

Please sign in to comment.