Fork me on GitHub
#clojurescript
<
2022-10-23
>
M J13:10:45

Hey everyone, I have a table:

(map (fn [{:keys [name updated_at]}]
             [table-row
              [table-cell name]
              [table-cell updated_at]])
           (:selected-folder/forms data))
Inside the (:selected-folder/forms data), this is how it looks like [{:name F1, :updated_at nil, :theme_data nil} {:name Untitled Form, :updated_at nil, :theme_data nil}] (for instance) HOW DO I DO sorted-map-by where it sorts the data either ascending or descending based on the :name KEY? Thanks, appreciate all the help in advance

Alexis Schad17:10:22

it seems that it is a seq/vector instead of a map. So you can use directly sort and its derivatives. (sort-by :name (:selected-folder/forms data)) ; asc (sort-by :name > (:selected-folder/forms data)) ; des

M J08:10:45

If im merging two vectors, you know how can I sort-by "2" keys, in this case, :product_name and :name ? THANKS

Alexis Schad08:10:39

If each donโ€™t exist in the other one, you can or them #(or (:name %) (:product_name %)) instead of :name

๐Ÿ™Œ 1
M J08:10:57

Thanks alot! worked ๐Ÿ˜

M J13:10:01

Another question, I am importing two maps to display on an MUI table. This is how I do it:

(map (fn [{:keys [product_name thumbnail id template_id last_send_count last_accessed_date product_description]}]
             [table-row
              [table-cell {} product_name]
              [table-cell {} "workspace-name"]
              [table-cell {} last_accessed_date]])
           (if (nil? @sorted-data) (:selected-folder/projects data) @sorted-data))

      (map (fn [{:keys [name id theme_data count updated_at form_id]}]
             [table-row
              [table-cell {} name]
              [table-cell {} "workspace-name"]
              [table-cell {} updated_at]])
           (:selected-folder/forms data))
Any ideas how do I "merge" both maps into one so when I want to sort the data, it sorts both maps ascending/descending order. Thanks

Alexis Schad17:10:50

as I said in the other thread they are vectors so just use concat: (concat data1 data2)

M J08:10:14

thanks alot

๐Ÿ™Œ 1
JAtkins18:10:55

Hi, is it possible to get the ns-alises of a cljs namespace calling a macro? e.g. (defmacro ns-aliases [] (ns-aliases *ns*)) Currently I get the empty map, though printing *ns* indicates that it is indeed the calling cljs namespace.

JAtkins18:10:51

correction, this does work if I'm calling from cljc. test.cljs

(println (other-ns/ns-aliases)) => {}
test.cljc
(println (other-ns/ns-aliases)) => {dev.other-ns other-ns}

Alexis Schad08:10:28

Macros are run in Clojure (Java), even if it is used in cljs. If you want it at runtime you might want to use google closure api.

Fredrik Andersson19:10:27

I'm trying to understand how to use thrown? with cljs.test. Now i get this error

FAIL in (col-ref-to-doc-path) (anr/fire/admin_test.cljs:24:9)
Creating CollectionReference with a document path
expected: (thrown? (f/col [:tests :test-id]))
  actual: nil
My test code is:
(deftest col-ref-to-doc-path
  (testing "Creating CollectionReference with a document path"
    (is (thrown? (f/col [:tests :test-id])))))
I'm not sure what to put as the first argument to thrown?

p-himik19:10:50

Any form that is expected to throw. thrown? accepts a body that the function handling thrown? wraps in a try-catch block. In your case, seems like that call to f/col didn't throw.

p-himik19:10:33

Oh, sorry - the body comes as the last item in the (thrown? ...) form. The first item is the exception type - what you'd put after catch.

Fredrik Andersson19:10:56

yes, it successfully tried with js/Error

p-himik19:10:15

So if you'd write

(try
  (some-code)
  (catch :default e
    ...))
then in a test it would be (is (thrown? :default (some-code))).

Fredrik Andersson19:10:43

ah, I'll try :default too

Fredrik Andersson19:10:59

yep that works too

Fredrik Andersson19:10:01

thanks!

๐Ÿ‘ 1
chromalchemy23:10:36

Anyone know how to use pseudo elements in Garden? I am trying to use a ::before psuedo-elem. (css [:p [garden.selectors/before {:content "'mytext'"}]]) Returns "p ::before {\n content: 'mytext';\n}" But not sure how to connect element to psuedo-element in rule so it renders like this: p::before {content: "mytext";}

chromalchemy02:10:32

This works:

(css [:p:before {:content "'mytext '"}])

=> "p:before {\n  content: 'mytext ';\n}"

localshred17:10:23

[:p (g.sel/& (g.sel/before)) {:content "'mytext '"}]

localshred17:10:57

or

[(g.sel/p (g.sel/before)) {:content "'mytext '"}]

localshred17:10:34

and of course you can always just do

["p::before" {:content "'mytext '"}]