Skip to content

Commit b1501b9

Browse files
committed
fix(swift): improve ergonomics of Document.on
1 parent 26ee359 commit b1501b9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

swift/LiveViewNative/Sources/LiveViewNative/LiveViewNative.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ public class Document {
7878
/// - context: A caller-provided value which should be passed to the callback when it is invoked
7979
/// - callback: The callback to invoke when an event of the given type occurs
8080
///
81-
public func on(_ event: EventType, with context: AnyObject?, _ callback: @escaping (Document, AnyObject?) -> ()) {
81+
public func on(_ event: EventType, _ callback: @escaping (Document, AnyObject?) -> ()) {
82+
self.handlers[event] = Handler(context: nil, callback: callback)
83+
}
84+
85+
public func on<T: AnyObject>(_ event: EventType, with context: T, _ callback: @escaping (Document, AnyObject?) -> ()) {
8286
self.handlers[event] = Handler(context: context, callback: callback)
8387
}
8488

0 commit comments

Comments
 (0)