Fork me on GitHub
Mark Wardle16:09:17

Hi all. Is there a clever way of sorting by a javascript value such as 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.


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 which I am importing so it would work, but the hint is in the wrong place so well spotted. PS enjoyed your recent podcast!


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

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)


(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


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


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.


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


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


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

👍 1

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


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


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.


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


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

Thanks! 🙂