Created
September 30, 2020 09:31
-
-
Save mrampazz/4185152884cf268de85d01bea1ef5ea1 to your computer and use it in GitHub Desktop.
Redux-react implementation kotlin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import actions.ToggleSideBar | |
import react.* | |
import react.redux.rConnect | |
import reducers.AppState | |
import redux.WrapperAction | |
private interface TableStateProps : RProps { | |
var isSideBarOpen: Boolean | |
} | |
private interface TableDispatchProps : RProps { | |
var toggleSideBar: (Boolean) -> Unit | |
} | |
val wrappedTable: RClass<RProps> = | |
rConnect<AppState, ToggleSideBar, WrapperAction, RProps, TableStateProps, TableDispatchProps, TableProps>( | |
mapStateToProps = { state, _ -> | |
isSideBarOpen = state.isSideBarOpen | |
}, | |
mapDispatchToProps = { dispatch, _ -> | |
toggleSideBar = { dispatch(ToggleSideBar(it)) } | |
} | |
)(TableComponent::class.js.unsafeCast<RClass<TableProps>>()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package components | |
import kotlinx.html.js.onClickFunction | |
import react.RBuilder | |
import react.RComponent | |
import react.RProps | |
import react.RState | |
import react.dom.button | |
import react.dom.div | |
external interface TableProps : RProps { | |
var isSideBarOpen: Boolean | |
var toggleSideBar: (Boolean) -> Unit | |
} | |
class TableComponent(props: TableProps) : RComponent<TableProps, RState>(props) { | |
override fun RBuilder.render() { | |
div { | |
if (props.isSideBarOpen) { | |
+"is open" | |
} else { | |
+"is closed" | |
} | |
button { | |
attrs.onClickFunction = { props.toggleSideBar(!props.isSideBarOpen) } | |
+"click me" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment