forked from shadowfacts/Tusker
Fix retain cycle in timeline cell cache observers
The use an unowned reference to self because when the cell is deinit'd, the Combine observers will be cancelled.
This commit is contained in:
parent
2f630f2f8f
commit
ee252c02e9
|
@ -100,16 +100,16 @@ class BaseStatusTableViewCell: UITableViewCell {
|
|||
open func createObserversIfNecessary() {
|
||||
if statusUpdater == nil {
|
||||
statusUpdater = mastodonController.cache.statusSubject
|
||||
.filter { $0.id == self.statusID }
|
||||
.filter { [unowned self] in $0.id == self.statusID }
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink(receiveValue: updateStatusState(status:))
|
||||
.sink { [unowned self] in self.updateStatusState(status: $0) }
|
||||
}
|
||||
|
||||
if accountUpdater == nil {
|
||||
accountUpdater = mastodonController.cache.accountSubject
|
||||
.filter { $0.id == self.accountID }
|
||||
.filter { [unowned self] in $0.id == self.accountID }
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink(receiveValue: updateUI(account:))
|
||||
.sink { [unowned self] in self.updateUI(account: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -49,9 +49,9 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
|
|||
|
||||
if rebloggerAccountUpdater == nil {
|
||||
rebloggerAccountUpdater = mastodonController.cache.accountSubject
|
||||
.filter { $0.id == self.rebloggerID }
|
||||
.filter { [unowned self] in $0.id == self.rebloggerID }
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink(receiveValue: updateRebloggerLabel(reblogger:))
|
||||
.sink { [unowned self] in self.updateRebloggerLabel(reblogger: $0) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,6 +95,7 @@ class TimelineStatusTableViewCell: BaseStatusTableViewCell {
|
|||
}
|
||||
|
||||
func updateTimestamp() {
|
||||
guard superview != nil else { return }
|
||||
guard let status = mastodonController.cache.status(for: statusID) else { fatalError("Missing cached status \(statusID!)") }
|
||||
|
||||
timestampLabel.text = status.createdAt.timeAgoString()
|
||||
|
|
Loading…
Reference in New Issue