-
Notifications
You must be signed in to change notification settings - Fork 134
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
RUMM-2299 Core Context Application State Publisher #928
RUMM-2299 Core Context Application State Publisher #928
Conversation
26dc277
to
36a77a5
Compare
36a77a5
to
9c82e05
Compare
29594d9
to
bab5809
Compare
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.
Awesome 🚀. I left few non-blocking feedbacks 🙌.
self.notificationCenter = notificationCenter | ||
} | ||
|
||
func publish(to receiver: @escaping ContextValueReceiver<AppStateHistory>) { |
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/ The more often I see this in different publishers, the more I think it should be called startPublishing(to:)
to better express what it should do 💭. Just a note, I'm totally fine with keeping existing name (after all, it is well explained in the protocol comment).
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.
That would work, current name also correctly reflect what it should do, at the protocol level, IMO. publisher.publish(to receiver:)
Lets keep it as is for now 👍
/// Creates a Application state publisher for publishing application state | ||
/// history. | ||
/// | ||
/// - Parameters: | ||
/// - initialState: The initial application state. | ||
/// - queue: The queue for publishing the history. | ||
/// - dateProvider: The date provider for the Application state snapshot timestamp. | ||
/// - notificationCenter: The notification center where this publisher observes `UIApplication` notifications. | ||
init( | ||
initialState: AppState, | ||
queue: DispatchQueue = AppStatePublisher.defaultQueue, | ||
dateProvider: DateProvider = SystemDateProvider(), | ||
notificationCenter: NotificationCenter = .default | ||
) { |
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/ As we have a nice doc string now (🏅), I think it's worth adding in that it needs to be called on the main thread, because it calls application. applicationState
transitively:
private static var currentApplicationState: UIApplication.State {
UIApplication.managedShared?.applicationState ?? .active // fallback to most expected state
}
WDYT?
/// Creates a Application state publisher for publishing application state | |
/// history. | |
/// | |
/// - Parameters: | |
/// - initialState: The initial application state. | |
/// - queue: The queue for publishing the history. | |
/// - dateProvider: The date provider for the Application state snapshot timestamp. | |
/// - notificationCenter: The notification center where this publisher observes `UIApplication` notifications. | |
init( | |
initialState: AppState, | |
queue: DispatchQueue = AppStatePublisher.defaultQueue, | |
dateProvider: DateProvider = SystemDateProvider(), | |
notificationCenter: NotificationCenter = .default | |
) { | |
/// Creates a Application state publisher for publishing application state | |
/// history. | |
/// | |
/// **Note**: It must be called on the main thread. | |
/// | |
/// - Parameters: | |
/// - initialState: The initial application state. | |
/// - queue: The queue for publishing the history. | |
/// - dateProvider: The date provider for the Application state snapshot timestamp. | |
/// - notificationCenter: The notification center where this publisher observes `UIApplication` notifications. | |
init( | |
initialState: AppState, | |
queue: DispatchQueue = AppStatePublisher.defaultQueue, | |
dateProvider: DateProvider = SystemDateProvider(), | |
notificationCenter: NotificationCenter = .default | |
) { |
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.
Oh indeed, but this should be documented in the extension below, the one that uses UIKit
.
I didn't know about threading constraint on UIApplication/applicationState
. This is a good argument to make the subscription/assignment thread-safe as you mentioned here so we can dispatch the ApplicationStatePublisher
init and subscription on the main thread!
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.
Ah, indeed it has a consequence on subscriptions
(array) thread-safety. Good call 👍.
Sources/Datadog/DatadogCore/Context/NetworkConnectionInfoPublisher.swift
Outdated
Show resolved
Hide resolved
bab5809
to
2bb18fa
Compare
2bb18fa
to
f75119a
Compare
What and why?
Publish application state to Datadog Context.
How?
Implement a
AppStatePublisher
that complies toContextValuePublisher
and provideAppStateHistory
to the context.Review checklist
Custom CI job configuration (optional)