Skip to content

Instantly share code, notes, and snippets.

@japgolly
japgolly / stateful_spa.scala
Last active September 20, 2022 11:20
Stateful SPA
// Overview of how this works:
// 1. Initialisation data is used to create an instance of LoadedRoot.
// 2. LoadedRoot contains a component which is the virtual top-level component.
// It uses the initialisation data and can be sure that it won't change (a guarantee you don't have with component props).
// It's the only component to have state.
// The state can applies to the entire SPA, all routes.
// It gets told by the router which page to render.
// It can house logic that applies when certain pages change to certain other pages.
// 3. LoadedRoot is passed to Routes.routerConfig.
// Routes.routerConfig creates a config that sends all routes to the LoadedRoot component, using the Page & RouterCtl as props.
@mpetuska
mpetuska / JSObj.kt
Created October 14, 2021 10:49
Fluent Kotlin DSL for building JSON trees
@DslMarker
annotation class JSBuilderDsl
@DslMarker
annotation class JSSetterDsl
data class JSObj(val map: MutableMap<String, Any?> = mutableMapOf()) : MutableMap<String, Any?> by map {
object Arr {
@JSBuilderDsl
operator fun get(vararg items: Any?) = items