Fork me on GitHub
#clojurescript
<
2022-04-21
>
Sakib09:04:26

I have created a reagent component in the following way.

(ns giggin.components.giggs
  (:require [giggin.state :as state]))

(defn gigs
  []
  [:main
   [:div.gigs (map gig (vals @state/gigs))]])

(defn gig [{:keys [id img title price desc]}]
  [:div.gig {:key id}
   [:img.gig__artwork {:src img :alt title}]
   [:div.gig__body
    [:div.gig__title
     [:div.btn.btn--primary.float--right.tooltip {:data-tooltip "Add to order"}
      [:i.icon.icon--plus]] title]
    [:p.gig__price price]
    [:p.gig__desc desc]]])
Here state is a reagent/atom. Everything rendering correctly. But got the following warning.
[:app] Compiling ...
[:app] Build completed. (163 files, 2 compiled, 1 warnings, 0.24s)

------ WARNING #1 - :undeclared-var --------------------------------------------
 File: /home/sakib/Workspace/school/clojure/jacekschae-reagent/learn-reagent-course-files/giggin/src/giggin/components/giggs.cljs:7:20
--------------------------------------------------------------------------------
   4 | (defn gigs
   5 |   []
   6 |   [:main
   7 |    [:div.gigs (map gig (vals @state/gigs))]])
--------------------------^-----------------------------------------------------
 Use of undeclared Var giggin.components.giggs/gig
--------------------------------------------------------------------------------
   8 | 
   9 | (defn gig [{:keys [id img title price desc]}]
  10 |   [:div.gig {:key id}
  11 |    [:img.gig__artwork {:src img :alt title}]

p-himik09:04:04

This belongs more in #reagent But the error is using gig before defining it.

thanks3 1
p-himik09:04:11

CLJS is different from JS in this regard.

👍 1
1
thheller09:04:09

that is because you define gig after gigs. need to swap the order of the function to make that warning go away

Em09:04:54

Figwheel Troubles UPDATE: I learned that you need to keep the tab open to do CLJS… That was my problem I’m having trouble following the tutorial here https://figwheel.org/docs/vim.html they say to:

$ lein repl
user=> (require 'figwheel.main.api)
user=> (figwheel.main.api/start {:mode :serve} "dev")
user=> ;; the above two worked fine
user=> ;; the next line will fail with "No such namespace: figwheel.main.api"
user=> (figwheel.main.api/cljs-repl "dev")
 
I assume it has to do with what happens when the dev environment is started with my code - all i’d really like to do is connect vim to the cljs repl which requires something like
(figwheel.main.api/cljs-repl "dev")
Does this strike anyone as a problem they’re familiar with?

Em09:04:06

Ah, thanks to @U031CHTGX1T for pointing out that the browser tab needs to be open for this sort of stuff 😅

👍 1
rayat21:04:58

I literally forget this every other time, so when I get a notice from shadow like "no js runtime" with no browser open I Surprise Pikachu, until I :face_palm::skin-tone-4:

❤️ 1
Pepijn de Vos13:04:13

huh? This SO post suggest cljs has an abs function but... it doesn't. Is this a super recent addition? Not sure what my clojursctipt version is, since I don't think my shadow-cljs config has a direct dependency.

p-himik13:04:23

Which post? :)

Pepijn de Vos13:04:57

> As of Clojure 1.11, it is simply (abs -1) in both Clojure and Clojurescript.

p-himik13:04:58

The commentator is rushing a bit. According to the docstring of abs that's in the CLJS repo, it will be available in 1.11.10 which is not released yet.

Pepijn de Vos13:04:12

aww 😞 ok makes sense

Pepijn de Vos13:04:45

Initially I was extra confused because the answer is dated 2014, but it's been edited.

zimablue16:04:50

is there a duratom equivalent in cljs?

zimablue16:04:28

I mean literally, not something like datahike, konserve

zimablue16:04:14

I also realize it would be MUCH simpler because of concurrency model

lilactown16:04:09

i think what most people do is use a regular atom with a watch that persists wherever you want, and on startup loads the data from wherever

lilactown16:04:24

if you're just persisting to local storage it's quite easy

zimablue16:04:15

thanks that's a simpler solution which should fit my usecase