HistoryNavigationMiddlewareExample.kt (1123B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 // This is example code for the 'Simplified Example' section of 6 // /docs/architecture-overview.md 7 class HistoryNavigationMiddleware( 8 private val navController: NavController, 9 ) : Middleware<HistoryState, HistoryAction> { 10 override fun invoke( 11 context: MiddlewareContext<HistoryState, HistoryAction>, 12 next: (HistoryAction) -> Unit, 13 action: HistoryAction, 14 ) { 15 // This middleware won't need to manipulate the action, so the action can be passed through 16 // the middleware chain before the side-effects are initiated 17 next(action) 18 when(action) { 19 is HistoryAction.OpenItem -> { 20 navController.openToBrowserAndLoad( 21 searchTermOrURL = item.url, 22 newTab = true, 23 from = BrowserDirection.FromHistory, 24 ) 25 } 26 else -> Unit 27 } 28 } 29 }