Skip to content

Commit

Permalink
Pass the Notification to the NotificationListener, instead of just it…
Browse files Browse the repository at this point in the history
…s `userInfo` NSDictionary
  • Loading branch information
aleclarson committed Aug 4, 2017
1 parent d78da94 commit e748743
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/NotificationListener.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public class NotificationListener : Listener {
if self._targetID != getHash(target) {
return
}
} else {
return
}
}
} else {
return
}
}

self._trigger(notif.userInfo)
self._trigger(notif)
})

// Add self to global cache.
Expand All @@ -49,10 +49,10 @@ public class NotificationListener : Listener {
NotificationListenerCache[self.name] = targets.nilIfEmpty
}

init (_ name: Notification.Name, _ target: AnyObject!, _ once: Bool, _ handler: @escaping (NSDictionary) -> Void) {
init (_ name: Notification.Name, _ target: AnyObject!, _ once: Bool, _ handler: @escaping (Notification) -> Void) {
self.name = name
super.init(target, once) {
handler(($0 as? NSDictionary) ?? [:])
handler($0 as! Notification)
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Notifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ public class Notifier {
self.name = name
}

public func on (_ handler: @escaping (NSDictionary) -> Void) -> NotificationListener {
public func on (_ handler: @escaping (Notification) -> Void) -> NotificationListener {
return NotificationListener(name, nil, false, handler)
}

public func on (_ target: AnyObject!, _ handler: @escaping (NSDictionary) -> Void) -> NotificationListener {
public func on (_ target: AnyObject!, _ handler: @escaping (Notification) -> Void) -> NotificationListener {
return NotificationListener(name, target, false, handler)
}

@discardableResult
public func once (_ handler: @escaping (NSDictionary) -> Void) -> NotificationListener {
public func once (_ handler: @escaping (Notification) -> Void) -> NotificationListener {
return NotificationListener(name, nil, true, handler)
}

@discardableResult
public func once (_ target: AnyObject!, _ handler: @escaping (NSDictionary) -> Void) -> NotificationListener {
public func once (_ target: AnyObject!, _ handler: @escaping (Notification) -> Void) -> NotificationListener {
return NotificationListener(name, target, true, handler)
}

Expand Down

0 comments on commit e748743

Please sign in to comment.