Fork me on GitHub
#beginners
<
2015-07-30
>
jeffmk03:07:07

I have an API that takes a list of string 'fields'. I want these to map to functions on the backend, which are then called, and the data returned. I want the fns to be evaluated only when the API call is made and the result thrown away after it’s sent back to the client. For this would it be idiomatic to store a map of fields to quoted fn calls (i.e., (def foomap {:field-1 '(some-fn-1) .. :field-n '(some-fn-N)}, and then resolve the values as in (eval (:field-1 foomap))? If this is madness, what's a better way?

andrut03:07:23

maybe what you need is just (def foomap {:field-1 (fn[] (some-fn-1) .. :field-n (fn [] (some-fn-N)}) and then ((:field-1 foomap))?

jeffmk03:07:41

@andrut: Hm, yeah I think I like that better than using eval. Thanks!

samueldev19:07:30

can I ask clojurescript questions here?

samueldev19:07:42

nvm read channel description

samueldev19:07:44

so I've got an angular app

samueldev19:07:46

pure JS, no CLJS

samueldev19:07:54

and I want a specific "page" of the angular app

samueldev19:07:03

to be essentially an embedded CLJS app

samueldev19:07:18

is this possible? in other words can I call the initialization function of my, say, Om app

samueldev19:07:25

(where it targets an element by id on the page)

samueldev19:07:28

from plain JS?

samueldev19:07:19

ill direct this one @dnolen if he ever has a minute to read simple_smile no worries if not though

samueldev19:07:48

but let me clarify that i understand that this is a weird use-case for cljs, its just that we have a monolithic enterprise angular app, and are only partway through the development wanting to try some CLJS in client-facing production

samueldev19:07:57

and as such it isnt feasible to rebuild entirely in CLJS

teslanick19:07:08

CLJS namespaces compile into google closure namespaces. So if your main CLJS namespace is my-app.core, you can access the functions that ns provides by accessing window.my_app.core

samueldev19:07:31

so if my entire Om app is behind one initialization function

samueldev19:07:36

where im targetting an element on teh page by id and rendering

samueldev19:07:47

I just call that function at my-app.core.initialize() and boom done

teslanick19:07:17

e.g. http://nickol.us/om-identicon/ - in the developer console you can enter om_identicon.core and it will return that NS in javascript

samueldev19:07:48

very cool. thanks @teslanick

teslanick19:07:53

So you could do my_app.core.initialize() and get what you want.

teslanick19:07:14

You probably want a teardown method as well.

teslanick19:07:36

(assuming the page falls out of scope, you want to do a (js/React.unmountComponentAtNode root-node))

teslanick19:07:54

Nix that, if you're using Om, you want (om.core/detach-root root-node)