clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
william 2020-11-28T00:06:46.498500Z

I'm learning reagent, and I have a doubt: I want to slowly construct a graph during the lifetime of the application, and the graph will be displayed with cytoscape.js. What should go in a r/atom? How can I get the external javascript to change the page?

phronmophobic 2020-11-28T00:21:46.000800Z

can’t bundlers make many types of transformations as well as add asynchrony when loading modules? it seems like either of those could potentially break find-ns-obj

2020-11-28T00:40:13.001Z

I mean that's true if you want to eval code that interacts with an existing namespace.

2020-11-28T00:40:54.001200Z

But what if you wanted to have a sort of sandboxed evaluation where the evalled code can't interact with the bundled code?

phronmophobic 2020-11-28T01:02:37.003300Z

i suppose there are situations where it might work. my guess is that’s it’s the type of thing where they’re explicitly not intending to offer support for that use case since it could potentially be a rabbit hole

2020-11-28T01:05:07.003500Z

I see. Sad. 😞

2020-11-28T01:07:01.003700Z

Okay, so it sounds like a sandboxed-eval isn't really possible with clojurescript. Thanks anyway. 😞

phronmophobic 2020-11-28T01:58:48.006Z

sand boxing and target bundle isn’t the only possible combination. what’s wrong with producing javascript using the normal target and using one of the available javascript sandboxing options?

phronmophobic 2020-11-28T02:01:23.007300Z

if sand boxing is the primary goal, then i think that should be doable

2020-11-28T03:12:12.009800Z

@smith.adriane I'm mostly using the bundle target for npm packages.

2020-11-28T03:12:54.010900Z

Although I have another possible approach. Would it be possible to run two clojurescript programs on the same page?

william 2020-11-28T03:12:59.011200Z

I have two questions on reagent; the context is that my page displays a graph managed with cytoscape.js 1. I have the entire graph in my r/atom. However, when the graph is updated, I don't want to redraw all the graph (because to keep positions of the already displayed nodes I want to pass only those to cytoscape). Instead, I want to calculate the diff between what was previously in the atom and my new version, and use that diff to issue the proper command to cytoscape. I cannot figure where to put this logic in the reagent framework, though

2020-11-28T03:13:38.012100Z

If so, then one could be build with bundle and the other the default target and then communicate through websockets or something like that.

william 2020-11-28T03:14:14.013Z

2. I want to intercept when a node in my graph is clicked, and put that information in my global atom. But that part of the dom is built by cytoscape. How can I intercept the click events on the nodes?

p-himik 2020-11-28T03:18:06.013100Z

All these questions should probably be asked in #reagent instead.

william 2020-11-28T03:18:45.013300Z

Thanks, will ask there!

phronmophobic 2020-11-28T03:30:27.015600Z

i’m away from keyboard, but I assume there’s some set up that allows for using npm packages and having sandboxed clojure script eval in the browser.

phronmophobic 2020-11-28T03:32:53.017700Z

have you tried shadow cljs? i’m not super familiar with its internals, but it’s integration with npm has been great in my experience and it looks like it support several targets, http://shadow-cljs.org

phronmophobic 2020-11-28T03:33:53.019100Z

for sand boxing, i would use one of the tools that focuses on sandboxing js in the browser and using that for your js eval function

phronmophobic 2020-11-28T03:39:45.020400Z

unless the sandboxing isn’t security critical, then I would just eval code in its own namespace

2020-11-28T04:52:01.020900Z

@smith.adriane The sandboxing isn't security focused.

2020-11-28T04:52:08.021100Z

Its more just isolation.

2020-11-28T04:52:23.021300Z

And evaling it in its own namespace would 100% be enough, if I could. 😞

2020-11-28T04:52:56.021500Z

But since eval seems to directly call find-ns-obj it doesn't work with the bundle target. 😞

2020-11-28T04:53:34.021700Z

I have looked at shadow cljs, but IIRC its set to a fixed version of clojurescript

2020-11-28T04:54:11.021900Z

And so I'd be a bit dubious of it working since eval in older versions of clojurescript seemed to work just fine.

2020-11-28T04:54:34.022100Z

(Mostly because the *target* variable was pre-set to default, rather than bundle.

2020-11-28T04:54:49.022300Z

I'm not sure how that changed though.

2020-11-28T04:54:58.022500Z

Anyway, thanks for your help so far.

phronmophobic 2020-11-28T06:46:13.026500Z

another option I would consider to ease the configuration issues is to have two separate js output builds. have one js output with target bundle that runs your application and does most of the work and have a second js build target that exports just the eval functionality that you need with the default target.

william 2020-11-28T17:03:39.028300Z

Why can I use this in a template:

[:p #{{:id 1 :data "foo"}}]
but not this:
[:p {:foo #{{:id 1 :data "foo"}}}]
It has something to do with the way data is represented in the js side, but I'd like to understand better

william 2020-11-28T17:07:36.029Z

sometimes an object is printed as #object[Core [object Object]] even if I use str

william 2020-11-28T17:46:33.029500Z

Nevermind my bad, I had a bad type assignment (I need instrumentation 😂)

jmckitrick 2020-11-28T21:10:59.031Z

I’m using .-rep to view a LocalDate in transit, but I need to format the result differently. What’s a good way to do that?

jmckitrick 2020-11-28T21:11:10.031300Z

First time working with transit, BTW.