Lisplog

Blogging in Lisp

Search

Feed Aggregator Page 679

Rendered on Mon, 31 Jan 2022 13:02:33 GMT  newer latest older 

What's wrong with using Html.map?

via Elm - Latest posts by @Latty Gareth Latty on Fri, 28 Jan 2022 23:20:27 GMT

Html.map doesn’t really offer much value in that scenario, I would just apply the function directly (i.e: DoStuff |> toMap |> onClick). What I was trying to say is that if you pass the wrapping function down to wherever the Html is made, rather than using Html.map after it’s made, you get more flexibility which is generally preferable.

Core library fixes and improvements: Part 2

via Elm - Latest posts by @rupert Rupert Smith on Fri, 28 Jan 2022 21:52:09 GMT

Thanks for your thoughts on it. I am thinking it might make sense to turn PRs off for elm-janitor packages - to encourage the PR to be made against the official version first? Not sure if GitHub lets me turn off PRs without also turning off Issues though, I should check that.

Not quite complete yet, but I have been trying to document a process (and FAQ type stuff) here:

https://github.com/elm-janitor/manifesto/blob/master/README.md
https://github.com/elm-janitor/manifesto/blob/master/git-help.md

What's wrong with using Html.map?

via Elm - Latest posts by @rupert Rupert Smith on Fri, 28 Jan 2022 21:28:37 GMT

If you have a (Msg -> msg) function, you might use it through Html.map (or Cmd.map in an update function):

someView : (Msg -> msg) -> Model -> Html msg
someView toMsg model =
    Html.div
         [ onClick DoStuff ]
         [ ... ]
         |> Html.map toMsg

I could have done that without Html.map, but just wanted to show it can be useful in this pattern too.

Locale-aware Date/Time formatting package: pre-publish review

via Elm - Latest posts by @system system on Fri, 28 Jan 2022 21:22:44 GMT

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

Elm-charts formatting of dates

via Elm - Latest posts by @terezka Tereza Sokol on Fri, 28 Jan 2022 17:33:33 GMT

Hi @hansv! Thank you for your kind words :blush: I didn’t realize that there wasn’t a good example for editing time label formatting- thanks for letting me know! I’ll add one at my earliest convenience.

For basic formatting you can use the format attribute on the x or y labels in question (like in this example). It will give you the timestamp (in float, so you will likely need to round it) which you can format as you’d like. I like using the ryannhg/date-format package for this!

However, if you need more advanced formatting, where you’d like use some higher level information than just the timestamp (e.g. info relative to other labels such as whether this label just changed month or year etc.) you can do that too, just a little more tricky. I made you a little ellie with an example which I hope is helpful! The gist is that you need to use the generate API to produce Time's which holds all the info available for each timestamp. You can then create exactly the labels you’d like! This is not as elegant for midlevel needs as I’d like it to be right now, but I hope I’ll find a nice way to improve it in the future. In the meanwhile, thank you for your patience!

Let me know if you have any further questions!

State of JS 2021

via Elm - Latest posts by @igghibu Andrea Callea on Fri, 28 Jan 2022 16:28:46 GMT

Jim Morrison has just completed the survey :stuck_out_tongue:

Elm-charts formatting of dates

via Elm - Latest posts by @hansv Hans verschooten on Fri, 28 Jan 2022 16:24:32 GMT

Hi,

I love the elm-charts package. Definitely the easiest charting module I have ever encountered.

I could not find any documentation on how to format the dates generated by the times function. Now they are in US format, I would love to format them differently. (day/month vs month/day)

Thanks for any pointers,
Hans

What's wrong with using Html.map?

via Elm - Latest posts by @Latty Gareth Latty on Fri, 28 Jan 2022 12:06:26 GMT

So this implies that you can build even a fairly sized application using only one Msg type. In practice, this is rarely the case, only if you are building some demo/toy/one screen app.

That is why the referred statement in Html docs may be misleading in pursuing too much simplicity.

Generally if you do need to have something like that, the better solution is to take a Msg -> msg function that wraps the inner message type and return Html msg. The main advantage of this over Html.map is it doesn’t lock you into “one layer” of the message type. You can then potentially take another argument that results in a msg for something else, and the caller can provide whatever they want.

E.g: say you have some kind of reusable form. You might want internal messages to update the state of the form (some kind of FormMsg -> msg), but then take some kind of FormData -> msg for the user submitting the form, as it will be context dependent what that does, and it doesn’t really make sense for it to be internal to the form.

What's wrong with using Html.map?

via Elm - Latest posts by @romper stomper on Fri, 28 Jan 2022 10:49:51 GMT

So this implies using a single Msg type through your app, you still have hierarchy inside of it? Seems that any reasonably-sized app should have some form of hierarchal structure.

Something like that:

type Msg = 
  | CommonAppRelated
  | PartRelated (DoSomethingWithPart | DoSomethingElseWithPart)
  | OtherPartRelated (DoSomethingWithOtherPart | DoSomethingElseWithOtherPart)
  

?

Core library fixes and improvements: Part 2

via Elm - Latest posts by @rauxyo Rob on Fri, 28 Jan 2022 05:44:45 GMT

Yep I agree. :+1:

If a PR also exists in elm/core (and I assume/hope that will always be the case) it may also make sense to reference the PR as well so that there’s a direct breadcrumb from there.

But I suppose we’re down to minutiae that can be documented and iterated on in a project wiki.

Core library fixes and improvements: Part 2

via Elm - Latest posts by @jerith Matt McHenry on Fri, 28 Jan 2022 03:29:16 GMT

You’re right, I was definitely conflating PRs and issues in my last two posts! And you’re also right that it probably doesn’t make sense to have issues in elm-janitor/core – just PRs.

So let’s say we have issue elm/core#123, which has a proposed fix in PR elm/core#789, and that same fix is also submitted in PR elm-janitor/core#456. Then I think all that’s needed is fixes elm/core#123 in the commit message. I believe that’ll cause GH to auto-generate a note in the root issue elm/core#123 that references the elm-janitor/core#456 PR, because that PR’s text (taken from the commit message) will mention the issue.

That’s the key thing in my mind: people who run into an Elm bug are gonna find the original issue in the elm/* project, and if GH auto-generates that link, they’ll be able to make their way over to the elm-janitor PR and find instructions for how to make use of it in their project.

For example, I mentioned the elm/core#1018 PR in a commit on my project, and GH automatically created a link from the former to the latter. Admittedly the thing in elm/core was a PR, not an issue, but I’m pretty sure this mechanism works for either.

Core library fixes and improvements: Part 2

via Elm - Latest posts by @rauxyo Rob on Fri, 28 Jan 2022 00:16:01 GMT

I see. I thought elm/core#123 in your example was a PR because you were talking about connecting PRs. I’m not following why there would even be issues in elm-janitor/core, at least not issues that duplicate the ones in elm/core.

Core library fixes and improvements: Part 2

via Elm - Latest posts by @jerith Matt McHenry on Thu, 27 Jan 2022 23:49:01 GMT

I think “fixes” is right – if this same commit were merged into elm/core's master branch, it would fix that issue. Auto-closing won’t happen unless/until that merge happens – merging it into elm-janitor/core's master branch will only auto-close the elm-janitor/core issue.

Early release of the Elm-pair editor tool

via Elm - Latest posts by @system system on Thu, 27 Jan 2022 19:49:05 GMT

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

What's wrong with using Html.map?

via Elm - Latest posts by @Atlewee Atle Wee Førre on Thu, 27 Jan 2022 18:32:53 GMT

I have about 60k lines of code running in production, a decent sized application. I do not see any benefit of HTML.map there. I think there is only one of them in this application. But this is not pages, it’s an application. Maybe the mapping makes more sense if you build a website with pages.
I used to do more of the nested tea structure earlier, but found it much easier to just not do it.
Then there is no “parent/child”, “child/parent” or sibling communication. It’s just model update and messages. Simple stuff that works without your head hurting.

What's wrong with using Html.map?

via Elm - Latest posts by @romper stomper on Thu, 27 Jan 2022 16:55:20 GMT

So this implies that you can build even a fairly sized application using only one Msg type. In practice, this is rarely the case, only if you are building some demo/toy/one screen app.

That is why the referred statement in Html docs may be misleading in pursuing too much simplicity.

:studio_microphone: Elm Radio Episode 048: If It Compiles It Works

via Elm - Latest posts by @system system on Thu, 27 Jan 2022 16:11:50 GMT

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

State of JS 2021

via Elm - Latest posts by @tgelu Gelu Timoficiuc on Thu, 27 Jan 2022 11:30:06 GMT

That’s funny. The pairings I got seem to be different than yours :slight_smile: I guess it’s a feature.

Core library fixes and improvements: Part 2

via Elm - Latest posts by @rauxyo Rob on Thu, 27 Jan 2022 10:40:39 GMT

I don’t think “fixes” is what you want there right? That’s for auto-closing issues. Sounds like you just want to relate PRs together. So something like “Corresponds to elm/core#123” would make more sense at a glance.

State of JS 2021

via Elm - Latest posts by @norregaarden Norregaarden on Thu, 27 Jan 2022 04:35:45 GMT

Thanks, it was nice to get an overview over modern web development. All the new web API’s in particular.

 newer latest older