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

How to reuse elm view/logic on different projects? #125

Open
SimonLab opened this issue Dec 3, 2018 · 4 comments
Open

How to reuse elm view/logic on different projects? #125

SimonLab opened this issue Dec 3, 2018 · 4 comments

Comments

@SimonLab
Copy link
Member

SimonLab commented Dec 3, 2018

On the following project: https://github.com/club-soda/club-soda-guide, one of the feature is to allow user to filter a list of drinks based on types (first level filters) and styles (sub level fitlers):

image

As the UI and logic of this type of feature is not obvious/easy to implement with vanilla js it makes sense to use elm and with the idea of being able to reuse this kind of filtering on other projects (see dwyl/technology-stack#67) I looked at how to make the elm code reusable.

I'm still not sure what is the best way to do this. Some projects will have different requirements (for example different UI, different logic of filtering...) and it's quiet tricky to make the elm code abstract enough to be reused on different type of projects. I think trying to create some code that can be used and configured anywhere would be the perfect solution but I don't think it is the right way to start as it makes things overcomplicated for a first version.

So my goal is first to create an understanding step by step guide on how to create the above type of "dropdown filter" with Elm. Then during the writing of this guide some questions and solutions will come in mind and a better (more reusable) version of this Elm module will be created.

Some reading:

some watching:

some tweets:

@ondrej-tucek
Copy link

Hi @SimonLab,

maybe this a repo could you help. Now we've almost finished it but we have to write a tons of descriptions for that (and maybe a few refactoring of code, mainly an animation part) before than we insert it on elm-package web. We've created a component (in our case it's modal window) which could be reused with different UI and different behaviours. I think that would be good point for your reading too.

@SimonLab
Copy link
Member Author

SimonLab commented Dec 3, 2018

Thanks for the link to your repository @ondrej-tucek , I'll definitely have a look at it and try to give you some feedback 👍

@ondrej-tucek
Copy link

Okay, that would be great, thanks.

@SimonLab
Copy link
Member Author

SimonLab commented Dec 4, 2018

I've done more research and reading (especially https://github.com/evancz/elm-sortable-table) to try to understand how to make the code reusable. I think the main two concepts to remember is

  • to have one source of truth for your data. Do not store the data in your package model
  • Elm doesn't work well to create reusable components. Instead create your package as a reusable view. On previous project I've done this mistake and I think I start to understand the difference and see the advantages of creating reusable views.

I'll try to explain in more details about these two points on my PR (#126)

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

2 participants