Be wary of becoming "stringly typed" and missing out on some of the benefits of Elm "making impossible states impossible." You can easily declare custom types to use as enums instead.
You should also be wary of pre-computing values and putting them in your model (like the "palette"). Your model is usually just the data that the user is dealing with, and you can generate all other values from the data. That's because generally computing values is cheap, and it's only updating the DOM that is costly (but that's where Elm's virtual DOM comes in). When computing values is not cheap you can use Html.lazy and still write the program declaratively. (See guide.elm-lang.org/optimization/la...)
Here's the same program with those two changes. (I threw in a Html.lazy to demonstrate how surprisingly easy that is to do, but not because it was particularly necessary.) ellie-app.com/bSwbq324RPya1
Nice! Your types and other changes really make the code more readable.
I haven't seen anonymous functions used with events before, but I can see how your approach really cleans up the update function.
So the model should be as simple as possible, and calculations should be derived from it, not part of it.
I was a bit confused by HTML.lazy, since it's not needed in this project, but this simple example illustrated very well what it does: discourse.elm-lang.org/t/how-does-...
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Be wary of becoming "stringly typed" and missing out on some of the benefits of Elm "making impossible states impossible." You can easily declare custom types to use as enums instead.
You should also be wary of pre-computing values and putting them in your model (like the "palette"). Your model is usually just the data that the user is dealing with, and you can generate all other values from the data. That's because generally computing values is cheap, and it's only updating the DOM that is costly (but that's where Elm's virtual DOM comes in). When computing values is not cheap you can use
Html.lazy
and still write the program declaratively. (See guide.elm-lang.org/optimization/la...)Here's the same program with those two changes. (I threw in a
Html.lazy
to demonstrate how surprisingly easy that is to do, but not because it was particularly necessary.)ellie-app.com/bSwbq324RPya1
Nice! Your types and other changes really make the code more readable.
I haven't seen anonymous functions used with events before, but I can see how your approach really cleans up the update function.
So the model should be as simple as possible, and calculations should be derived from it, not part of it.
I was a bit confused by HTML.lazy, since it's not needed in this project, but this simple example illustrated very well what it does: discourse.elm-lang.org/t/how-does-...