-
Notifications
You must be signed in to change notification settings - Fork 59
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: adds clear function to HitsSource #265
base: master
Are you sure you want to change the base?
Feat: adds clear function to HitsSource #265
Conversation
Thank your for your PR, @NicFontana !
This assumption is not consistent with the InstantSearch architecture. The source of truth containing the information about the current state of If you want to clear your hits view manually, you might do it by changing the However, there is actually no simple way to reset the |
Sources/InstantSearchSwiftUI/DataModel/HitsObservableController.swift
Outdated
Show resolved
Hide resolved
Sources/InstantSearchSwiftUI/DataModel/HitsObservableController.swift
Outdated
Show resolved
Hide resolved
Co-authored-by: Vladislav Fitc <[email protected]>
Also mark `HitsObservableController` @published props as private(set)
Hello @VladislavFitz Thanks for your feedback, I followed your suggestions in the last commit. I also marked with
|
Fix build issue due to private(set) accessor of `hits` in HitsObservableController
@@ -68,42 +68,83 @@ | |||
} | |||
} | |||
|
|||
#if os(iOS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By removing this conditional compiling clause, you make it fail while compiling for macOS
. So, the test
step fails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my bad. Fixed
} | ||
} | ||
|
||
static let rawHits: Data = """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the goal of this change? I purposely used String
as a simplest type to simplify testing as much as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By declaring @Published private(set) public var hits: [Hit?]
I wasn't capable anymore to set hits
directly, so I had to use a sample HitsInteractor
with sample data
@Published public var hits: [Hit?] | ||
|
||
/// List of hits items to present | ||
@Published private(set) public var hits: [Hit?] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Published private(set) public var hits: [Hit?] | |
@Published public var hits: [Hit?] |
This field is set from the InstantSearchCore
module, so it cannot be declared as private(set)
without compilation failure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't have any compilation failure targeting macOS and iOS. Am I missing something?
Summary
This PR adds a
clear()
function toHitsSource
protocol that can be used to clear the data source's memory, if desired.Motivation:
HitsObservableController
has a@Published public var hits: [Hit?]
property that can be set empty to show an empty result list.For instance, we can set it empty if we want to clear the results list for any reason, and not just when a query becomes empty by leveraging the
showItemsOnEmptyQuery
property ofHitsInteractor.Settings
.Result
As a result we have a reduced memory consumption when we assign an empty array to
HitsObservableController
's hits and whenever desired.I also added a couple of tests that cover the new introduced code.
I hope this can be useful and the same result is not achievable in another way, otherwise, I apologize.
Please let me know if I missed something.
Thank you