Skip to content

Commit

Permalink
feat(datastore): Add isLoaded public property in List+Model (#3296)
Browse files Browse the repository at this point in the history
  • Loading branch information
thisisabhash authored Oct 19, 2023
1 parent 195f0db commit bdc9b4a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
10 changes: 10 additions & 0 deletions Amplify/Categories/DataStore/Model/Lazy/List+Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ public class List<ModelType: Model>: Collection, Codable, ExpressibleByArrayLite

/// The current state of lazily loaded list
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 @@ -8,9 +8,9 @@
import Combine
import XCTest

@testable import Amplify
@testable import AmplifyTestCommon
@testable import AWSDataStorePlugin
import Amplify
import AmplifyTestCommon
import AWSDataStorePlugin

class ListTests: BaseDataStoreTests {

Expand All @@ -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 bdc9b4a

Please sign in to comment.