Skip to content

Conversation

@devpolant
Copy link

Updates

In this pull request I'm going to fix the logic of registering new tap handlers.

Previous implementation of this method is completely wrong, because copy-on-write behaviour was not considered.

New handler was appended to copy in this line - handlers.append(handler). tapHandlers dictionary was not changes, so as a user:

  • I was not able to register second tap handler for the same node
  • I was not able to register new tap handler if I disposed previous one

This is old implementation:

    @discardableResult public func onTap(tapCount: Int = 1, f: @escaping (TapEvent) -> Void) -> Disposable {
        let handler = ChangeHandler<TapEvent>(f)
        if var handlers = tapHandlers[tapCount] { // array copy is created
            handlers.append(handler) // copy is mutated here, so changes not applied to `self.tapHandlers`
        } else {
            tapHandlers[tapCount] = [handler]
        }

        return Disposable { [weak self, unowned handler]  in
            guard let index = self?.tapHandlers[tapCount]?.firstIndex(of: handler) else {
                return
            }

            self?.tapHandlers[tapCount]?.remove(at: index)
        }
    }

Issue is fixed in new implementation.

…ed copy on write behavior, so it was not possible to register second tap hander.
@ystrot ystrot self-assigned this Jul 17, 2020
@ystrot ystrot added this to the 0.9.7 milestone Jul 17, 2020
@ystrot ystrot merged commit 2a8e6ee into exyte:master Jul 17, 2020
@ystrot
Copy link
Member

ystrot commented Jul 17, 2020

Thank you for the fix! Merged it.

@devpolant devpolant deleted the bugfix/touch-handling branch August 3, 2020 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants