Skip to content

Commit

Permalink
feat: Custom interception handlers API improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
maximkrouk committed Jan 30, 2024
1 parent 85f9f5f commit 6c52750
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Sources/Interception/NSObject+Interception.swift
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ extension InterceptionHandlerProtocol {
public struct SimpleInterceptionHandler: InterceptionHandlerProtocol {
private var _action: (InterceptionResult<Any, Any>) -> Void

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

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

public func register(_ action: InterceptionHandlerProtocol?, for key: AnyHashable) {
storage[key] = action
public subscript(key: AnyHashable) -> InterceptionHandlerProtocol? {
set { self.storage[key] = newValue }
_read { yield self.storage[key] }
_modify { yield &self.storage[key] }
}

public func register(_ handler: InterceptionHandlerProtocol?, for key: AnyHashable) {
storage[key] = handler
}

public func callAsFunction(_ invocation: AnyObject) {
Expand Down

0 comments on commit 6c52750

Please sign in to comment.