Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(datastore): Add isLoaded public property in List+Model #3296

Merged
merged 3 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading