Trying to get my head around commands


I wrote a small app while learning Elm.

When the user clicks the “Add shadow” button, [1] a new shadow is appended to the list of shadows, and [2] I would like to randomly generate a color for it.

Right now, I am able to append a new shadow to the list [1] and generate a random color [2] independently. I can’t figure out how to make it work togheter.

The code is way better at explaining my issue than my words:

I would like to replace the #000000 at this line with a randomly generated color (the code to generate the color is in the same file)

Thank you

If I understand correctly, you want to generate the color in the same step as the shadow is added?

If so, you’ll want to use Ranrom.step, which will require you to store a Random.Seed in your model.


I’ll look into Random.step, thanks.

I’ve found a simpler solution.
When the “Add a shadow” button is clicked, I run the command to generate a color,
when the color has been generated, I actually add the shadow with the generated color.

In code:

1 Like

@carlotm Your project has introduced me to Devbox. Thanks! I currently use Nix flakes but Devbox seems to be more user friendly and also built upon Nix.

BTW, feel free to submit your app to Built with Elm.

Yeah, it’s a lovely tool.
With the limitations of json, but lovely :slight_smile:


This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.