Fork me on GitHub
#clojurescript
<
2020-02-12
>
rickmoynihan07:02:26

Hey; Are there any recommendations for cljc time libraries? My main requirement right now is actually just preserving the type information across the wire from clojure (java.time types) to clojurescript via transit. i.e. preserving that a value is an OffsetDateTime or a LocalDate or a LocalDateTime or a Period etc… rather than actually doing anything with the information; other than displaying it via a format string. Though at some point I’ll want to sort and compare times of the same type; I probably won’t ever need much date/time arithmetic. Candidates as I see it are: 1. https://github.com/henryw374/time-literals 2. https://github.com/juxt/tick 3. https://github.com/henryw374/cljc.java-time Actually looking at these maybe cljc.java-time is what I want or just the time-literals?

rickmoynihan08:02:55

Thinking the cljc.java-time and time-literals combo look ace.

dominicm11:02:20

They're all the same. :)

dominicm11:02:29

Tick uses the others.

dominicm11:02:42

Imo, tick is a nice interface over java time.

dominicm11:02:51

But they're all by juxt

rickmoynihan11:02:45

Yeah… I don’t need tick just yet… I really just need containers for the types

rickmoynihan11:02:08

will include it when I need it though

pinkfrog08:02:03

is there any nice theme to choose from when building a website?

rickmoynihan08:02:04

I’m no expert; but if you don’t know any better and are doing a greenfield project; you probably want to first pick a grid-system/css-framework — and then either theme it yourself or find a theme for it. No idea what is currently in vogue (it changes every week) but some starting points to look at would be: - https://get.foundation/ - https://getbootstrap.com/ - http://getskeleton.com/ - https://material.io/design/

rickmoynihan08:02:18

What you pick will most likely depend on what kind of site/app you’re building; and what features you need; e.g. responsive, grid, widgets etc.

pinkfrog09:02:27

i’d go with bulma and material-ui react.

rickmoynihan09:02:40

ahh yes bulma was the other one… I was struggling to remember its name!

kaffein12:02:27

Hey friends, I have a little (beginner) question please about the way we manipulate js objects directly from cljs. I have the following object defined with the js literal :

dev:cljs.user!{:conn 2}=> (def student #js {"locker" 212
                     #_=>                   "grades" {"Math" "A",
                     #_=>                             "Physics" "B",
                     #_=>                             "English" "A+"}})
I would like to modify the “Physics” value and I thought I could use aset like this :
dev:cljs.user=> (aset student "grades" "Physics" "my new-value")
"my new-value"
but then I end up with this :
dev:cljs.user=> student
#js {:locker 212, :grades {"Math" "A", "Physics" "B", "English" "A+"}}
dev:cljs.user=> (aget student "grades")
{"Math" "A", "Physics" "B", "English" "A+"}
The new value was not applied even though when I access the “Physics” value again with aget, I have :
dev:cljs.user=> (aget student "grades" "Physics")
"my new-value"
did I miss something ?

Wilson Velez13:02:24

@U0DTAJS3Y from the docs aset and aget work with arrays but you have a map, the way I change the value in a map is

(assoc-in student ["grades" "Physics"] "my new value")

kaffein13:02:35

I was actually expecting some magic trick to happen with aset since you could access nested structures with aget if I am not wrong

kaffein13:02:51

but thanks for the hint 😉

p-himik13:02:31

The issue is that #js is not recursive. You end up with a plain JS object that contains a ClojureScript vector under its "grades" key`. If you specify #js in front of every map and vector, aset would work. But you should not use it as it's designed to work only with arrays. There are other options: 1. Use multiple calls to goog.object.set - will work with any keys 2. Use (set! (.. student -grades -Physics) "my new-value") - will work only with keys that are valid symbols 3. Use https://github.com/binaryage/cljs-oops 4. Use https://github.com/mfikes/cljs-bean 5. Don't manipulate JS data structures at all - manipulate only CLJS data structures and then convert them to JS when needed (the least preferred solution if you care about performance)

💯 4
👍 4
kaffein14:02:11

thanks a lot for the explanation @U2FRKM4TW 🙂

pinkfrog13:02:08

can anybody shed some light on how the frontend of this site is built?

pinkfrog13:02:42

I feel it’s written with react. but how is the css part, and how is the html structured? any framework involved?

Lu14:02:14

CSS is very polished .. for the rest there’s not much going on .. I didn’t inspect the page to check if it’s react and personally I wouldn’t use it for something like that because I feel it’s overkill ..

Janne Sauvala14:02:16

My Wappalyzer chrome plugin detected React + Next.js

👍 8
rickmoynihan14:02:06

Is there a more idiomatic way to write this in cljs (simplified):

(require '[js-joda])

(defmulti render-value type)

(defmethod render-value (.. js-joda -LocalDateTime) [ldt]
    (str ldt))

p-himik14:02:26

If you're using shadow-cljs, you can use ["js-joda" :refer [LocalDateTime]] require. But I have no idea if that would work with self-hosted CLJS.

rickmoynihan14:02:14

ahh yes that does work. Thanks I forgot about that syntax; I’ve used it once before a long time ago

Wilson Velez15:02:55

I’m following an highchart react example to build something in cljs, this is how I’m creating the component

[:> HighchartsReact {:highcharts Highcharts
                     :constructorType "stockChart"
                     :options stock-config}]
however it is failing because: > The “constructorType” property is incorrect or some required module is not imported. And it probably is because I haven’t imported the exporting.js module, but I haven’t been able to write it right, this is what it need to include,
require('highcharts/modules/exporting')(Highcharts)
how can I translate this to a cljs require?

p-himik15:02:18

> it probably is because I haven’t imported the exporting.js module Why do you think that?

p-himik15:02:41

How did you require Highcharts?

Wilson Velez15:02:16

I had a normal chart working, that doesn’t need the constructorType property, and it was working, now that I want to test stockchart I’m following a different example, and in that example (https://stackblitz.com/edit/react-4ded5d?file=index.js) there are many things included, exporting is one of them, also in the reagent example with highcharts they include the exporting.js in the html directly (https://github.com/reagent-project/reagent-cookbook/tree/master/recipes/highcharts)

Wilson Velez15:02:33

and currently I’m importing Highcharts like this

["highcharts" :default Highcharts]
["highcharts-react-official" :default HighchartsReact]

p-himik15:02:31

The highcharts-react examples uses:

import Highcharts from 'highcharts/highstock'
You use:
["highcharts" :default Highcharts]
Notice the difference?

Wilson Velez16:02:36

yes, I also tried

["highcharts/highstock" :default Highcharts]

p-himik16:02:36

What what happened? Was it the same warning?

Wilson Velez16:02:32

yes, the same, right now I’m going to add

["highcharts/modules/exporting"]

Wilson Velez16:02:06

I was confused, that exporting module is just to generate images from the chart, so it is not what I need, how ever it is still not working

p-himik16:02:34

Try ["highcharts/highstock" :as Highcharts].

Wilson Velez16:02:24

I’m doing that, the problem is the string it is expecting in :constructorType

p-himik16:02:45

Notice that I use :as instead of :default.

Wilson Velez16:02:47

if I use the default :constructorType ‘chart’ it draws a chart

p-himik16:02:55

With that, I got the chart working.

p-himik16:02:33

Do (js/console.log "Highcharts" Highcharts) somewhere at the top level. Does it print out an object or undefined?

Wilson Velez16:02:34

but if I use :constructorType ‘stockChart’ it throws the error

Wilson Velez16:02:15

(js/console.log "Highcharts" Highcharts) => undefined

p-himik16:02:37

OK. How do you import highcharts/highstock right now?

Wilson Velez16:02:07

["highcharts/highstock" :default Highcharts]
["highcharts-react-official" :default HighchartsReact]

lilactown16:02:29

console.log returns undefined, you should check your chrome console for the output

p-himik16:02:39

Replace ["highcharts/highstock" :default Highcharts] with ["highcharts/highstock" :as Highcharts]. What does that log output now?

Wilson Velez16:02:59

> Highcharts {product: “Highstock”, version: “8.0.0", deg2rad: 0.017453292519943295, doc: document, hasBidiBug: false, …}

p-himik16:02:18

And with that being the case, the chart still doesn't work?

Wilson Velez17:02:29

why did work with :default ?

p-himik17:02:07

No idea - I'm stumped myself. I'll ask in #shadow-cljs

lilactown17:02:38

hey let’s back up a sec.

lilactown17:02:01

you can render a chart depending on what constructorType you pass in, yes?

Wilson Velez17:02:09

yes, but you all need to import/require the correct highchart file (highchart, highstock, highmap, etc..)

lilactown17:02:37

and the issue is that you can’t import the additional supporting chart files?

p-himik17:02:45

@U4YGF4NGM The import does not translate well using the shadow-cljs guide, that's it. For some reason, this particular import works in JS (maybe transpiled, no idea), but not in CLJS.

p-himik17:02:04

It's just some peculiarity of the JS import machinery.

p-himik17:02:13

And how shadow-cljs tries to alleviate the pain.

lilactown17:02:14

when I look at the examples of Highcharts, there’s a lot of stuff they’re doing where they import additional files (not just "highcharts/highcarts" and "highcharts-react-official" , but many more modules) and then execute them as functions on the high charts object

lilactown17:02:04

I’ve read you two talk about importing high charts, but not about the supporting modules and applying them, so I’m just making sure we’ve already ensured we have those working

lilactown17:02:53

For instance, here’s an example of a stockChart: https://codesandbox.io/s/10yv629397 notice how it’s importing import StockTools from "highcharts/modules/stock-tools.js"; which seems relevant

p-himik17:02:44

None of the supporting modules are required. I got it working in CLJS with just the "highcharts/highcarts" and "highcharts-react-official".

lilactown17:02:50

it’s interesting in the first example @U9BUENJ1F posted that specific import doesn’t show up, but maybe it’s rolled up into one of those other modules like 'highcharts/indicators/indicators' or something

Wilson Velez17:02:12

yes, as @U2FRKM4TW say, I don’t need any other module, the example you give uses a lot of GUI objects that I don’t need

Wilson Velez17:02:45

@U2FRKM4TW thanks a bunch!

👍 4
jjttjj19:02:46

Since the namespace rename forms don't work (https://clojure.atlassian.net/browse/CLJS-2371) is there any hacky way to rename a macro from an external library?

lilactown19:02:25

(defmacro new-name [& args]
  `(old-gross-name ~@args))

😄 4
jjttjj19:02:48

I thought of that the moment you sent it, thanks 🙂

😄 4
rschmukler22:02:54

Is there any way to get the value of a variable in cljs? Looking for the equivalent of var-get in clojure

rschmukler22:02:39

Nevermind, .val works!