Fork me on GitHub
#clojurescript
<
2019-11-14
>
mruzekw02:11:41

Is there a cljs equivalent of clojure.lang.IObj?

dnolen15:11:28

@mruzekw I'm assuming you want to do metadata, yeah? IMeta and IWithMeta protocols

mruzekw15:11:40

I was mainly looking for a way to check that something is a map. Was following a CLJ example using that

dnolen15:11:16

map? is all you need

dnolen15:11:25

IObj is about metadata if I recall, so that seems like a weird example

mruzekw15:11:13

Gotcha, thinking about it that would make sense. Though there was a comment about making sure it wasn’t a scalar

gleisonsilva19:11:33

How can I evaluate/execute a javascript expression from a string?

gleisonsilva19:11:10

suppose that I have this string function (e) {return e * 2}... how can I invoke it?

Space Guy19:11:35

In the browser console (or other environments if they allow it), usually eval("function f(e) {return e * 2}") works, so in CLJS (js/eval "function f(e) {return e * 2}") should be equivalent. However:

Space Guy19:11:39

- for specifically the browser, 'eval' is blocked by content-security-policy ("CSP") on many pages, specific headers may be needed

dpsutton19:11:58

it seems function is a statement however so you don't get anything back you could use

Space Guy19:11:07

Right. If I put in directly eval("function(e) {return e * 2}") it says SyntaxError: function statement requires a name. function f(e) ... works but then you can only get to the result via a global name - this name would be hit by advanced optimisations

dpsutton19:11:14

(js/eval "(function f () { return function f(e) {return e * 2}})()")

Space Guy19:11:20

eval("(e) => {return e * 2}") returns the function object

dpsutton19:11:22

you can do an IIFE that returns a function?

dpsutton19:11:35

oh interesting

lilactown22:11:48

is there a way to use the analyzer to resolve only local bindings?

lilactown22:11:11

I thought that cljs.analyzer.api/resolve was doing that, but I'm also getting macros in there which I do not want

lilactown23:11:17

also anytime I try and print anything coming back from the analyzer, I get way too much data (like thousands of lines). is there a better way to inspect it?

Roman Liutikov23:11:57

Should be huge env map, dissoc :env

lilactown23:11:28

that helped thanks

thheller23:11:20

look at it with shadow-cljs inspect 😉

thheller23:11:07

for local bindings you can just look at (:locals &env) too?

lilactown23:11:23

I think that I can detect function args and let bindings by checking to see if :local equals :let after calling resolve

lilactown23:11:48

I can't remember why I decided to use resolve instead of (:locals &env), wrote this code a number of months ago

lilactown23:11:10

it seems to work just fine if I do that. seems simpler