Fork me on GitHub
#clojurescript
<
2022-09-21
>
Mark Wardle16:09:17

Hi all. Is there a clever way of sorting by a javascript value such as goog.date.Date? I currently have (sort-by #(-> ^Date % :t_ms_event/date .getTime) my-sequence-of-items) but it is brittle, doesn't handle nil values. I guess I need a comparator that can handle that type? If it makes a difference, I'm using Fulcro.

p-himik16:09:02

If you replace that -> with some-> it should handle nil values just fine. Apart from that, there's nothing wrong in your approach, although I find it strange that you annotate % with ^Date (which should probably be ^js/Date) and then extract :t_ms_event/date from it.

Mark Wardle16:09:01

Thanks @U2FRKM4TW ! It's a goog.date.Date which I am importing so it would work, but the hint is in the wrong place so well spotted. PS enjoyed your recent podcast!

p-himik16:09:26

Ah, right. But that hint is useless anyway - it's basically a documentation for you, unless you see the compiler complaining about .getTime (which it shouldn't). And thanks. :)

👍 1
MegaMatt18:09:10

How can i use apply on a constructor eg (apply new js/Date date-arr) <- doesn't work. also doesn't work (apply js/Date. date-arr)

p-himik18:09:08

(let [bound-constructor (.. js/Function bind (apply js/Date date-arr))]
  (new bound-constructor))
or something like that.

Lone Ranger22:09:32

Whoaa that's pretty rad

Lone Ranger22:09:12

I should learn JavaScript some day

MegaMatt22:09:49

oof. that's pretty involved 😄 thanks for posting it.

karkunow23:09:38

Does anyone knows how to avoid multiple repetitive refers? E.g. if I have a Material UI lib and want to refer all of the components in different source files. I want to bundle icons into one big .cljs file and MUI components into another one and just :use or :refer them. Currently, as it seems to me, it is impossible to do.

p-himik06:09:19

I myself unconditionally prefer :as often with a single-character alias.

karkunow11:09:29

Yeah, we can use it. But in "ideal" world it would be great just to :refer :all and forget about prefix

dnolen15:09:33

This is an old decision, use an alias - and I don’t recommend single char aliases

👍 1
p-himik15:09:47

Re single chars - just something personal or is there something technical behind it?

dnolen16:09:56

it’s like single letter var names, it’s annoying - I used to do this too years ago - no more

p-himik16:09:48

Ah, well, maybe I'll arrive there at some point. :) But so far it feels just fine and s for spec seems to be kinda stuck in the community as well.

dnolen16:09:41

sure for stuff like spec ok, but for a lot of namespaces you’re not doing yourself any favors IMO

p-himik16:09:53

Maybe we're actually on the same note here - I'm using them only for very specific "low-level" namespaces, with a particular alias always representing a particular namespace within a particular project. E.g. in one of the projects r is always reagent.core (third-party, global) and i is always my.project.ui.icons (project-specific). I definitely don't use r as well for my.project.reagent-stuff or using x for my.project.ns1.x and my.project.ns2.x.

👍 1
karkunow22:09:33

Thanks! 🙂