bacta

An external router for mithril using streams.

Usage no npm install needed!

<script type="module">
  import bacta from 'https://cdn.skypack.dev/bacta';
</script>

README

bacta

This is a very early draft at an opinionated layer on top of mithril that manages:

  • routing
  • state management
  • side effects
  • more!

Please do not use this yet! Very early days!

Example

Live Example

Quick Start

import m from 'mithril'
import * as B from 'bacta'

const LoggedIn = B.maybe('LoggedIn')

B.mount( document.body, {
  Route: {
    Home: ['/', () => import('./components/home.js')],
    Login: ['/login', () => import('./components/login.js')]
  },
  initial(){
    return {
      user: LoggedIn.N()
    }
  },
  render({ activeComponent, ...attrs }){

    const Loaded = activeComponent()

    return Loaded 
      ? m(Loaded, attrs )
      : m('h1', 'Loading')
  }
})

API

attrs

  • setState
  • getState
  • link
  • subLink
  • route
  • moduleCache
  • Route
  • activeModule
  • activeComponent

B.mount

B.mount options

  • Route
  • initial
  • services
  • render
  • default
  • reducer
  • location
  • streamKey

B.component

B.types

B.createRoute

B.stream