1 min read
Middleware
Last Updated - Platform 18.1 - SDK 13.0Middleware handle interaction across features or services.
Loading data
.withServiceMiddleware(.productListService( repository: Container.shared.repositories.productListRepository(), wishlist: Container.shared.repositories.wishlistItemRepository()))
Middleware to handle retrieving the ProductList
domain object from the data layer.
Handles the following actions:
ServiceAction.ProductList.fetch: Attempts to retrieve a ProductList
from the ProductListRepository
. Dispatches ServiceAction.ProductList.fetched
on completion.
ServiceAction.ProductList.fetchPage: Attempts to retrieve a page of the ProductList
from the ProductListRepository
. Dispatches ServiceAction.ProductList.fetchedPage
on completion.
Navigation
.withRouterMiddleware(.productListNavigation(navigator: Container.shared.navigator()))
Middleware to handle navigation actions.
Handles the following NavigationAction
destinations:
ProductListNavigationDestination.filterSelection: Builds and presents the FilterSelectionViewController
using .withDelegateMiddleware(using: store.dispatch)
to allow the Filter Selection feature to apply selected Filter
s to the current state.
Currently the Filter Selection feature is built by this middleware. To customise it you must also customise this middleware and override this action.
ProductListNavigationDestination.sortSelection: Builds and presents the SortSelectionViewController
using .withDelegateMiddleware(using: store.dispatch)
to allow the Sort Selection feature to apply a selected SortOrder
to the the current state.
Currently the Sort Selection feature is built by this middleware. To customise it you must also customise this middleware and override this action.
ProductListNavigationDestination.product: Uses the navigator
to open the Product Details feature via its deeplink using the passed product and listing ids.
Apply filters
.withFilterSelectionMiddleware(.productListFilterSelection())
Middleware to handle changes to the Filter
selection by dispatching an action to re-retrieve the ProductList
.
Handles the following actions:
FilterSelectionAction: Dispatched from the Filter Selection feature delegate middleware. Dispatches ServiceAction.ProductList.fetch
to attempt to re-retrieve the ProductList
domain object with the new Filter
selection.
Apply sort order
.withSortSelectionMiddleware(.productListSortSelection())
Middleware to handle changes to the SortOrder
by dispatching an action to re-retrieve the ProductList
.
Handles the following actions:
SortSelectionAction: Dispatched from the Sort Selection feature delegate middleware. Dispatches ServiceAction.ProductList.fetch
to attempt to re-retrieve the ProductList
domain object with the new SortOrder
selection.