Skip to content
New issue

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

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

Already on GitHub? # to your account

Communication between components #7

Open
jscriptcoder opened this issue Sep 23, 2016 · 4 comments
Open

Communication between components #7

jscriptcoder opened this issue Sep 23, 2016 · 4 comments

Comments

@jscriptcoder
Copy link

jscriptcoder commented Sep 23, 2016

Hi there,

this is something I ran into when playing around with Elm. Currently I'm working on a personal project, quite componentized (if that word even exists), where I need to pass information from child to parent (sometimes three levels up), child to child or even component to component that aren't in the same branch. I figured out a few possible solutions, but it would be great to have a talk about it since I don't even know if that's the right way or there is a better one, sort of standard way.

Thanks in advance

@stoeffel
Copy link
Member

hey @jscriptcoder!
maybe reading https://guide.elm-lang.org/reuse/ wil help you.
cheers

@ccapndave
Copy link

For my latest project I'm using a flat hierarchy made with extensible records which means that most of the time you simply don't need to communicate from child to parent (Noah at NoRedInk came up with this, btw, not me :) ) I don't think its the standard way, but I've found that it works really well; I'll happily show you tonight.

@stoeffel
Copy link
Member

Yes, we use that sometimes. But it's also okay to just pass parts of the model to the child view.

One pattern I recently like is (without extensible records):

select : Model -> SubModel
select model =
  { disabled = List.isEmpty model.users
  , userCount = List.length model.users
  }

subView : SubModel -> Html msg
subView model =
  -- display stuff

-- in parent
subView (select model)

@jscriptcoder
Copy link
Author

Great... thanks guys. Looking forward to tonight's meetup

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants