diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-10-17 21:58:34 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-10-17 21:58:34 +0200 |
commit | 736b80835f67c9c34657074ebcfbe0752bef1c18 (patch) | |
tree | 82d1e18a9ec07692dfe5dd31f470b842a9950a89 /kvision-modules/kvision-tabulator/src | |
parent | 53b325d52208bfd44ba6a524ce3dda5379aed699 (diff) | |
download | kvision-736b80835f67c9c34657074ebcfbe0752bef1c18.tar.gz kvision-736b80835f67c9c34657074ebcfbe0752bef1c18.tar.bz2 kvision-736b80835f67c9c34657074ebcfbe0752bef1c18.zip |
Move DSL builder functions out of the companion objects (#93)
Diffstat (limited to 'kvision-modules/kvision-tabulator/src')
-rw-r--r-- | kvision-modules/kvision-tabulator/src/main/kotlin/pl/treksoft/kvision/tabulator/Tabulator.kt | 135 |
1 files changed, 67 insertions, 68 deletions
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<T : Any>( } companion object { - - /** - * DSL builder extension function. - * - * It takes the same parameters as the constructor of the built component. - */ - fun <T : Any> Container.tabulator( - data: List<T>? = null, - dataUpdateOnEdit: Boolean = true, - options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - init: (Tabulator<T>.() -> Unit)? = null - ): Tabulator<T> { - 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 <T : Any, S : Any, A : RAction> Container.tabulator( - store: ReduxStore<S, A>, - dataFactory: (S) -> List<T>, - options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - init: (Tabulator<T>.() -> Unit)? = null - ): Tabulator<T> { - 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 <T : Any, A : RAction> Container.tabulator( - store: ReduxStore<List<T>, A>, - options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - init: (Tabulator<T>.() -> Unit)? = null - ): Tabulator<T> { - 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 <T : Any> Container.tabulator( - options: TabulatorOptions<T> = TabulatorOptions(), - types: Set<TableType> = setOf(), - classes: Set<String> = setOf(), - init: (Tabulator<T>.() -> Unit)? = null - ): Tabulator<T> { - 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<T : Any>( } } } + +/** + * DSL builder extension function. + * + * It takes the same parameters as the constructor of the built component. + */ +fun <T : Any> Container.tabulator( + data: List<T>? = null, + dataUpdateOnEdit: Boolean = true, + options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf(), + init: (Tabulator<T>.() -> Unit)? = null +): Tabulator<T> { + 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 <T : Any, S : Any, A : RAction> Container.tabulator( + store: ReduxStore<S, A>, + dataFactory: (S) -> List<T>, + options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf(), + init: (Tabulator<T>.() -> Unit)? = null +): Tabulator<T> { + 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 <T : Any, A : RAction> Container.tabulator( + store: ReduxStore<List<T>, A>, + options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf(), + init: (Tabulator<T>.() -> Unit)? = null +): Tabulator<T> { + 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 <T : Any> Container.tabulator( + options: TabulatorOptions<T> = TabulatorOptions(), + types: Set<TableType> = setOf(), + classes: Set<String> = setOf(), + init: (Tabulator<T>.() -> Unit)? = null +): Tabulator<T> { + val tabulator = Tabulator(dataUpdateOnEdit = false, options = options, types = types, classes = classes) + init?.invoke(tabulator) + this.add(tabulator) + return tabulator +} |