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 public api to register global listener #451

Merged
merged 8 commits into from
Nov 19, 2020

Conversation

shalehaha
Copy link
Contributor

@shalehaha shalehaha commented Nov 17, 2020

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.

@@ -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
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link

codecov bot commented Nov 17, 2020

Codecov Report

Merging #451 (dc32c13) into dev (f6a0550) will increase coverage by 0.10%.
The diff coverage is 100.00%.

@@            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     

@shalehaha shalehaha changed the title Add public api to register global listener [WIP] Add public api to register global listener Nov 17, 2020
Copy link
Contributor

@pfransenadb pfransenadb left a 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
Copy link
Contributor

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) {

Copy link
Contributor

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"
Copy link
Contributor

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"
Copy link
Contributor

Choose a reason for hiding this comment

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

Unrelated?

@shalehaha shalehaha changed the title [WIP] Add public api to register global listener Add public api to register global listener Nov 18, 2020
@shalehaha
Copy link
Contributor Author

@pfransenadb fixed. removed the code that is not related to this pr.

Copy link
Member

@sbenedicadb sbenedicadb left a 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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

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

register > registered

@shalehaha shalehaha merged commit c1b3112 into adobe:dev Nov 19, 2020
@@ -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
Copy link
Member

Choose a reason for hiding this comment

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

An should be A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to register a global listener, or register a random one time listener
4 participants