Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict contract for buildElement #190

Merged
merged 1 commit into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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