Fork me on GitHub
#clojurescript
<
2020-05-23
>
jaide01:05:43

So I've got a mongoose Model. I'd like to create a couple of reusable clojure functions to wrap some of its methods to make for smooth interop. What tool should I reach for? I'm a bit lost between protocols/methods and the like.

myguidingstar02:05:00

@jayzawrotny the problem with mongoose is that the abstraction it creates are objects, which don't really compose nicely. Creating a protocol over such objects can only help with making clojuric names aka (.fooBar x) to (foo-bar x) and does not really add any value

myguidingstar02:05:28

And the fact that you're lost may be a cue that you don't really need that abstraction

myguidingstar02:05:09

I don't know how your model looks like, but I guess you will want your clojure(script) code to build around verbs instead of nouns, so functions or pathom mutations or re-frame events

myguidingstar02:05:18

And these verbs reflects what tasks you want to do with the domain model at large

myguidingstar02:05:13

In the implementation of these verbs, you can use those ugly js methods anyway, because the "interface" (the verbs and their arguments) are clojuric already :)

myguidingstar02:05:30

To sum up, my point is to skip wrapping mongoose models with clj(s) and go straight to domain modeling

jaide02:05:11

I think you鈥檙e right. I was thinking a protocol would be a good choice for creating a (find-one MyModel #js {:id 1234}) but what you pointed out was that it a simple function would work just the same.

馃憤 4
FHE03:05:38

Hey folks. I just made a post in the #beginners thread, and I don't want to break any rules if there is one against reposting in a different thread, but it's definitely a beginner question AND a clojurescript question. Just wondering about tooling, if anyone doesn't mind reading my whole question there. Thanks.

Christos12:05:01

Hey guys, any ideas how I could use media queries for material-ui components in reagent? Many thanks in advance.

p-himik13:05:17

Found this form in cljs.pprint:

(def ^{:private true}
type-map {"core$future_call" "Future",
          "core$promise" "Promise"})
Where does core$promise come from?

athomasoriginal17:05:52

I have a few questions about the new :bundle target. I felt it would be helpful if I wrote gist to ask the questions/explain where my questions come from. See https://gist.github.com/athomasoriginal/fd00691bde0be8d9a52c33f3ca968bdc#questions.

athomasoriginal17:05:50

Let me know if it鈥檚 preferred to just write everything in slack rather than a gist. Further, if anything is unclear or requires minimals, I am happy to provide. Thanks!

lilactown17:05:12

hey @tkjone. long-form posts in other mediums is fine IMO

馃檹 4
lilactown17:05:19

I鈥檓 glad you got your firebase example working

lilactown17:05:29

your noted benefits of the :bundle target is correct, plus some other things

lilactown17:05:18

there鈥檚 the JS dependency problem (which you noted) but there鈥檚 also many times when we want to feed our ClojureScript code to other tools to allow us to do cool things

lilactown17:05:12

for instance, React Native has its own bundler that does a bunch of stuff we don鈥檛 want to figure out; so we can use the :bundle target to feed our compiled ClojureScript code to their bundler to easily build mobile apps

lilactown17:05:14

for your questions, > When would a user not want to use the聽`:bundle`聽target? this is a really good question that I don鈥檛 know the answer to immediately. the :bundle target is the latest in the state of the art, so it might be too cutting edge for some. For others, they already have projects that use a different target. I think that if you were building a Node.js app, that using the :bundle target wouldn鈥檛 be what you want either; but I鈥檓 not really sure about that

lilactown17:05:42

> Does the CLJS compiled JS go through optimizations before it gets to webpack? I believe the answer is yes, your CLJS code will be compiled to JS and go through advanced optimizations in release mode

lilactown17:05:47

before reaching webpack

lilactown17:05:50

> Would it be fair to say that there are times when we would need a聽`foreign library`, like how the聽https://github.com/clojure/clojurescript-site/blob/ff54b9490e56f18572427cddf03f0ab3dca893f8/content/guides/webpack.adoc#javascript-dependencies聽worked, in combination with the聽`:bundle`聽target? if your JS code gets included via webpack, then there鈥檚 AFAIK no need to write a foreign-lib declaration. If you鈥檙e including the JS code in a way that it doesn鈥檛 go through webpack, you might need to use the foreign-lib machinery

athomasoriginal17:05:40

Good notes and yes, glad to see that there is a way to get the require working. Hopefully it鈥檚 not incidental/going to pose problems in the future 馃檹

athomasoriginal17:05:24

> if your JS code gets included via webpack, then there鈥檚 AFAIK no need to write a foreign-lib declaration 100%. my thinking was, before I found the @firebase/app and @firebase/auth solution, that I would have to declare a foreign-lib. Now I see I don鈥檛. So that question was really about a hypothetical鈥robably not the best way to approach the question because unless it鈥檚 a real problem, its speculative.

Spaceman23:05:45

what does the following error mean?:

Spaceman23:05:01

Uncaught Error: Vector's key for assoc must be a number.
    at Object.eval [as cljs$core$IAssociative$_assoc$arity$3] (core.cljs:5590)
    at Function.eval [as cljs$core$IFn$_invoke$arity$3] (core.cljs:1977)
    at merge_entry (core.cljs:9104)
    at eval (core.cljs:2459)
    at Function.eval [as cljs$core$IFn$_invoke$arity$3] (core.cljs:2459)
    at Object.eval [as cljs$core$IReduce$_reduce$arity$3] (core.cljs:6786)
    at Function.eval [as cljs$core$IFn$_invoke$arity$3] (core.cljs:2529)
    at merge2 (core.cljs:9106)
    at eval (core.cljs:1503)
    at Function.eval [as cljs$core$IFn$_invoke$arity$4] (core.cljs:1503)

Carlos Requena L贸pez00:05:13

Happened to me when I tried to assoc-in like this:

(assoc-in {:a [{:b 1}]} [:a :key :b] 2)
Should be:
(assoc-in {:a [{:b 1}]} [:a 0 :b] 2)
Basically when trying to refer to a vector position with a key like :key

didibus02:05:02

When you assoc on a vector, the key argument (second argument to assoc) must be a number

krzyz02:05:15

Vectors are associative, like maps, based on their indices. Of course a vector index must be numeric.