dwyl / learn-elm

:rainbow: discover the beautiful programming language that makes front-end web apps a joy to build and maintain!
https://github.com/dwyl/learn-elm
483 stars 43 forks source link

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

Open SimonLab opened 5 years ago

SimonLab commented 5 years ago

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 https://github.com/dwyl/technology-stack/issues/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 commented 5 years ago

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 commented 5 years ago

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

ondrej-tucek commented 5 years ago

Okay, that would be great, thanks.

SimonLab commented 5 years ago

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

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