Skip to content

Commit

Permalink
Add a public boolean isLoaded property
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisabhash committed Oct 13, 2023
1 parent e7150df commit 259ae94
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
14 changes: 12 additions & 2 deletions Amplify/Categories/DataStore/Model/Lazy/List+Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,22 @@ public class List<ModelType: Model>: Collection, Codable, ExpressibleByArrayLite
public typealias Element = ModelType

/// Represents the data state of the `List`.
public enum LoadedState {
enum LoadedState {
case notLoaded
case loaded([Element])
}

/// The current state of lazily loaded list
public internal(set) var loadedState: LoadedState
var loadedState: LoadedState

/// Boolean property to check if list is loaded
public var isLoaded: Bool {
if case .loaded = loadedState {
return true
}

return false
}

/// The provider for fulfilling list behaviors
let listProvider: AnyModelListProvider<Element>
Expand Down Expand Up @@ -61,6 +70,7 @@ public class List<ModelType: Model>: Collection, Codable, ExpressibleByArrayLite
}
}


// MARK: - Initializers

public init(listProvider: AnyModelListProvider<ModelType>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ class ListTests: BaseDataStoreTests {
let postId = preparePostDataForTest()

func checkComments(_ comments: List<Comment>) async throws {
guard case .notLoaded = comments.loadedState else {
XCTFail("Should not be loaded")
return
}
XCTAssertFalse(comments.isLoaded)
try await comments.fetch()
guard case .loaded = comments.loadedState else {
XCTFail("Should be loaded")
return
}
XCTAssertTrue(comments.isLoaded)
XCTAssertEqual(comments.count, 2)
expect.fulfill()
}
Expand Down

0 comments on commit 259ae94

Please sign in to comment.