-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Allow NSObject.reactive.signal to also intercept and return the 'return' value of the executed selector. #3557
base: master
Are you sure you want to change the base?
Conversation
…elector) NSObject.reactive.signal(for selector: Selector, includeReturnValue: Bool = false) Will add a return value to the end of the NSArray. If the method returns Void, than the flag is ignored and no value is appended to the NSArray.
03c17dd
to
f37617d
Compare
It looks great with a quick skim. I will take a second look ASAP. In the meantime, could you please clean up the indentation, the excess blank lines & break the long lines? The GitHub shows quite a few nits. |
…agray/ReactiveCocoa into reactive_signal_include_return_vals
/// - returns: A signal that sends an array of bridged arguments. | ||
public func signal(for selector: Selector) -> Signal<[Any?], NoError> { | ||
return base.intercept(selector).map(unpackInvocation) | ||
public func signal(for selector: Selector, includeReturnValue: Bool = false) -> Signal<[Any?], NoError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is API-compatible but binary-incompatible change. So the original API should be kept as is and the new API should be added as a separete one.
/// - selector: The selector to observe. | ||
/// - includeReturnValue: the array will include the value returned by the invocation. Ignored if the selector returns Void. | ||
/// - returns: A signal that sends an array of bridged arguments. | ||
public func signal(for selector: Selector, includeReturnValue: Bool) -> Signal<[Any?], NoError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to me the wrong way to do this. Instead, it would be better to have a struct
that tied together the parameters and return value.
struct Invocation {
var parameters: [Any?]
var returnValue: Any?
}
|
||
invocation.copyReturnValue(to: buffer) | ||
value = NSValue(bytes: buffer, objCType: retRawEncoding) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's code duplication here between this and the parameters. I think they could be combined so that all this logic doesn't need to be repeated.
case is CInt.Type: | ||
return #selector(InterceptedObject.testReturnValuesI(arg:)) | ||
case is CLong.Type: | ||
return #selector(InterceptedObject.testReturnValuesL(arg:)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this logic unnecessarily complicates the test. It would be better to pass in the Selector
directly if possible.
Added the
includeReturnValue
to reactive.signal(for selector: Selector)NSObject.reactive.signal(for selector: Selector, includeReturnValue: Bool = false)
Will add a return value to the end of the array, for each value of the Signal.
If the selector does not return a value, than the flag is ignored and no value is appended to the array.
Checklist