Fork me on GitHub
#clojurescript
<
2018-12-13
>
dnolen00:12:34

@dante.the.monkey :npm-deps + :target :node will probably just work for you since that skips Closure

Dante T. M.03:12:28

I think I misunderstood some documents I was reading. :foreign-libs was what I was after. Found a nice tutorial at lambdaisland that helped make sense of it

Dante T. M.03:12:12

I think the library I'd be using is EC6 as well, so I should be able to pull it in using the :model-type key

curlyfry09:12:10

I'm still wrestling a bit with the best way of using JS libraries. Is anyone happily using :npm-deps (in a browser based project) I've heard there are a bunch of libraries that don't work. Why is this and is there any workarounds?

pradyumna11:12:54

@curlyfry i have not tried :npm-deps. rather using webpack (https://clojurescript.org/guides/webpack) instead, for my browser project. Except for the initial hurdle with setting up yarn and understanding webpack config, it has been quite good. i have included multiple npm libs like react, @material-ui, d3 and they seem to work fine.

curlyfry11:12:39

@pradyumna Cool, that method seems to work quite well. It's unfortunate that it brings the whole webpack machinery with it, though. I think one of the main issues with that approach is that it's a lot off stuff to learn if you're a beginner and just want to use a JS lib from cljs

pradyumna11:12:34

yes, it brings in webpack. what i liked was it decoupled cljs from npm. actually i was facing issues with the npm itself. now, once bundling is done, then no more issues related npm while working with cljs.

thheller11:12:00

if you don't want to deal with webpack you could try shadow-cljs. it supports pretty much all npm packages

curlyfry11:12:42

@thheller That pretty much excludes using figwheel, right? I'd still very much like to use that, for example for the testing functionality. I know shadow has live reload functionality as well.

thheller11:12:38

shadow-cljs also has testing functionality

souenzzo20:12:50

there is something like Object.entries in goog lib?

mfikes21:12:02

@souenzzo Are you wanting to go from something like #js {:a 1 :b 2} to #js [#js ["a" 1] #js ["b" 2]]? I don't recall anything like that, but goog/forEach gets close. What are you trying to do?

mfikes21:12:05

Maybe a little code like this would do it

(let [o #js {:a 1 :b 2}]
  (map #(vector % (goog.object/get o %)) (js-keys o)))

👍 4
souenzzo21:12:31

I did almost it. I just need to turn a js map into a clojure map, but js->clj don't work because it's a odd js map

dylandrake21:12:06

Is it possible to store components in a reagent/atom? I am working on a web app that has a UI that is broken into a side navbar on the left and a "workspace" on the right. When you click options on the side bar it should change the workspace to reflect the item you want to work on. Can I: (defn work-space [] [@work-space-state]) then reset! the @work-space-state with the name/symbol of a component? So, there would be an on-click attribute with #(reset! @work-space-state item-view-component)

dpsutton21:12:30

why not store the state of the components and an indicator of which component you are in?

dylandrake21:12:08

@dpsutton like just store a string in the @work-space-state atom?

dpsutton21:12:42

sure. {:selected-component :user-editor :state {:first-name ....}}

dpsutton21:12:20

i used a keyword like :user-editor but you could use whatever values you want to indicate which component should be focused

dylandrake21:12:35

The app let's a user work with tabular data. The left side bar has user account options like settings then a button to create a table then a list of their tables. If they click on one of the tables or say, settings, the entire work-space div changes to hold a table-view component or the setttings-view component. So, in my work-space component should I just deref the work-space-state and have a bunch of if statement to check which component should be nested in the work-space div?

(defn work-space
  []
  (if (= @work-space-state "table-view")
    [table-view]
etc..

dpsutton22:12:37

you can use triple backticks for multiline

dylandrake22:12:46

sorry bout that

dpsutton22:12:52

no worries. just for your sanity 🙂

dpsutton22:12:30

that's the general idea. build it as general as you like

dylandrake22:12:31

haha definitely