More logging!
This commit is contained in:
parent
b7a4f7e30f
commit
5b116c0d4e
|
@ -38,7 +38,10 @@ actor TimelineLikeController<Item> {
|
||||||
|
|
||||||
private(set) var state = State.notLoadedInitial {
|
private(set) var state = State.notLoadedInitial {
|
||||||
willSet {
|
willSet {
|
||||||
precondition(state.canTransition(to: newValue))
|
guard state.canTransition(to: newValue) else {
|
||||||
|
logger.error("State \(self.state.debugDescription, privacy: .public) cannot transition to \(newValue.debugDescription, privacy: .public)")
|
||||||
|
preconditionFailure("cannot transition to state")
|
||||||
|
}
|
||||||
logger.debug("State: \(self.state.debugDescription, privacy: .public) -> \(newValue.debugDescription, privacy: .public)")
|
logger.debug("State: \(self.state.debugDescription, privacy: .public) -> \(newValue.debugDescription, privacy: .public)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,7 +121,10 @@ actor TimelineLikeController<Item> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func emit(event: Event) async {
|
private func emit(event: Event) async {
|
||||||
precondition(state.canEmit(event: event))
|
guard state.canEmit(event: event) else {
|
||||||
|
logger.error("State \(self.state.debugDescription, privacy: .public) cannot emit event: \(event.debugDescription, privacy: .public)")
|
||||||
|
preconditionFailure("state cannot emit event")
|
||||||
|
}
|
||||||
switch event {
|
switch event {
|
||||||
case .addLoadingIndicator:
|
case .addLoadingIndicator:
|
||||||
await delegate.handleAddLoadingIndicator()
|
await delegate.handleAddLoadingIndicator()
|
||||||
|
@ -227,7 +233,7 @@ actor TimelineLikeController<Item> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Event {
|
enum Event: CustomDebugStringConvertible {
|
||||||
case addLoadingIndicator
|
case addLoadingIndicator
|
||||||
case removeLoadingIndicator
|
case removeLoadingIndicator
|
||||||
case loadAllError(Error, LoadAttemptToken)
|
case loadAllError(Error, LoadAttemptToken)
|
||||||
|
@ -236,6 +242,27 @@ actor TimelineLikeController<Item> {
|
||||||
case prependItems([Item], LoadAttemptToken)
|
case prependItems([Item], LoadAttemptToken)
|
||||||
case loadOlderError(Error, LoadAttemptToken)
|
case loadOlderError(Error, LoadAttemptToken)
|
||||||
case appendItems([Item], LoadAttemptToken)
|
case appendItems([Item], LoadAttemptToken)
|
||||||
|
|
||||||
|
var debugDescription: String {
|
||||||
|
switch self {
|
||||||
|
case .addLoadingIndicator:
|
||||||
|
return "addLoadingIndicator"
|
||||||
|
case .removeLoadingIndicator:
|
||||||
|
return "removeLoadingIndicator"
|
||||||
|
case .loadAllError(let error, let token):
|
||||||
|
return "loadAllError(\(error), \(token))"
|
||||||
|
case .replaceAllItems(_, let token):
|
||||||
|
return "replcaeAllItems(<omitted>, \(token))"
|
||||||
|
case .loadNewerError(let error, let token):
|
||||||
|
return "loadNewerError(\(error), \(token))"
|
||||||
|
case .prependItems(_, let token):
|
||||||
|
return "prependItems(<omitted>, \(token))"
|
||||||
|
case .loadOlderError(let error, let token):
|
||||||
|
return "loadOlderError(\(error), \(token))"
|
||||||
|
case .appendItems(_, let token):
|
||||||
|
return "appendItems(<omitted>, \(token))"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoadAttemptToken: Equatable {
|
class LoadAttemptToken: Equatable {
|
||||||
|
|
Loading…
Reference in New Issue