Feat: adds clear function to HitsSource#265
Feat: adds clear function to HitsSource#265NicFontana wants to merge 8 commits intoalgolia:masterfrom
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 <Vladislav.fitz@gmail.com>
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
| } | ||
| } | ||
|
|
||
| #if os(iOS) |
There was a problem hiding this comment.
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.
Sorry, my bad. Fixed
| } | ||
| } | ||
|
|
||
| static let rawHits: Data = """ |
There was a problem hiding this comment.
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.
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.
| @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.
I didn't have any compilation failure targeting macOS and iOS. Am I missing something?
Summary
This PR adds a
clear()function toHitsSourceprotocol that can be used to clear the data source's memory, if desired.Motivation:
HitsObservableControllerhas 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
showItemsOnEmptyQueryproperty 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