I'm attempting to do some timed animation in clojurescript/reagent and I'm trying to use core.async to achieve series of timed steps in order. I'm using a third party js react library, so, to call its functions I'm using the form (fn [] ^js (.function (.something @ref)). However putting this anonymous function inside the go block as follows doesn't work -
(go
(js/console.log "going")
(<! (timeout 3000))
(fn [] ^js (.function (.somedata @lib))
(js/console.log "landed")
)
This returns "going" and "landed" timed correctly and works when putting another console.log function in its place. However if you wrap this console.log in an Fn it no longer gets called. It is being called in the :on-click handler of a component. What have I missed?
That
^jsthere is unnecessary.When you wrap something in
(fn [] ...), that something is not called unless thatfnis called. I.e.((fn [] ...)). But then, you end up creating a function and calling it immediately, which is completely unnecessary.So, assuming I understand you correctly, you can simply replace that
(fn [] ^js ...)with(-> @lib .somedata .function).On a side note,
somedatasounds like it's just a field that has some data and not a function that needs to be called. If that's the case, use.-somedatainstead of.somedata.