Skip to content

Commit bdc9b4a

Browse files
authored
feat(datastore): Add isLoaded public property in List+Model (#3296)
1 parent 195f0db commit bdc9b4a

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

Amplify/Categories/DataStore/Model/Lazy/List+Model.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ public class List<ModelType: Model>: Collection, Codable, ExpressibleByArrayLite
2626

2727
/// The current state of lazily loaded list
2828
var loadedState: LoadedState
29+
30+
/// Boolean property to check if list is loaded
31+
public var isLoaded: Bool {
32+
if case .loaded = loadedState {
33+
return true
34+
}
35+
36+
return false
37+
}
2938

3039
/// The provider for fulfilling list behaviors
3140
let listProvider: AnyModelListProvider<Element>
@@ -61,6 +70,7 @@ public class List<ModelType: Model>: Collection, Codable, ExpressibleByArrayLite
6170
}
6271
}
6372

73+
6474
// MARK: - Initializers
6575

6676
public init(listProvider: AnyModelListProvider<ModelType>) {

AmplifyPlugins/DataStore/Tests/AWSDataStorePluginTests/Core/ListTests.swift

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import Combine
99
import XCTest
1010

11-
@testable import Amplify
12-
@testable import AmplifyTestCommon
13-
@testable import AWSDataStorePlugin
11+
import Amplify
12+
import AmplifyTestCommon
13+
import AWSDataStorePlugin
1414

1515
class ListTests: BaseDataStoreTests {
1616

@@ -25,15 +25,9 @@ class ListTests: BaseDataStoreTests {
2525
let postId = preparePostDataForTest()
2626

2727
func checkComments(_ comments: List<Comment>) async throws {
28-
guard case .notLoaded = comments.loadedState else {
29-
XCTFail("Should not be loaded")
30-
return
31-
}
28+
XCTAssertFalse(comments.isLoaded)
3229
try await comments.fetch()
33-
guard case .loaded = comments.loadedState else {
34-
XCTFail("Should be loaded")
35-
return
36-
}
30+
XCTAssertTrue(comments.isLoaded)
3731
XCTAssertEqual(comments.count, 2)
3832
expect.fulfill()
3933
}

0 commit comments

Comments
 (0)