From 736b80835f67c9c34657074ebcfbe0752bef1c18 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Thu, 17 Oct 2019 21:58:34 +0200 Subject: Move DSL builder functions out of the companion objects (#93) --- .../pl/treksoft/kvision/tabulator/Tabulator.kt | 135 ++++++++++----------- 1 file changed, 67 insertions(+), 68 deletions(-) (limited to 'kvision-modules/kvision-tabulator/src/main/kotlin') diff --git a/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt b/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt index 16638012..0f5b48ae 100644 --- a/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt +++ b/kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt @@ -603,74 +603,6 @@ open class Tabulator( } companion object { - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun Container.tabulator( - data: List? = null, - dataUpdateOnEdit: Boolean = true, - options: TabulatorOptions = TabulatorOptions(), - types: Set = setOf(), - classes: Set = setOf(), - init: (Tabulator.() -> Unit)? = null - ): Tabulator { - val tabulator = create(data, dataUpdateOnEdit, options, types, classes) - init?.invoke(tabulator) - this.add(tabulator) - return tabulator - } - - /** - * DSL builder extension function for general redux store. - */ - fun Container.tabulator( - store: ReduxStore, - dataFactory: (S) -> List, - options: TabulatorOptions = TabulatorOptions(), - types: Set = setOf(), - classes: Set = setOf(), - init: (Tabulator.() -> Unit)? = null - ): Tabulator { - val tabulator = create(store, dataFactory, options, types, classes) - init?.invoke(tabulator) - this.add(tabulator) - return tabulator - } - - /** - * DSL builder extension function for dedicated redux store (backed with a list). - */ - fun Container.tabulator( - store: ReduxStore, A>, - options: TabulatorOptions = TabulatorOptions(), - types: Set = setOf(), - classes: Set = setOf(), - init: (Tabulator.() -> Unit)? = null - ): Tabulator { - val tabulator = create(store, options, types, classes) - init?.invoke(tabulator) - this.add(tabulator) - return tabulator - } - - /** - * DSL builder extension function for dynamic data (send within options parameter). - */ - fun Container.tabulator( - options: TabulatorOptions = TabulatorOptions(), - types: Set = setOf(), - classes: Set = setOf(), - init: (Tabulator.() -> Unit)? = null - ): Tabulator { - val tabulator = Tabulator(dataUpdateOnEdit = false, options = options, types = types, classes = classes) - init?.invoke(tabulator) - this.add(tabulator) - return tabulator - } - /** * A helper function to create a Tabulator object with correct serializer. */ @@ -727,3 +659,70 @@ open class Tabulator( } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun Container.tabulator( + data: List? = null, + dataUpdateOnEdit: Boolean = true, + options: TabulatorOptions = TabulatorOptions(), + types: Set = setOf(), + classes: Set = setOf(), + init: (Tabulator.() -> Unit)? = null +): Tabulator { + val tabulator = Tabulator.create(data, dataUpdateOnEdit, options, types, classes) + init?.invoke(tabulator) + this.add(tabulator) + return tabulator +} + +/** + * DSL builder extension function for general redux store. + */ +fun Container.tabulator( + store: ReduxStore, + dataFactory: (S) -> List, + options: TabulatorOptions = TabulatorOptions(), + types: Set = setOf(), + classes: Set = setOf(), + init: (Tabulator.() -> Unit)? = null +): Tabulator { + val tabulator = Tabulator.create(store, dataFactory, options, types, classes) + init?.invoke(tabulator) + this.add(tabulator) + return tabulator +} + +/** + * DSL builder extension function for dedicated redux store (backed with a list). + */ +fun Container.tabulator( + store: ReduxStore, A>, + options: TabulatorOptions = TabulatorOptions(), + types: Set = setOf(), + classes: Set = setOf(), + init: (Tabulator.() -> Unit)? = null +): Tabulator { + val tabulator = Tabulator.create(store, options, types, classes) + init?.invoke(tabulator) + this.add(tabulator) + return tabulator +} + +/** + * DSL builder extension function for dynamic data (send within options parameter). + */ +fun Container.tabulator( + options: TabulatorOptions = TabulatorOptions(), + types: Set = setOf(), + classes: Set = setOf(), + init: (Tabulator.() -> Unit)? = null +): Tabulator { + val tabulator = Tabulator(dataUpdateOnEdit = false, options = options, types = types, classes = classes) + init?.invoke(tabulator) + this.add(tabulator) + return tabulator +} -- cgit