-
Notifications
You must be signed in to change notification settings - Fork 40
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 public api to register global listener #451
Conversation
@@ -94,13 +94,23 @@ public final class MobileCore: NSObject { | |||
/// - responseCallback: Callback to be invoked with `event`'s response `Event` | |||
@objc(dispatch:responseCallback:) | |||
public static func dispatch(event: Event, responseCallback: @escaping (Event?) -> Void) { | |||
EventHub.shared.registerResponseListener(triggerEvent: event, timeout: 1) { event in | |||
EventHub.shared.registerResponseListener(triggerEvent: event, timeout: 2) { event in |
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.
should we make this timeout configurable? or at least explain that it exists in the docs for the method?
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.
will address this in a separate pr
Codecov Report
@@ Coverage Diff @@
## dev #451 +/- ##
==========================================
+ Coverage 87.46% 87.56% +0.10%
==========================================
Files 92 92
Lines 4050 4059 +9
==========================================
+ Hits 3542 3554 +12
+ Misses 508 505 -3 |
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.
Minor nit + clarity of PR.
@@ -20,5 +20,9 @@ import Foundation | |||
case callbackTimeout = 1 | |||
case callbackNil = 2 | |||
case none = 3 | |||
case serverError = 4 |
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.
Are these an artifact from some other work? I don't see them used anywhere in this PR.
/// - source: An `String` indicates the event source the current listener is listening for | ||
/// - listener: An `EventResponseListener` which will be invoked whenever the `EventHub` receives a event with matched typd and source | ||
func registerEventListener(type: String, source: String, listener: @escaping EventListener) { | ||
|
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.
nit: remove blank line.
@@ -22,6 +22,7 @@ public class EventSource: NSObject { | |||
public static let requestIdentity = "com.adobe.eventSource.requestIdentity" | |||
public static let requestProfile = "com.adobe.eventSource.requestProfile" | |||
public static let requestReset = "com.adobe.eventSource.requestReset" | |||
public static let notification = "com.adobe.eventSource.notification" |
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.
Unrelated to this PR?
@@ -34,6 +34,7 @@ public class EventType: NSObject { | |||
public static let userProfile = "com.adobe.eventType.userProfile" | |||
public static let places = "com.adobe.eventType.places" | |||
public static let offerDecisioning = "com.adobe.eventType.offerDecisioning" | |||
public static let edge = "com.adobe.eventType.edge" |
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.
Unrelated?
@pfransenadb fixed. removed the code that is not related to this pr. |
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.
looks good, just a few updates to the comments would be nice
@@ -101,6 +101,16 @@ public final class MobileCore: NSObject { | |||
EventHub.shared.dispatch(event: event) | |||
} | |||
|
|||
/// Registers an `EventListener` which will be invoked whenever a event with matched type and source is dispatched | |||
/// - Parameters: | |||
/// - type: An `String` indicates the event type the current listener is listening for |
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.
An String indicates
> A String indicating
/// Registers an `EventListener` which will be invoked whenever a event with matched type and source is dispatched | ||
/// - Parameters: | ||
/// - type: An `String` indicates the event type the current listener is listening for | ||
/// - source: An `String` indicates the event source the current listener is listening for |
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.
same here
/// - Parameters: | ||
/// - type: An `String` indicates the event type the current listener is listening for | ||
/// - source: An `String` indicates the event source the current listener is listening for | ||
/// - listener: An `EventResponseListener` which will be invoked whenever the `EventHub` receives a event with matched typd and source |
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.
typd
> type
@@ -148,6 +148,22 @@ final class EventHub { | |||
responseEventListeners.append(responseListenerContainer!) | |||
} | |||
|
|||
/// Registers an `EventListener` which will be invoked whenever a event with matched type and source is dispatched | |||
/// - Parameters: | |||
/// - type: An `String` indicates the event type the current listener is listening for |
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.
same fixes needed for copy/pasted docs
/// - listener: An `EventResponseListener` which will be invoked whenever the `EventHub` receives a event with matched typd and source | ||
func registerEventListener(type: String, source: String, listener: @escaping EventListener) { | ||
eventHubQueue.async { | ||
// use the event hub placeholder extension to hold all the listeners register from the public API |
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.
register
> registered
@@ -101,6 +101,16 @@ public final class MobileCore: NSObject { | |||
EventHub.shared.dispatch(event: event) | |||
} | |||
|
|||
/// Registers an `EventListener` which will be invoked whenever a event with matched type and source is dispatched | |||
/// - Parameters: | |||
/// - type: An `String` indicating the event type the current listener is listening for |
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.
An
should be A
Add an API to MobileCore to allow registering of an event listener. Mainly to support the scenario where an extension need to support a public permanent callback.