Skip to content

Commit

Permalink
Merge pull request #190 from turansky/strict-contract-build-element
Browse files Browse the repository at this point in the history
Strict contract for `buildElement`
  • Loading branch information
Leonya authored Apr 14, 2020
2 parents ff6b6ab + a177303 commit bbbd58f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion kotlin-extensions/src/main/kotlin/kotlinext/js/Object.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ external interface JsObject {
fun propertyIsEnumerable(v: String): Boolean
}

fun Any.asJsObject() = this as JsObject
fun Any.asJsObject() = unsafeCast<JsObject>()

external object Object {
fun <P, T : P> getPrototypeOf(o: T): P?
Expand Down
6 changes: 4 additions & 2 deletions kotlin-react/src/main/kotlin/react/RBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ fun buildElements(handler: RBuilder.() -> Unit): dynamic {

open class RBuilderSingle : RBuilder()

inline fun buildElement(handler: RBuilder.() -> Unit): ReactElement? =
RBuilder().apply(handler).childList.first() as ReactElement?
inline fun buildElement(handler: RBuilder.() -> Unit): ReactElement =
RBuilder().apply(handler)
.childList.first()
.unsafeCast<ReactElement>()

open class RElementBuilder<out P : RProps>(open val attrs: P) : RBuilder() {
fun attrs(handler: P.() -> Unit) {
Expand Down

0 comments on commit bbbd58f

Please sign in to comment.