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

Composition without passing parent #39

Closed
StokeMasterJack opened this issue Jun 24, 2017 · 2 comments
Closed

Composition without passing parent #39

StokeMasterJack opened this issue Jun 24, 2017 · 2 comments

Comments

@StokeMasterJack
Copy link

I would like to compose methods without passing the parent. Need some kind of add method. Something like below:

private fun renderGame(g: Game) = document.create.div {
    style = "margin:1rem;padding:1rem;background:yellow;display:flex"
    add(renderHand(g.ph))
    add(renderHand(g.dh))
}

private fun renderHand(h: Hand) = document.create.div {
    style = "margin:1rem;padding:1rem;background:#DDDDDD"
    div { b { +h.name } }
    div {
        h.cards.map { div { it.name } }
    }
    div { b { +"${h.points} points" } }
}
@kosiakk
Copy link
Contributor

kosiakk commented Sep 1, 2017

Instead of that you can declare your component function renderHand to be defined in FlowContent:

private fun FlowContent.renderHand(h:Hand) { 
   div{ 
      style = ... 
   } 
}

so that you could call your function directly, with no need for add function:

private fun renderGame(g: Game) = document.create.div {
    style = "..."
    renderHand(g.ph)
    renderHand(g.dh)
}

@cy6erGn0m
Copy link
Contributor

@StokeMasterJack I believe that Alexander (kosiakk) is completely right and this is the best solution. I don't think it is good idea to provide ability to add something without type-checking. At least it shouldn't be so easy to do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants