Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add generic ValueType to RACSignal and RACCommand #15

Merged
merged 1 commit into from
Nov 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions ReactiveObjC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -774,13 +774,6 @@
A97451351B3A935E00F48E55 /* watchOS-Framework.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "watchOS-Framework.xcconfig"; sourceTree = "<group>"; };
A97451361B3A935E00F48E55 /* watchOS-StaticLibrary.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = "watchOS-StaticLibrary.xcconfig"; sourceTree = "<group>"; };
A9B315541B3940610001CB9C /* ReactiveObjC.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ReactiveObjC.framework; sourceTree = BUILT_PRODUCTS_DIR; };
BE330A0E1D634F1E00806963 /* ReactiveSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ReactiveSwift.framework; path = build/Debug/ReactiveSwift.framework; sourceTree = "<group>"; };
BE330A101D634F2900806963 /* ReactiveSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ReactiveSwift.framework; path = build/Debug/ReactiveSwift.framework; sourceTree = "<group>"; };
BE330A121D634F2E00806963 /* ReactiveSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ReactiveSwift.framework; path = "build/Debug-iphoneos/ReactiveSwift.framework"; sourceTree = "<group>"; };
BE330A141D634F4000806963 /* ReactiveSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ReactiveSwift.framework; path = "build/Debug-iphoneos/ReactiveSwift.framework"; sourceTree = "<group>"; };
BE330A161D634F4E00806963 /* ReactiveSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ReactiveSwift.framework; path = "build/Debug-watchos/ReactiveSwift.framework"; sourceTree = "<group>"; };
BE330A181D634F5900806963 /* ReactiveSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ReactiveSwift.framework; path = "build/Debug-appletvos/ReactiveSwift.framework"; sourceTree = "<group>"; };
BE330A1A1D634F5F00806963 /* ReactiveSwift.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = ReactiveSwift.framework; path = "build/Debug-appletvos/ReactiveSwift.framework"; sourceTree = "<group>"; };
D037642A19EDA41200A782A9 /* NSArray+RACSequenceAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSArray+RACSequenceAdditions.h"; sourceTree = "<group>"; };
D037642B19EDA41200A782A9 /* NSArray+RACSequenceAdditions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSArray+RACSequenceAdditions.m"; sourceTree = "<group>"; };
D037642C19EDA41200A782A9 /* NSControl+RACCommandSupport.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSControl+RACCommandSupport.h"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1145,20 +1138,6 @@
path = watchOS;
sourceTree = "<group>";
};
BE330A0D1D634F1E00806963 /* Frameworks */ = {
isa = PBXGroup;
children = (
BE330A1A1D634F5F00806963 /* ReactiveSwift.framework */,
BE330A181D634F5900806963 /* ReactiveSwift.framework */,
BE330A161D634F4E00806963 /* ReactiveSwift.framework */,
BE330A141D634F4000806963 /* ReactiveSwift.framework */,
BE330A121D634F2E00806963 /* ReactiveSwift.framework */,
BE330A101D634F2900806963 /* ReactiveSwift.framework */,
BE330A0E1D634F1E00806963 /* ReactiveSwift.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
D037666519EDA57100A782A9 /* extobjc */ = {
isa = PBXGroup;
children = (
Expand All @@ -1178,7 +1157,6 @@
D04725F919E49ED7006002AA /* ReactiveObjCTests */,
D047262519E49FE8006002AA /* Configuration */,
D04725EB19E49ED7006002AA /* Products */,
BE330A0D1D634F1E00806963 /* Frameworks */,
);
sourceTree = "<group>";
usesTabs = 1;
Expand Down
5 changes: 3 additions & 2 deletions ReactiveObjC/MKAnnotationView+RACSignalSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>

@class RACSignal;
@class RACSignal<__covariant ValueType>;
@class RACUnit;

@interface MKAnnotationView (RACSignalSupport)

Expand All @@ -24,6 +25,6 @@
/// subscribeNext:^(UIButton *x) {
/// // do other things
/// }];
@property (nonatomic, strong, readonly) RACSignal *rac_prepareForReuseSignal;
@property (nonatomic, strong, readonly) RACSignal<RACUnit *> *rac_prepareForReuseSignal;

@end
4 changes: 2 additions & 2 deletions ReactiveObjC/NSControl+RACCommandSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Cocoa/Cocoa.h>

@class RACCommand<__contravariant InputType>;
@class RACCommand<__contravariant InputType, __covariant ValueType>;

@interface NSControl (RACCommandSupport)

Expand All @@ -17,6 +17,6 @@
/// to the command's `canExecute`.
///
/// Note: this will reset the control's target and action.
@property (nonatomic, strong) RACCommand<__kindof NSControl *> *rac_command;
@property (nonatomic, strong) RACCommand<__kindof NSControl *, id> *rac_command;

@end
4 changes: 2 additions & 2 deletions ReactiveObjC/NSControl+RACTextSignalSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Cocoa/Cocoa.h>

@class RACSignal;
@class RACSignal<__covariant ValueType>;

@interface NSControl (RACTextSignalSupport)

Expand All @@ -19,6 +19,6 @@
///
/// Returns a signal which sends the current string value of the receiver, then
/// the new value any time it changes.
- (RACSignal *)rac_textSignal;
- (RACSignal<NSString *> *)rac_textSignal;

@end
4 changes: 2 additions & 2 deletions ReactiveObjC/NSData+RACSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#import <Foundation/Foundation.h>

@class RACScheduler;
@class RACSignal;
@class RACSignal<__covariant ValueType>;

@interface NSData (RACSupport)

// Read the data at the URL using -[NSData initWithContentsOfURL:options:error:].
// Sends the data or the error.
//
// scheduler - cannot be nil.
+ (RACSignal *)rac_readContentsOfURL:(NSURL *)URL options:(NSDataReadingOptions)options scheduler:(RACScheduler *)scheduler;
+ (RACSignal<NSData *> *)rac_readContentsOfURL:(NSURL *)URL options:(NSDataReadingOptions)options scheduler:(RACScheduler *)scheduler;

@end
4 changes: 2 additions & 2 deletions ReactiveObjC/NSFileHandle+RACSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

#import <Foundation/Foundation.h>

@class RACSignal;
@class RACSignal<__covariant ValueType>;

@interface NSFileHandle (RACSupport)

// Read any available data in the background and send it. Completes when data
// length is <= 0.
- (RACSignal *)rac_readInBackground;
- (RACSignal<NSData *> *)rac_readInBackground;

@end
4 changes: 2 additions & 2 deletions ReactiveObjC/NSNotificationCenter+RACSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@

#import <Foundation/Foundation.h>

@class RACSignal;
@class RACSignal<__covariant ValueType>;

@interface NSNotificationCenter (RACSupport)

// Sends the NSNotification every time the notification is posted.
- (RACSignal *)rac_addObserverForName:(NSString *)notificationName object:(id)object;
- (RACSignal<NSNotification *> *)rac_addObserverForName:(NSString *)notificationName object:(id)object;

@end
2 changes: 1 addition & 1 deletion ReactiveObjC/NSObject+RACDeallocating.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@class RACCompoundDisposable;
@class RACDisposable;
@class RACSignal;
@class RACSignal<__covariant ValueType>;

@interface NSObject (RACDeallocating)

Expand Down
2 changes: 1 addition & 1 deletion ReactiveObjC/NSObject+RACLifting.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Foundation/Foundation.h>

@class RACSignal;
@class RACSignal<__covariant ValueType>;

@interface NSObject (RACLifting)

Expand Down
2 changes: 1 addition & 1 deletion ReactiveObjC/NSObject+RACPropertySubscribing.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
#endif

@class RACDisposable;
@class RACSignal;
@class RACSignal<__covariant ValueType>;

@interface NSObject (RACPropertySubscribing)

Expand Down
2 changes: 1 addition & 1 deletion ReactiveObjC/NSObject+RACSelectorSignal.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Foundation/Foundation.h>

@class RACSignal;
@class RACSignal<__covariant ValueType>;

/// The domain for any errors originating from -rac_signalForSelector:.
extern NSString * const RACSelectorSignalErrorDomain;
Expand Down
4 changes: 2 additions & 2 deletions ReactiveObjC/NSString+RACSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#import <Foundation/Foundation.h>

@class RACScheduler;
@class RACSignal;
@class RACSignal<__covariant ValueType>;

@interface NSString (RACSupport)

// Reads in the contents of the file using +[NSString stringWithContentsOfURL:usedEncoding:error:].
// Note that encoding won't be valid until the signal completes successfully.
//
// scheduler - cannot be nil.
+ (RACSignal *)rac_readContentsOfURL:(NSURL *)URL usedEncoding:(NSStringEncoding *)encoding scheduler:(RACScheduler *)scheduler;
+ (RACSignal<NSString *> *)rac_readContentsOfURL:(NSURL *)URL usedEncoding:(NSStringEncoding *)encoding scheduler:(RACScheduler *)scheduler;

@end
4 changes: 2 additions & 2 deletions ReactiveObjC/NSText+RACSignalSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

#import <Cocoa/Cocoa.h>

@class RACSignal;
@class RACSignal<__covariant ValueType>;

@interface NSText (RACSignalSupport)

/// Returns a signal which sends the current `string` of the receiver, then the
/// new value any time it changes.
- (RACSignal *)rac_textSignal;
- (RACSignal<NSString *> *)rac_textSignal;

@end
5 changes: 3 additions & 2 deletions ReactiveObjC/NSURLConnection+RACSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

#import <Foundation/Foundation.h>

@class RACSignal;
@class RACTuple;
@class RACSignal<__covariant ValueType>;

@interface NSURLConnection (RACSupport)

Expand All @@ -20,6 +21,6 @@
// then send a `RACTuple` of the received `NSURLResponse` and downloaded
// `NSData`, and complete on a background thread. If any errors occur, the
// returned signal will error out.
+ (RACSignal *)rac_sendAsynchronousRequest:(NSURLRequest *)request;
+ (RACSignal<RACTuple *> *)rac_sendAsynchronousRequest:(NSURLRequest *)request;

@end
16 changes: 8 additions & 8 deletions ReactiveObjC/RACCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Foundation/Foundation.h>

@class RACSignal;
@class RACSignal<__covariant ValueType>;
NS_ASSUME_NONNULL_BEGIN

/// The domain for errors originating within `RACCommand`.
Expand All @@ -25,7 +25,7 @@ extern NSString * const RACUnderlyingCommandErrorKey;

/// A command is a signal triggered in response to some action, typically
/// UI-related.
@interface RACCommand<__contravariant InputType> : NSObject
@interface RACCommand<__contravariant InputType, __covariant ValueType> : NSObject

/// A signal of the signals returned by successful invocations of -execute:
/// (i.e., while the receiver is `enabled`).
Expand All @@ -36,7 +36,7 @@ extern NSString * const RACUnderlyingCommandErrorKey;
///
/// Only executions that begin _after_ subscription will be sent upon this
/// signal. All inner signals will arrive upon the main thread.
@property (nonatomic, strong, readonly) RACSignal *executionSignals;
@property (nonatomic, strong, readonly) RACSignal<RACSignal<ValueType> *> *executionSignals;

/// A signal of whether this command is currently executing.
///
Expand All @@ -46,7 +46,7 @@ extern NSString * const RACUnderlyingCommandErrorKey;
///
/// This signal will send its current value upon subscription, and then all
/// future values on the main thread.
@property (nonatomic, strong, readonly) RACSignal *executing;
@property (nonatomic, strong, readonly) RACSignal<NSNumber *> *executing;

/// A signal of whether this command is able to execute.
///
Expand All @@ -60,7 +60,7 @@ extern NSString * const RACUnderlyingCommandErrorKey;
///
/// This signal will send its current value upon subscription, and then all
/// future values on the main thread.
@property (nonatomic, strong, readonly) RACSignal *enabled;
@property (nonatomic, strong, readonly) RACSignal<NSNumber *> *enabled;

/// Forwards any errors that occur within signals returned by -execute:.
///
Expand All @@ -70,7 +70,7 @@ extern NSString * const RACUnderlyingCommandErrorKey;
///
/// After subscription, this signal will send all future errors on the main
/// thread.
@property (nonatomic, strong, readonly) RACSignal *errors;
@property (nonatomic, strong, readonly) RACSignal<NSError *> *errors;

/// Whether the command allows multiple executions to proceed concurrently.
///
Expand All @@ -93,7 +93,7 @@ extern NSString * const RACUnderlyingCommandErrorKey;
/// to a replay subject, sent on `executionSignals`, then
/// subscribed to synchronously. Neither the block nor the
/// returned signal may be nil.
- (id)initWithEnabled:(nullable RACSignal *)enabledSignal signalBlock:(RACSignal * (^)(InputType _Nullable input))signalBlock;
- (id)initWithEnabled:(nullable RACSignal<NSNumber *> *)enabledSignal signalBlock:(RACSignal * (^)(InputType _Nullable input))signalBlock;

/// If the receiver is enabled, this method will:
///
Expand All @@ -108,7 +108,7 @@ extern NSString * const RACUnderlyingCommandErrorKey;
/// Returns the multicasted signal, after subscription. If the receiver is not
/// enabled, returns a signal that will send an error with code
/// RACCommandErrorNotEnabled.
- (RACSignal *)execute:(nullable InputType)input;
- (RACSignal<ValueType> *)execute:(nullable InputType)input;

NS_ASSUME_NONNULL_END
@end
Expand Down
2 changes: 1 addition & 1 deletion ReactiveObjC/RACDelegateProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#import <Foundation/Foundation.h>

@class RACSignal;
@class RACSignal<__covariant ValueType>;

// A private delegate object suitable for using
// -rac_signalForSelector:fromProtocol: upon.
Expand Down
2 changes: 1 addition & 1 deletion ReactiveObjC/RACMulticastConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import <Foundation/Foundation.h>

@class RACDisposable;
@class RACSignal;
@class RACSignal<__covariant ValueType>;

/// A multicast connection encapsulates the idea of sharing one subscription to a
/// signal to many subscribers. This is most often needed if the subscription to
Expand Down
2 changes: 1 addition & 1 deletion ReactiveObjC/RACPassthroughSubscriber.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "RACSubscriber.h"

@class RACCompoundDisposable;
@class RACSignal;
@class RACSignal<__covariant ValueType>;

// A private subscriber that passes through all events to another subscriber
// while not disposed.
Expand Down
2 changes: 1 addition & 1 deletion ReactiveObjC/RACSequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#import "RACStream.h"

@class RACScheduler;
@class RACSignal;
@class RACSignal<__covariant ValueType>;

/// Represents an immutable sequence of values. Unless otherwise specified, the
/// sequences' values are evaluated lazily on demand. Like Cocoa collections,
Expand Down
16 changes: 8 additions & 8 deletions ReactiveObjC/RACSignal.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@class RACSubject;
@protocol RACSubscriber;

@interface RACSignal : RACStream
@interface RACSignal<__covariant ValueType> : RACStream
NS_ASSUME_NONNULL_BEGIN

/// Creates a new signal. This is the preferred way to create a new signal
Expand Down Expand Up @@ -111,7 +111,7 @@ NS_ASSUME_NONNULL_BEGIN

@end

@interface RACSignal (Subscription)
@interface RACSignal<__covariant ValueType> (Subscription)

/// Subscribes `subscriber` to changes on the receiver. The receiver defines which
/// events it actually sends and in what situations the events are sent.
Expand All @@ -134,13 +134,13 @@ NS_ASSUME_NONNULL_BEGIN
/// Convenience method to subscribe to the `next` event.
///
/// This corresponds to `IObserver<T>.OnNext` in Rx.
- (RACDisposable *)subscribeNext:(void (^)(id _Nullable x))nextBlock;
- (RACDisposable *)subscribeNext:(void (^)(ValueType _Nullable x))nextBlock;

/// Convenience method to subscribe to the `next` and `completed` events.
- (RACDisposable *)subscribeNext:(void (^)(id _Nullable x))nextBlock completed:(void (^)(void))completedBlock;
- (RACDisposable *)subscribeNext:(void (^)(ValueType _Nullable x))nextBlock completed:(void (^)(void))completedBlock;

/// Convenience method to subscribe to the `next`, `completed`, and `error` events.
- (RACDisposable *)subscribeNext:(void (^)(id _Nullable x))nextBlock error:(void (^)(NSError * _Nullable error))errorBlock completed:(void (^)(void))completedBlock;
- (RACDisposable *)subscribeNext:(void (^)(ValueType _Nullable x))nextBlock error:(void (^)(NSError * _Nullable error))errorBlock completed:(void (^)(void))completedBlock;

/// Convenience method to subscribe to `error` events.
///
Expand All @@ -153,7 +153,7 @@ NS_ASSUME_NONNULL_BEGIN
- (RACDisposable *)subscribeCompleted:(void (^)(void))completedBlock;

/// Convenience method to subscribe to `next` and `error` events.
- (RACDisposable *)subscribeNext:(void (^)(id _Nullable x))nextBlock error:(void (^)(NSError * _Nullable error))errorBlock;
- (RACDisposable *)subscribeNext:(void (^)(ValueType _Nullable x))nextBlock error:(void (^)(NSError * _Nullable error))errorBlock;

/// Convenience method to subscribe to `error` and `completed` events.
- (RACDisposable *)subscribeError:(void (^)(NSError * _Nullable error))errorBlock completed:(void (^)(void))completedBlock;
Expand All @@ -180,7 +180,7 @@ NS_ASSUME_NONNULL_BEGIN
/// Additional methods to assist with unit testing.
///
/// **These methods should never ship in production code.**
@interface RACSignal (Testing)
@interface RACSignal<__covariant ValueType> (Testing)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this sort of change required? i.e., is adding generics a breaking change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this change was not enforced by the compiler—I just added it so that asynchronousFirstOrDefault could have access to ValueType. Note that RACSignal (Debugging) does not have it as part of this change.


/// Spins the main run loop for a short while, waiting for the receiver to send a `next`.
///
Expand All @@ -196,7 +196,7 @@ NS_ASSUME_NONNULL_BEGIN
///
/// Returns the first value received, or `defaultValue` if no value is received
/// before the signal finishes or the method times out.
- (nullable id)asynchronousFirstOrDefault:(nullable id)defaultValue success:(nullable BOOL *)success error:(NSError * _Nullable * _Nullable)error;
- (nullable ValueType)asynchronousFirstOrDefault:(nullable ValueType)defaultValue success:(nullable BOOL *)success error:(NSError * _Nullable * _Nullable)error;

/// Spins the main run loop for a short while, waiting for the receiver to complete.
///
Expand Down
Loading