Fork me on GitHub
#clojurescript
<
2015-06-21
>
theophilusx00:06:29

@phil The figwheel template is pretty good for a bare bones starting point. I've also used the reagent template.

mateusz-fiolka06:06:10

@phil: Also there's Luminus template for Reagent.

mateusz-fiolka06:06:52

I'm wondering - I'm using re-frame and would like to achieve the following behaviour: After some event happens - I'm changing app state in a event handler function. Because of that - one of the components get's selected (this is a virtual selection, no related to browser focus). It might happen that this element will be out of the page fragment that the user is looking at. So I'd like to scroll the page to make this element visible. But how to do that using re-frame - I have no idea where to start. Maybe someone of you has?

mateusz-fiolka06:06:21

One way to do it would be to record the selection change in app state and when rendering in componentdidupdate doing the scroll and dispatching component selection handled event to remove the temporary state in app state. Though it feels rather inelegant.

ambrosebs07:06:30

how do I evaluate clojure code from clojurescript?

ambrosebs07:06:38

thinking socket

ambrosebs07:06:43

anyone tried it?

zoldar08:06:50

@mateusz-fiolka why inelegant? Your solution sounds good.

mateusz-fiolka08:06:49

@zoldar: Because it's sounds like too many steps for such seemingly not complicated feature.

jonas08:06:51

@ambrosebs how do you mean "evaluate clojure code from clojurescript"? I guess it'll depend on the js environment you're running in?

ambrosebs08:06:43

I don't know what JS offers tbh. I was thinking start a Clojure nREPL server, then pipe evaluations to it via a socket from CLJS.

jonas08:06:07

You can probably talk to nREPL easily from node. There's probably a more direct route if you're on nashorn or rhino. Perhaps websockets for browser envs

ambrosebs08:06:52

jonas: very cool

jonas08:06:10

@ambrosebs: if you’re on Nashorn you can probably access the clojure compiler directly: https://docs.oracle.com/javase/8/docs/technotes/guides/scripting/nashorn/api.html

ambrosebs08:06:51

jonas: right, this was more a thought exercise in what combinations of host/checking languages is possible with core.typed

ambrosebs08:06:57

if I were to use cljc files

zoldar09:06:58

@mateusz-fiolka you could create an async channel in app state and setup a loop in will-mount of component responsible for scrolling. That way you just push scroll command to that queue

micha12:06:46

is anyone here transpiling to clojurescript from some other language? how would you get source map support for that?

mateusz-fiolka13:06:30

@zoldar: Another problem is that domnode is not accessible from react as far as I understood.

mateusz-fiolka13:06:37

@zoldar: To get current widget location I'd need to have dom node, not only render function.

zoldar13:06:50

@mateusz-fiolka: DOM is accessible - see reagent.core/dom-node

mateusz-fiolka13:06:26

@zoldar: Thanks, I'll check it.

zoldar13:06:39

@mateusz-fiolka: first argument to component lifecycle methods (like will-mount, did-mount, did-component-update etc.) is the underyling React component and it's possible to access underlying DOM node calling .getDOMNode method on it - reagent.core/dom-node is a simple convenience for that.

mateusz-fiolka13:06:22

@zoldar: Awesome, I'm already using 3-rd form component.

mdallastella14:06:18

quick question: is it better to start with reactjs and then switch to om/reagent or to start directly with om/reagent? I mean for studying purposes.

colin.yates15:06:55

@mdallastella: The general consensus is to at least read through the reactjs docs. Personally I think this is right. The lifecycle of a react component leaks (not in a negative way) through to both libraries for example.

colin.yates15:06:49

@mdallastella: Also, a lot of people start with om and then move onto reagent. I did, and then moved onto re-frame. Any of those three though will rock your world 😉

dnolen15:06:02

@micha ClojureScript has generic source map facilities at both compile & runtime

dnolen15:06:07

it also includes helpers to merge source maps together. The intention was for it to be generic, but it may be that it only works for merging two source maps. Happy to see it people enhance it if that's the case.

micha15:06:54

dnolen: awesome!

micha15:06:56

is merging transitive? or is that what you mean by "it may be that it only works for merging two"

dnolen15:06:49

@micha: yes, never needed more than 2 so no tests around transitivity

micha15:06:11

very encouraging thanks

micha15:06:20

i have haml --> hoplon --> cljs

micha15:06:30

it would be mind blowing to get source maps working with that

micha16:06:13

dnolen: would i add source map metadata to the bottom of the generated cljs source file, and the browser would follow that transitively?

micha16:06:34

like cljs generates the .cljs --> .js source mapping in the .js file

micha16:06:00

and i generate the .haml --> .cljs source mapping and add it to the bottom of the .cljs file?

dnolen16:06:37

@micha: no you will need to do all the source mapping merging yourself manually.

dnolen16:06:43

source maps in browsers are not transitive

clojuregeek19:06:48

I am using om and want to load my data using cljs-ajax from an api … I have set a handler function to get the result of the GET call .. how do I use it to set the app state?

zoldar19:06:51

@clojuregeek: if that's a one-time load, you can put that GET call in component's will-mount method

zoldar19:06:23

@clojuregeek: from there, just call om/transact! (or other function altering app state or component's local state) to populate state with data from the ajax call

clojuregeek20:06:56

ok thanks.. i’ll try that..

delaguardo20:06:19

Im use core.async for that, put channel consumer to will-mount method and share channel with all component children. Call GET method and put result into channel in callback

Petrus Theron20:06:17

Fighting with cljs trying to get a browser REPL working 😐. Here's what I tried:

(use 'figwheel-sidecar.repl-api)
=> nil
(cljs-repl)
NullPointerException   clojure.core/deref-future (core.clj:2184)

clojuregeek20:06:31

@zoldar: I have this … http://screencast.com/t/vtsONT4RHj then in console

XHR finished loading: GET "".goog.net.XhrIo.send @ xhrio.js:561goog.net.XhrIo.ajax$core$AjaxImpl$_js_ajax_request$arity$7 @ core.cljs:61ajax$core$_js_ajax_request @ core.cljs:21ajax$core$ajax_request @ core.cljs:376ajax$core$easy_ajax_request @ core.cljs:441ajax.core.GET.cljs$core$IFn$_invoke$arity$variadic @ core.cljs:447ajax$core$GET @ core.cljs:447recipes_om$core$get_data @ core.cljs:25(anonymous function) @ VM7088:1(anonymous function) @ VM7088:9(anonymous function) @ VM7088:14figwheel$client$eval_javascript_STAR__STAR_ @ client.cljs:116figwheel.client.repl_plugin @ client.cljs:142(anonymous function) @ client.cljs:305cljs.core.Atom.cljs$core$IWatchable$_notify_watches$arity$3 @ core.cljs:3478cljs$core$_notify_watches @ core.cljs:397cljs$core$reset_BANG_ @ core.cljs:3509cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$3 @ core.cljs:3493cljs$core$swap_BANG_ @ core.cljs:3491(anonymous function) @ socket.cljs:62
core.cljs:901 Uncaught Error: Assert failed: (transactable? cursor)

Petrus Theron20:06:28

When running lein figwheel, is it still necessary to run a separate repl to enable a browser-repl?

zoldar21:06:45

@clojuregeek: where is app coming from? if handler is defined as a top form, it's undefined

zoldar21:06:47

@clojuregeek: if you're calling get-data in component's will-mount, pass app-state to it, then pass it to handler

zoldar21:06:59

@clojuregeek: alternatively, you could simply swap! the app-state atom directly