tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

HistoryTelemetryMiddlewareExample.kt (949B)


      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 HistoryTelemetryMiddleware : Middleware<HistoryState, HistoryAction> {
      8    override fun invoke(
      9        context: MiddlewareContext<HistoryState, HistoryAction>,
     10        next: (HistoryAction) -> Unit,
     11        action: HistoryAction,
     12    ) {
     13        // This middleware won't need to manipulate the action, so the action can be passed through
     14        // the middleware chain before the side-effects are initiated
     15        next(action)
     16        when(action) {
     17            is HistoryAction.DeleteItems -> History.itemsDeleted.record()
     18            is HistoryAction.OpenItem -> History.itemOpened.record()
     19            else -> Unit
     20        }
     21    }
     22 }