clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
Oliver Smit 2021-06-29T04:42:20.053500Z

Check out np by Sindre https://github.com/sindresorhus/np

thheller 2021-06-29T06:46:21.053900Z

I do things manually. takes 5sec max. setting something up probably takes hours 😉

danielneal 2021-06-29T10:15:13.054600Z

Anyone know how to replicate the following imports using figwheel-main?

import Highcharts from 'highcharts';
import Heatmap from 'highcharts/modules/heatmap.js';
Heatmap(Highcharts);

danielneal 2021-06-29T10:15:51.055300Z

I tried

(ns highcharts.demo
  (:require 
    ["highcharts" :as Highcharts]
    ["highcharts/modules/heatmap.js" :as Heatmap]))
but no dice

danielneal 2021-06-29T10:23:48.055900Z

I’m getting Highcharts ok, just not the nested heatmap module

danielneal 2021-06-29T10:24:12.056400Z

I’ve tried with and without the .js suffix

2021-06-29T10:34:31.060500Z

I guess you can't nav to the heatmap from Highcharts - or don't want to without bringing in all the modules? requiring a single module/file from an npm lib is not possible in cljs afaik. maybe shadow can do it? I don't know highcharts, but googling cljs highcharts there seems to be quite a few results, so maybe something there?

danielneal 2021-06-29T10:36:34.060800Z

yeah, can’t navigate through the Highcharts object sadly

danielneal 2021-06-29T10:41:04.061400Z

> requiring a single module/file from an npm lib is not possible in cljs afaik do you know if there’s a reference somewhere for the cljs string requires? I’m struggling to find the right google search terms

2021-06-29T10:50:43.062Z

there's this: https://clojurescript.org/news/2021-04-06-release

2021-06-29T10:52:35.063500Z

... but actually the feature that's described as new is not what you're after. I think it's just sugar for navigating js object

danielneal 2021-06-29T10:52:52.063800Z

yeah but good shout, maybe if I look back over the release notes

danielneal 2021-06-29T10:55:11.064300Z

https://github.com/clojure/clojurescript/blob/a4673b880756531ac5690f7b4721ad76c0810327/src/test/cljs_build/npm_deps_test/string_requires.cljs#L3 seems to be able to pick a single module/file out of an npm lib?

danielneal 2021-06-29T10:55:23.064700Z

I wonder if I’m doing something dumb

danielneal 2021-06-29T11:06:41.065300Z

oh holup it looks like its working now

danielneal 2021-06-29T11:07:11.065800Z

did a restart and a refresh etc and used the “highcharts/modules/heatmap” incantation

👍 1
practicalli-john 2021-06-29T12:01:42.073500Z

I am creating a very simple landing page as a ClojureScript Single Page App. I have identified 4 different views, home, reference, tutorials, support, which are fairly separate from each other. There may be a few functions shared between these views, but the overall layout will be different. What is the simplest approach to displaying each view based on a user action, eg clicking on the tutorials button on the home view changes the view to the tutorials view. • do i just hide and unhide the • do i need to include some kind of router like a compojure equivallent (seems a little excessive) I am using reagent, http://bulma.io for CSS and figwheel-main as I am most familiar with these and would prefer to avoid JavaScript and npm (not familiar and its supposed to be a simple site). Thank you for sharing any ideas or examples.

henrik42 2021-06-30T07:40:38.100900Z

Just to clarify - what do you refer to by 'hide'/'unhide'? Is this better/worse compared to using a cond? Like in https://github.com/henrik42/solo/blob/83064f711b3cec897fd5f59fec50dd418b309f88/src/cljs/solo/spa.cljs#L276

p-himik 2021-06-29T12:04:52.073800Z

Simplest - indeed the "hide and unhide" approach. And tad less simple but more scalable and useful in general - the router approach. If your app is limited to those four views and it's OK that people can't share links to particular views, then the first approach is reasonable.

Adam Kalisz 2021-06-29T14:19:08.076100Z

I am strugling with http://goog.net.Cookies.prototype.set: https://github.com/google/closure-library/blob/master/closure/goog/net/cookies.js#L167-L229 I have:

(.set goog.net.Cookies.prototype "test" "test" #js{:maxAge   1000
                                                   :path     "/"
                                                   :domain   "localhost"
                                                   :sameSite (.-LAX goog.net.Cookies.SameSite)
                                                   :secure   true})
but this keeps telling me "this.document_ is undefined". I don't know, how to provide the context so that goog.net.Cookies understands where to set the cookies. Any clues?

p-himik 2021-06-29T14:22:49.076300Z

Don't call prototype functions. Instead, create a concrete object and call a regular method on it. In this case, use <http://goog.net|goog.net>.Cookies.getInstance to get the actual Cookies instance and call the set method on it instead of its prototype.

Adam Kalisz 2021-06-29T14:38:54.076500Z

(.set (.getInstance js/goog.net.Cookies) "test" "test" #js{:maxAge 1000 :path "/" :domain "localhost" :sameSite (.-LAX http://goog.net.Cookies.SameSite) :secure true})

Adam Kalisz 2021-06-29T14:39:23.076700Z

Thank you for the explanation. It works!

p-himik 2021-06-29T14:56:13.076900Z

Also, don't use js/goog .... Instead, require it properly. E.g. (:require [goog.net.Cookies :as Cookies]) with a consequent (Cookies/getInstance).

👍 1
Adam Kalisz 2021-06-29T16:11:45.077300Z

This is all related to my problem in the shadow-cljs channel: https://github.com/reagent-project/reagent-utils/issues/19 basically, it works in dev and doesn't work in release. Something is totally off here. I feel like I have learned a great deal in the last day, but this really is a problem I must fix - we need to set the SameSite option. Thank you for your mentoring

Stephen Kershaw 2021-06-29T20:01:26.082500Z

I'm trying to make https://clojars.org/tick/versions/0.4.32 work with https://www.npmjs.com/package/react-datepicker but so far I'm unable to convert from tick/joda's LocalDate to a Date that react-datepicker can recognize. Is there a recommended datepicker to use with tick, or can anyone point me to an example of how to convert to javascript native date-fns? @henryw374

nate sire 2021-06-29T21:26:37.082800Z

I like to keep all my dates in UTC with the location data because of daylight savings time.

👍 1
nate sire 2021-06-29T21:28:19.083100Z

because time varies based on location even when in the same longitude... and UTC is coordinated across all locations and time zones

Stephen Kershaw 2021-06-29T21:29:54.083300Z

what libraries do you use for managing temporal data and for date-picking UI ?

nate sire 2021-06-29T21:31:11.083500Z

Datomic is for temporal snapshots of data based on time

nate sire 2021-06-29T21:31:26.083700Z

I used some jquery date picker libs... but...

nate sire 2021-06-29T21:31:53.083900Z

if you have time... I'd write my own at some point... to reduce your dependencies

nate sire 2021-06-29T21:33:00.084100Z

why are you not able to convert between date formats?

nate sire 2021-06-29T21:33:36.084300Z

I actually wrote a machine learning algo to recognize the hundreds of ways to write dates/times. Fun project.

nate sire 2021-06-29T21:36:34.084500Z

Formatting If you want to create custom formatters from patterns, such as "dd MMM yyyy", add this require

nate sire 2021-06-29T21:37:04.084700Z

Looks like tick has a way to custom format but it is not very well documented... this is only in alpha?

nate sire 2021-06-29T21:37:58.084900Z

hmmm... I used regex to recognize and convert dates to a standard utc format

nate sire 2021-06-29T21:38:50.085100Z

I always use UTC since a manager told the team to switch over our servers at midnight on Tuesday...

Stephen Kershaw 2021-06-29T21:39:11.085400Z

haha

Stephen Kershaw 2021-06-29T21:40:07.085600Z

I'll try to add clarity by pasting in the errors I'm getting. One sec.

nate sire 2021-06-29T21:42:00.085900Z

I found an example...

Stephen Kershaw 2021-06-29T21:42:01.086100Z

So I've got a LocalDate object, and I get this error when passing it in to react-datepicker: No protocol method IConversion.inst defined for type object: 2020-01-23

nate sire 2021-06-29T21:42:35.086300Z

ahhhj

nate sire 2021-06-29T21:42:42.086500Z

it is missing some methods

nate sire 2021-06-29T21:43:22.086700Z

the JS object is expected to have some methods available

nate sire 2021-06-29T21:44:32.086900Z

you need to change how you are passing it in

Stephen Kershaw 2021-06-29T21:44:33.087100Z

so I need to find the right set of conversion(s) if I want to use this datepicker UI that relies on native javascript date objects

nate sire 2021-06-29T21:45:15.087300Z

you need to search the correct way to instantiate an object for that react date picker

nate sire 2021-06-29T21:45:33.087500Z

so all the methods are there

2021-06-29T21:46:21.087700Z

so you want to convert to/from LocalDate to js/Date, in UTC I think

👍 1
nate sire 2021-06-29T21:46:43.087900Z

where is your code that instantiates the react js object?

nate sire 2021-06-29T21:47:31.088100Z

ReactDate.create( ) ?

nate sire 2021-06-29T21:48:03.088300Z

the LocalDate object is not compatible with the React object... those are two different classes

nate sire 2021-06-29T21:48:23.088500Z

you need to use dependency injection

Stephen Kershaw 2021-06-29T21:48:28.088700Z

#(tick/date %) where the argument is a string

Stephen Kershaw 2021-06-29T21:48:42.088900Z

tick makes use of js-joda ....

nate sire 2021-06-29T21:49:17.089100Z

I know what you need...

nate sire 2021-06-29T21:49:49.089300Z

you need to focus on creating the React object... then read the tick string into it...

nate sire 2021-06-29T21:50:08.089600Z

not pass a foreign tick object to a foreign react object

2021-06-29T21:50:18.089800Z

(-&gt; (t/date)
    (t/midnight)
    (t/in (t/zone "UTC"))
    (t/inst))

👍 1
nate sire 2021-06-29T21:51:37.090100Z

inst is not defined on the React object?

nate sire 2021-06-29T21:51:41.090300Z

"inst"

2021-06-29T21:52:43.090500Z

t is alias for tick.alpa.api ns

nate sire 2021-06-29T21:53:32.090700Z

what does "inst" do?

Stephen Kershaw 2021-06-29T21:53:42.090900Z

Trying to make that code work. I'm currently seeing this error: No protocol method IExtraction.date defined for type null

2021-06-29T21:53:42.091100Z

as in (:require [tick.alpha.api :as t])

👍 1
2021-06-29T21:54:01.091400Z

t/inst converts an object to a native Date object

nate sire 2021-06-29T21:54:19.091600Z

ahhh... for native fns

2021-06-29T21:54:39.091800Z

well, that is what the react date picker api expects I guess

👍 2
nate sire 2021-06-29T21:54:47.092Z

yes

2021-06-29T21:56:21.092400Z

so, if user selects a date, and that api gives you a native Date obj, convert it to a LocalDate with :

(-&gt; js-date-obj
    t/instant
    (cljc.java-time.zoned-date-time/of-instant (t/zone "UTC"))
    t/date)

2021-06-29T21:59:14.092600Z

it does seem a bit complicated... I'm thinking this specific thing should be documented as it seems like a normal thing to want to do. longer term.. this will all become easier with the new js date objects . fyi see https://github.com/henryw374/tempo

❤️ 1
Stephen Kershaw 2021-06-29T22:00:58.092900Z

So I've got a date from a postgres db that I've coerced to LocalDate via #(t/date %) In the DatePicker I'm formatting the value as you said, I think: `(-> start-date (tick/midnight) (tick/in (tick/zone "UTC")) (tick/inst))`

Stephen Kershaw 2021-06-29T22:01:42.093100Z

Does the No protocol method IExtraction.date defined for type null error make sense to you?

nate sire 2021-06-29T22:02:13.093400Z

I found some github comments about that IExtract error

nate sire 2021-06-29T22:02:25.093600Z

looks like a parsing format error

2021-06-29T22:02:41.093800Z

well that means the thing you're passing in is null I think

nate sire 2021-06-29T22:03:22.094Z

yea... what is the output of your clojure tick code?

nate sire 2021-06-29T22:04:10.094200Z

(-&gt; (t/date)
    (t/midnight)
    (t/in (t/zone "UTC"))
    (t/inst))

nate sire 2021-06-29T22:04:17.094400Z

what does this output?

2021-06-29T22:04:32.094600Z

a native Date object

nate sire 2021-06-29T22:05:00.094800Z

is it actually outputting it... though... because of the null?

nate sire 2021-06-29T22:05:08.095Z

paste that into your REPL

nate sire 2021-06-29T22:05:14.095200Z

see what it returns

2021-06-29T22:05:15.095400Z

(t/date) creates a date, but you put your date from postgres instead of that

nate sire 2021-06-29T22:05:31.095600Z

ahhhh

Stephen Kershaw 2021-06-29T22:05:43.095800Z

aha, sorry, I had some old code in a let block that was throwing that error

2021-06-29T22:05:51.096Z

🙂

Stephen Kershaw 2021-06-29T22:05:59.096200Z

so it does appear to be working! Thank you both so much

nate sire 2021-06-29T22:06:20.096400Z

yea... make sure your % is working

nate sire 2021-06-29T22:06:27.096600Z

the pg field

nate sire 2021-06-29T22:06:41.096800Z

@henryw374 good job

2021-06-29T22:06:50.097Z

hehe cheers