1 min read
Filter Selection
Last Updated - Platform 19.0.0 - SDK 14.0.0Builders are the main setup and customisation point of a feature. However, containers can be used to customise standard dependencies of a feature for all instances of that feature.
The FilterSelectionBuilder
is constrained to a FilterSelectionState
where the default type is PoqFilterSelectionState
.
It uses delegateMiddleware
to apply the Filter
selection to the Product List or previous feature.
The ProductListState
has a filter
sub-state that can be easily passed to the FilterSelectionBuilder
.
Customise the filters feature
To customise middleware or reducers you will need to override the product list navigation middleware.
Create a new Swift file for the custom navigation middleware with the following code.
import PoqFoundationimport PoqProductList
extension Middleware where State : ProductListState { static func customNavigation() -> Middleware { Middleware { (store, action) in store.continue(action) guard let action = action as? NavigationAction else { return } guard let destination = action.destination as? ProductListNavigationDestination else { return } switch destination { case .filterSelection: guard let state = store.state else { break } guard !state.filters.available.isEmpty else { break } // Customise and set up the filters feature. let viewController = FilterSelectionBuilder() .withDelegateMiddleware(using: store.dispatch) .build(with: state.filters) // Modally present the filters feature. NavigationHelper.shared.present(viewController) default: // Otherwise execute the default middleware. Middleware.productListNavigation() .execute(store: store, action: action) } } }}
You must provide delegate middleware to the FilterSelectionBuilder
within your code.
Open your AppModule
and modify the ProductListBuilder
variable that you set up earlier.
import PoqFoundationimport PoqProductList
class AppModule: PoqModule { var productListBuilder: ProductListBuilder { ProductListBuilder() .withNavigationMiddleware(.customNavigation()) }}
You have customised the filters feature.
Container customisation
Containers can be used to customise services, mappers, views and more by modifying your AppModule
to inject custom implementations into Container.shared
.
A good location for this code is at the beginning of the setUpProductList
function, or in setUpDependencies
for global dependencies. See the full list of dependencies, used by this feature, below.
See views for a comprehensive list of views in this feature.
Builder customisation
Example of basic usage.
let viewController = FilterSelectionBuilder() .withDelegateMiddleware(using: store.dispatch) .build(with: state.filters)
Example of usage with custom view controller subclass.
let viewController: CustomFilterSelectionViewController = FilterSelectionBuilder() .withDelegateMiddleware(using: store.dispatch) .build(with: state.filters)
Example of usage with customisation.
let viewController = FilterSelectionBuilder<CustomFilterSelectionState>() .withDelegateMiddleware(using: { (action) in guard case FilterSelectionAction.apply(let filters) = action else { return store.dispatch(action) } filters.forEach({ print($0) }) store.dispatch(FilterSelectionAction.apply(filters)) }) .withRouterMiddleware(.customNavigation()) .withView(CustomView()) .withViewDataMapper(CustomViewDataMapper()) .build(with: staticFilters)