Last active
December 16, 2021 05:09
-
-
Save wickedev/cbd483ef1089715cecf603d6136a69f0 to your computer and use it in GitHub Desktop.
kotlin extension language for type safe macro
This file contains hidden or 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 react.dom.* | |
import react.styled | |
import kotlinx.browser.document | |
import org.w3c.dom.Window | |
import io.grpc | |
import org.graphql | |
val greetStub = grpc.stub!("proto/greeter.proto") // Type Inference & Code Generation from file contents | |
val Content = styled.div! { | |
background-color: #333333; | |
} | |
fun main() { | |
val root = document.getElementById("root") | |
render(root, html! { | |
<div> | |
<h1 id="ktx">kotlin extension</h1> | |
<Content> | |
<p>Welecome to next generation of Kotlin</p> | |
<button onClick={{ event -> | |
alert(greetStub.greeter.greeting("Ryan").await()) | |
}}> | |
Greeting | |
<button/> | |
</Content> | |
<Suspense fallback={<div>Loading...</div>}> | |
<SubCompoennt/> | |
</Suspense> | |
</div> | |
}) | |
} | |
fun SubComponent(): Element { | |
val res = useQuery(graphql! { | |
posts { | |
id | |
title | |
content | |
author { | |
id | |
name | |
} | |
} | |
}) | |
return html! { | |
<h2>Suspense sample</h2> | |
<div>{res.data?.posts.map { post -> | |
<div key={post.id}> | |
<h3>{post.title}</h3> | |
<div>{post.content}</div> | |
<div>{post.author.name}</div> | |
<div>} | |
}</div> | |
} | |
} |
This file contains hidden or 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
val server = Server { | |
val greeterService = proto.generate(GreeterService()) | |
val grpc = GrpcService.builder() | |
.addService(greeterService) | |
.build() | |
service(grpc) | |
} | |
class GreeterService: Service { | |
suspend fun greeting(name: String): String { | |
return "Hello, $name" | |
} | |
} | |
fun main() { | |
server.run() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment