Skip to content

Instantly share code, notes, and snippets.

@pocmo
Created January 4, 2022 17:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pocmo/d4c0d285b68cb0d14ae6ae162e55f608 to your computer and use it in GitHub Desktop.
Save pocmo/d4c0d285b68cb0d14ae6ae162e55f608 to your computer and use it in GitHub Desktop.
Generic middleware
interface StateWithTopSites : State {
val topsites: List<TopSite>
}
interface TopSite {
// ..
}
interface AddTopSiteAction {
val topSite: TopSite
}
class TopSitesMiddleware<S : StateWithTopSites, A : Action> : Middleware<S, A> {
override fun invoke(
context: MiddlewareContext<S, A>,
next: (A) -> Unit,
action: A
) {
when (action) {
is AddTopSiteAction -> TODO("Add to storage")
}
next(action)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment