Skip to content

Commit 6c52750

Browse files
committed
feat: Custom interception handlers API improvements
1 parent 85f9f5f commit 6c52750

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Sources/Interception/NSObject+Interception.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ extension InterceptionHandlerProtocol {
338338
public struct SimpleInterceptionHandler: InterceptionHandlerProtocol {
339339
private var _action: (InterceptionResult<Any, Any>) -> Void
340340

341-
init(_ action: @escaping (InterceptionResult<Any, Any>) -> Void) {
341+
public init(_ action: @escaping (InterceptionResult<Any, Any>) -> Void) {
342342
self._action = action
343343
}
344344

@@ -352,8 +352,14 @@ public struct SimpleInterceptionHandler: InterceptionHandlerProtocol {
352352
public final class InterceptionHandlers {
353353
private var storage: [AnyHashable: InterceptionHandlerProtocol] = [:]
354354

355-
public func register(_ action: InterceptionHandlerProtocol?, for key: AnyHashable) {
356-
storage[key] = action
355+
public subscript(key: AnyHashable) -> InterceptionHandlerProtocol? {
356+
set { self.storage[key] = newValue }
357+
_read { yield self.storage[key] }
358+
_modify { yield &self.storage[key] }
359+
}
360+
361+
public func register(_ handler: InterceptionHandlerProtocol?, for key: AnyHashable) {
362+
storage[key] = handler
357363
}
358364

359365
public func callAsFunction(_ invocation: AnyObject) {

0 commit comments

Comments
 (0)