Fork me on GitHub
#clojurescript
<
2018-08-08
>
euccastro00:08:48

having your code in .cljc files and rendering it server-side (then hooking up the React logic in the client side) is super easy in rum. last time I checked that was tricky in reagent, but that may have changed

takamura00:08:17

hahaha thanks!

takamura00:08:47

When you say "rendering it server-side" what do you mean? To render a js file specific for a user? Or to render a html specific for a user (like Rails, for instance)?

takamura00:08:52

Usually, you generate a bundle with your cljs files and this files is served for all your users, right? And this client code performs requests fetching the data it needs :thinking_face:

Chris O’Donnell00:08:26

I think they were referring to server side rendering (as described in https://reactjs.org/docs/react-dom-server.html)

☝️ 4
takamura00:08:54

Ahh thanks hahaha

lilactown00:08:09

anyone know of a solid & fast shallow implementation of converting a JS data structure to CLJS?

richiardiandrea02:08:52

@lilactown I copied js->clj - I know....

richiardiandrea02:08:49

I think the go to though for big objects is to use transit. It would be handy to have an option for shallow transform so that we don't need to add a dependency

pesterhazy07:08:33

@lilactown something like this?

(defn js-obj->hash-map
  [o]
  (let [t (transient {})]
    (-> o
        (goog.object/forEach (fn [v k] (conj! t [k v]))))
    (persistent! t)))

(defn js-array->vec [a]
  (vec a))

martinklepsch07:08:30

I noticed this exception in a cljdoc build and it seems that the analyzer’s ns validation somehow chokes on this ns form: https://github.com/dvingo/cljs-styled-components/blob/59d865294e4b99490a318469fa56722c5ae1a726/src/main/cljs_styled_components/reagent.cljc#L1-L11 Is that expected? (Is the ns form not correct?)

thheller07:08:41

@pesterhazy that is "illegal". transients should still be used like persistent data, meaning you should not call conj! multiple times on the same thing, rather always use the return value.

thheller07:08:58

@martinklepsch looks like someone published something I advised against. it is supported in shadow-cljs but not CLJS. See https://dev.clojure.org/jira/browse/CLJS-2376

martinklepsch07:08:39

So that :default thing is shadow-cljs specific and (usually) shouldn’t be published in jars?

pesterhazy08:08:50

@thheller fine

(defn js-obj->hash-map [o]
  (let [a #js [(transient {})]]
    (-> o
        (goog.object/forEach (fn [v k] (aset a 0 (conj! (aget a 0) [k v])))))
    (persistent! (aget a 0))))

vemv11:08:44

What's the actual implementation of >? The source doesn't make sense per se and obviously is using some trick

(defn ^boolean >
 ...
  ([x y] (cljs.core/> x y)))

thheller11:08:44

@vemv it is implemented as a macro in cljs.core but you can totally define your own >

vemv11:08:53

@thheller could you point out to the macro location? I'm interested in how it works as I'm debugging an issue

dominicm11:08:32

probably cljs/core.clj

vemv11:08:44

Ty both!

roti14:08:35

I am currently looking at mori vs immutable.js, and thought about building an OO wrapper around mori, to make the API look more like Immutable.JS, and ES6 for that matter. And I stumbled upon the major difference (in my oppinion) between the APIs that the two expose, namely the (lazy) Sequences. So, for instance map on a HashMap will return another HashMap in immutable.js, while it returns a (lazy) sequence in mori (and clojurescript, of course). It's quite an interesting design decision, and I wonder whether that's the reason why mori is faster. Anyway this means, that in order to do the same in mori/clojurescript I need to build another hashmap from the resulting sequence, which will require two "iterations". For this reason I gave up on the OO wrapper around mori. I will do some performance tests at some point, to verify my suspicion, but I'd like to hear your thoughts on this. One question that pops into my mind is how many times will you actually convert the sequence from a map over hashmap back into a hashmap vs just process it further.

abdullahibra20:08:13

how can i move to the beginning of the page in clojurescript ?

pauld20:08:13

That an editor issue.

pauld20:08:17

Which one?

pauld20:08:40

or you mean in the dom?

abdullahibra20:08:38

yeah in the dom

abdullahibra20:08:59

clojurescript function to goto beginning of the page, say :on-click #(here)

john20:08:44

something involving scroll, .-top and 0

john20:08:09

Can't remember the exact details. But find the global scroll on the window and run js-keys on it to see what props it has. It might have a top or a y and then just set it to 0.

abdullahibra20:08:42

(.scrollTo js/window 0) ?

abdullahibra20:08:27

it didn't work

justinlee20:08:54

scrollto takes 2 arguments: x an y

justinlee20:08:59

you only gave it the x

john20:08:17

Yeah that's right. Worked here

john20:08:55

(.scrollTo js/window 0 0)

abdullahibra20:08:50

thanks, works 🙂

👍 4
abdullahibra22:08:49

why when i use secretary routes and refresh page i get "404 page not found" ?

abdullahibra22:08:03

or the state of reagent atom gone when i refresh the page?

abdullahibra22:08:08

and how can i fix this issue?

pauld22:08:25

did you use defonce for the atom?

pauld22:08:59

I'm not a clojurescript expert, but I think the namespace gets reevaluated on reload. So def's are re-def'd to their original states.

abdullahibra23:08:44

so what is the normal ways to handle this situation ?

mfikes23:08:54

defonce is normal

abdullahibra23:08:19

how can i handle with refresh page?

abdullahibra23:08:28

maybe save to session ?

lilactown23:08:39

@abdullahibra what are you trying to save between page refresh

lilactown23:08:11

when you refresh the page, all JavaScript code is re-run. any state from before is gone.

abdullahibra23:08:53

i have current page variable which is reagent/atom i save on it the current reagent function

abdullahibra23:08:03

when i refresh it it gone to the default

abdullahibra23:08:43

how can handle keeping state even after refresh ?

abdullahibra23:08:58

add vars to session ?

lilactown23:08:35

so you want the user to be able to come to your application, change pages, and if they refresh it will go to the page they left off?

lilactown23:08:01

then yes, saving something to the user’s session storage is probably the right thing to do

justinlee23:08:51

@abdullahibra the 404 is probably happening because you don’t have your server setup to redirect all client-side routes to serve up your main bundle. if you serve the app out of /app and then you navigate to /app/user/info and then hit refresh, the browser will go hit that location on the server. you’ve got to get your server to handle that. shadow-cljs’s dev sever has a “push state” feature to handle this during development. i don’t know how people deal with this using figwheel or whatnot