-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OfflineIndexObserver for insight to Offline state (#206)
### Description - Update tests to expect offline index observer events - Update changelog - Add debug description strings for CoreOfflineIndexChangeEventType ### Checklist - [x] Update `CHANGELOG`
- Loading branch information
Showing
10 changed files
with
94 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
Sources/MapboxSearch/InternalAPI/Offline/CoreOfflineIndexChangeEventType.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright © 2024 Mapbox. All rights reserved. | ||
|
||
import Foundation | ||
|
||
extension CoreOfflineIndexChangeEventType: CustomDebugStringConvertible { | ||
public var debugDescription: String { | ||
switch self { | ||
case .added: | ||
return "Added" | ||
case .removed: | ||
return "Removed" | ||
case .updated: | ||
return "Updated" | ||
@unknown default: | ||
return "Unknown" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
Sources/MapboxSearch/PublicAPI/Offline/OfflineIndexObserver.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright © 2024 Mapbox. All rights reserved. | ||
|
||
import Foundation | ||
|
||
class OfflineIndexObserver: CoreOfflineIndexObserver { | ||
enum Types { | ||
typealias indexChangedBlock = (CoreOfflineIndexChangeEvent) -> Void | ||
typealias errorBlock = (CoreOfflineIndexError) -> Void | ||
} | ||
|
||
private var onIndexChangedBlock: Types.indexChangedBlock | ||
private var onErrorBlock: Types.errorBlock | ||
|
||
init( | ||
onIndexChangedBlock: @escaping Types.indexChangedBlock = { _ in }, | ||
onErrorBlock: @escaping Types.errorBlock = { _ in } | ||
) { | ||
self.onIndexChangedBlock = onIndexChangedBlock | ||
self.onErrorBlock = onErrorBlock | ||
} | ||
|
||
func onIndexChanged(for event: CoreOfflineIndexChangeEvent) { | ||
onIndexChangedBlock(event) | ||
} | ||
|
||
func onError(forError error: CoreOfflineIndexError) { | ||
onErrorBlock(error) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters