notify: switch over to new typesafe notifications

This commit is contained in:
William Casarin
2023-07-30 10:50:41 -07:00
parent 80063af19a
commit b40c595a7c
39 changed files with 129 additions and 289 deletions

View File

@@ -31,12 +31,12 @@ struct Notifications<T: Notify> {
struct NotifyHandler<T> { }
func notify_safe<T: Notify>(_ notify: Notifications<T>) {
func notify<T: Notify>(_ notify: Notifications<T>) {
let notify = notify.notify
NotificationCenter.default.post(name: T.name, object: notify.payload)
}
func handle_notify_safe<T: Notify>(_ handler: NotifyHandler<T>) -> AnyPublisher<T.Payload, Never> {
func handle_notify<T: Notify>(_ handler: NotifyHandler<T>) -> AnyPublisher<T.Payload, Never> {
return NotificationCenter.default.publisher(for: T.name)
//.compactMap { notification in notification.object as? T.Payload }
.map { notification in notification.object as! T.Payload }