Skip to content
This repository has been archived by the owner on Jan 5, 2023. It is now read-only.

Combine 바인딩 이벤트가 루프에 빠지는 버그 수정 #3

Closed
maakcode opened this issue Jan 16, 2021 · 1 comment
Closed
Assignees
Labels
bug Something isn't working

Comments

@maakcode
Copy link
Owner

놀랍게도 RxSwift의 .distinctUntilChanged()는 첫 이벤트는 비교할 대상이 없으므로 이벤트를 발생시키지 않지만 Combine의 .removeDuplicates()는 비교할 대상이 없으면 이벤트를 통과시킨다. 아마도 nil 이라고 생각하는게 아닐까?
따라서 할당과 동시에 self?.tableView.reloadData() 가 돌게되며 바인딩 이벤트가 루프에 빠지게된다.

@maakcode maakcode added the bug Something isn't working label Jan 16, 2021
@maakcode maakcode self-assigned this Jan 16, 2021
@maakcode
Copy link
Owner Author

그런데 배열을 대상으로해보면 정상적으로 동작한다. 뭐지?

Observable.of(1, 1, 2, 3)
    .distinctUntilChanged()
    .subscribe(onNext: { value in
        print("Rx", value)
    })
    .disposed(by: disposeBag)
// Rx 1
// Rx 2
// Rx 3
[1, 1, 2, 3].publisher
    .removeDuplicates()
    .sink { value in
        print("Combine", value)
    }
    .store(in: &bag)
// Combine 1
// Combine 2
// Combine 3

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant