Fork me on GitHub
#clojurescript
<
2018-08-26
>
tony.kay02:08:07

Anyone remember how to get a macro to emit a syntax quote? E.g. I need:

(macroexpand '(m f))
to output
(g `f)
(I’ve got a macro that needs to emit a call to a macro that wants a FQ symbol)

tony.kay02:08:42

it could also output

(g 'ns-of-f/f)

tony.kay02:08:15

Figured it out: 1. resolve to a var 2. Get the metadata on the var which has ns and name 3. Recombine those into a symbol If there’s a better way, love to hear it

tony.kay02:08:13

argh…macros and cljs…ok, that works for clj, but not cljs

tony.kay02:08:04

I used &env for cljs, and the other way for clj…that seemed to work

(defmacro main-macro [& forms]
  (let [sym   (first forms)
        nspc  (or
                (some-> &env :ns :meta :source)
                (some-> (resolve sym) meta :ns str))
        fqsym (symbol nspc (name sym))]
    `(other-macro (quote ~fqsym))))

mfikes03:08:58

@tony.kay the doc macro ends up forming the qualified name of the symbol passed to it. It may be similar to your solution. It calls (ana-api/resolve &env name)

tony.kay03:08:28

ah, is that considered public API then?

mfikes03:08:26

Yes. cljs.analyzer.api is public / stable API

jjttjj03:08:32

I stumbled upon the derivatives cljs library (https://github.com/martinklepsch/derivatives), the readme of which says "Let's assume you're hooked about the idea of storing all your application state in a single atom (db). (Why this is a great idea is covered elsewhere.)" Does anyone know some particular places this is discussed? Why is one big atom better than many small atoms?

john03:08:47

The experience of trying to maintain a large app with lots of small atoms 🙂

john03:08:30

You end up with intractable situations trying to reconcile state between different, uncoordinated locations

john03:08:27

and for being able to do cool things like time travel for a whole app, it helps to have every piece of state in the app under one coordination mechanism

john03:08:36

and any given state of an app at any given time can be reproduced by a dump of it's one state graph

jjttjj03:08:16

gotcha, thanks!

john03:08:18

yup no prob!

Ramzi03:08:38

What do you guys think of this as a general solution to asset management software

john18:08:10

I'd definitely use Datomic for a green field asset management project

john18:08:22

Perfect tool for a problem like that

john18:08:27

If your not talking about fast, ephemeral supply chain assets or something. But software/hardware catalogs whose items change no more often then every day or so, where you know you'll never run out of memory, you might as well use Datomic. Datomic Ions might be a good fit for a lightweight web service around it https://docs.datomic.com/cloud/ions/ions.html

john18:08:27

And there's lots of tutorials and videos on how to get connected to a Datomic DB from Clojure

john18:08:24

And you'll get to continue dealing with more clojurey data structures, rather than having to deal with SQL tables and whatnot

Ramzi19:08:33

I work on a government project, so we would need to push to the government AWS or government Git. But also, right now it's just a single server and a database server with postgres. So I guess I'm asking if we can keep the solution local, rather than cloud-based?

john19:08:12

mmm, ions is mostly a cloud thing. But it probably works on govt cloud. There's on prem Datomic too. But if you've gotta use postgres, it is what it is 😕

john19:08:40

Looks like there's some blog posts out there on Clojure and Postgres though

Ramzi03:08:02

That for every page, that's a table in a Postgres database. And for every input, that's a column.

Ramzi03:08:27

Some inputs are multiselect, but that just means saving a list in a cell in the db. No big deal.

Ramzi03:08:50

Then you have a straightforward mapping from pages to tables, and inputs to columns.

jjttjj03:08:08

what's the advantage of that over just a normalized schema

Ramzi03:08:49

i was thinking that to add new elements to a page

Ramzi03:08:58

that's as easy for the developer as adding one string to a list

Ramzi03:08:12

And that it would call a clojurescript routine to add the column to the db if it doesnt exist

Ramzi03:08:15

Then you dont even have a schema file. You just have your db defined in your cljs app

Bravi12:08:57

hi everyone. I’m looking for a good time library for clojurescript. I’m reading cljs-time documentation at the moment and I can’t find anything that would output something like 3 days ago or in 6 hours and etc.

Bravi12:08:01

what’s the alternative?

Bravi13:08:37

ok if not that, is there a way to parse a timestamp in cljs-time?

Bravi13:08:41

this is painful..

Bravi13:08:40

@valtteri that’s exactly what I ended up doing 😄

valtteri13:08:42

It’s also available in cljsjs

Bravi13:08:43

thank you

Bravi14:08:02

I’m using shadow-cljs and I added it to my package.json

Bravi14:08:17

but I had to create a custom function anyway to append ago and in words

Bravi14:08:27

like 2 days ago or in 2 days

valtteri14:08:49

Haha, actually I just lied to you. 😉 In that particular case I needed localization and wrote my own function. It wasn’t that bad. https://github.com/lipas-liikuntapaikat/lipas/blob/master/webapp/src/cljs/lipas/ui/utils.cljs#L82-L101

Bravi14:08:49

I was basically struggling with converting dates

Bravi14:08:08

I’m getting dates from backend which I’ve written in PHP

Bravi14:08:39

and I was returning a timestamp. so I was basically juggling PHP, js and clojure dates together

valtteri14:08:28

I feel your pain. Especially when you need to consider timezones.

valtteri14:08:00

I’m storing and transmitting timestamps in ISO format (“2018-08-26T14:06:25.443Z”), always in UTC.

martin_rdz14:08:24

Hi, for a small reagent SPA i need a component to display an alert/popover. Currently i am considering antizer and re-com but i am not sure which one to prefer. Does anyone have experience with them and can provide me some guidance?

pppaul19:08:31

hey, is there something like elms style elements for clojure?

pppaul22:08:23

I thought that was just for css

pppaul23:08:18

style elements has declarations that are not just html or css.