Skip to content
This repository was archived by the owner on Nov 2, 2022. It is now read-only.

Modularization

Ingwersaft edited this page Jun 27, 2018 · 2 revisions

DSL doesn't mean one huge unmanageable single source file, you can manage that in a couple of ways:

combine james instances

        val jamesOne = james {
            autoStart = false
            map("command1", "help") {
                send("answer1")
            }
        }
        val jamesTwo = james {
            use(jamesOne)
            map("command2", "help") {
                send("answer2")
            }
        }

extract extension block

    val moreCommands: James.()->Unit = {
        map("command2", "help"){
            send("answer2")
        }
    }
    james {
        map("command1", "help"){
            send("answer1")
        }
        moreCommands()
    }

extract mapping logic

    val logic : Mapping.() -> Unit = {
        send("answer1")
    }
    james {
        map("command1", "help", logic)
    }
Clone this wiki locally