Fork me on GitHub
#re-frame
<
2021-12-09
>
roelof06:12:53

I hope any bulma expert is here because after a few days struggeling I do not see why this is not showing what its supposed to do

(defn main-panel []
 [:section.hero.is-fullheight
  [:div.hero-body.has-text-centered
    [:div.container
     [:div.box 
     [:div.columns
       [:div.columns.is-four-fifths
         [:textarea.textarea]]
       [:div.columns.is-one-fifths]
       [:div.columns.is-one-fiths]]]]]])
and that is to show the text-area in a part of 4/5 of the container

thheller07:12:03

@roelof I don't have a clue about bulma but guessing from the naming conventions I would expect :div.column elements to be nested in :div.columns. right now you have :div.columns in :div.columns. There is also a is-four-fifths and then two is-one-fifths (although one has a typo) which would make it 6/5?

👍 1
Gerome07:12:26

You have a keen eye. I didn't see that one.

roelof07:12:18

thanks, have to dive into it

roelof07:12:29

still not complete happy with the layout

roelof07:12:41

looks to me that the second text-area is smaller then the first

roelof07:12:02

(defn main-panel []
 [:section.hero.is-fullheight
  [:div.hero-body.has-text-centered
    [:div.container
     [:div.box 
     [:div.columns
       [:div.column.is-two-fifths
         [:textarea.textarea]]
       [:div.column.is-one-fifths]
       [:div.column.is-two-fiths
          [:textarea.textarea]]]]]]])

thheller07:12:50

is-two-fiths vs is-two-fifths

👍 1
roelof07:12:53

thanks, now it looking what I have in mind

roelof07:12:33

next challenge, find out how I can add what I added in the first text-area to the atom

roelof07:12:42

so back to the books

roelof08:12:25

and another problem I wanted to add 10x to the mix and now I have this

:builds
 {:app {:target :browser
        :output-dir "resources/public/js/compiled"
        :asset-path "js/compiled"
        :modules
        :devtools
         {:pre-loads [day8.re-frame-10x.preload]}
        :dev
        {:compiler-options
         {:closure-defines
          {re-frame.trace.trace-enabled?   true
           day8.re-frame.tracing.trace-enabled  true}}}
        :relaase
         {:build-options
         {:ns-aliases
          {day8.re-frame.tracing day8.re-frame-tracing-stubs}}}
        {:app {:init-fn toy-project1.core/init}}}}

 :nrepl {:port 8777}}
but when I want to run it I see this error message
[:app] Build failure:
Invalid configuration
-- Spec failed --------------------

  {:target ...,
   :output-dir ...,
   :asset-path ...,
   :modules :devtools,
            ^^^^^^^^^
   {:pre-loads [day8.re-frame-10x.preload]} ...,
   {:compiler-options
    {:closure-defines
     {re-frame.trace.trace-enabled? true,
      day8.re-frame.tracing.trace-enabled true}}}
   ...,
   {:build-options
    {:ns-aliases {day8.re-frame.tracing day8.re-frame-tracing-stubs}}}
   ...,
   :build-id ...}

should satisfy

  map?

roelof08:12:58

and this one compiles

:builds
 {:app {:target :browser
        :output-dir "resources/public/js/compiled"
        :asset-path "js/compiled"
        :modules
         {:app {:init-fn toy-project1.core/init}}}}
        :devtools
         {:pre-loads [day8.re-frame-10x.preload]}
        :dev
        {:compiler-options
         {:closure-defines
          {re-frame.trace.trace-enabled?   true
           day8.re-frame.tracing.trace-enabled  true}}}
        :relaase
         {:build-options
         {:ns-aliases
          {day8.re-frame.tracing day8.re-frame-tracing-stubs}}}
        :nrepl {:port 8777}}
but I do not see 10x appear 😢

thheller08:12:36

:preloads not :pre-loads

Gerome08:12:49

Hey! Very good!

thheller08:12:14

:release not :relaase. you really gotta check your typos

thheller08:12:01

also the :nrepl seems to have gotten into the build. it belongs at the top level, otherwise it'll have no effect

roelof08:12:03

I think im given up on this

roelof13:12:13

Can someone help me figure out why I do not see 10x appear

;; shadow-cljs configuration
{:source-paths
 ["src"]

 :dependencies
 [
     [reagent "1.1.0"]
     [re-frame "1.2.0"]
     [day8.re-frame/re-frame-10x "1.0.2"]
 ]

 :dev-http {8280 "resources/public"}

 :builds
 {:app {:target :browser
        :output-dir "resources/public/js/compiled"
        :asset-path "js/compiled"
        :modules
         {:app {:init-fn toy-project1.core/init}}}}
        :devtools
         {:preloads [day8.re-frame-10x.preload]}
        :dev
        {:compiler-options
         {:closure-defines
          {re-frame.trace.trace-enabled?   true
           day8.re-frame.tracing.trace-enabled  true}}}
        :release 
         {:build-options
         {:ns-aliases
          {day8.re-frame.tracing day8.re-frame-tracing-stubs}}}
        :nrepl {:port 8777}}

anthony-galea13:12:36

@roelof did you press ctrl-h as mentioned in https://github.com/day8/re-frame-10x#usage? And if you did and the trace panel doesn’t show maybe this will help you: https://github.com/day8/re-frame-10x#if-the-re-frame-10x-window-wont-show-up-when-pressing-ctrl-h

roelof14:12:07

I did and the last link you gave me gives nill

roelof14:12:23

and crtl-h gives me the history

anthony-galea14:12:46

You’re pretty close @roelof 1. Pull out :nrepl to top level of the config map 2. Remove the 2 extra curly braces around init-fn 3. trace-enabled? (note missing ?) 4. re-frame.tracing-stubs (`.` not -)

roelof14:12:20

Thanks, you saved my day

👍 1
roelof15:12:00

stills something wrong. 10x is not updated 😢

paulbutcher17:12:46

Is there some way to hide the re-frame-10x inspector other than ^H on the keyboard? I’m trying to debug on my iPad and can’t find a way to hide the inspector? Thanks!

paulbutcher17:12:48

Cool - thanks 👍

paulbutcher17:12:06

I see that there’s a (rather old!) pull request for one of those issues? Is there a reason why it wasn’t applied?

p-himik17:12:34

No clue - might actually be worth pinging the maintainers there.

p-himik17:12:56

Sometimes things just get lots among all else.

paulbutcher17:12:55

Cool - will do. Thanks again!

👍 1
roelof18:12:59

Why is my db not updated after I enters 1 char

(def default-db
  {:text ""})
views :
(defn main-panel []
 [:section.hero.is-fullheight
  [:div.hero-body.has-text-centered
    [:div.container
     [:div.box
     [:div.columns
       [:div.column.is-two-fifths
         [:textarea.textarea {:on-change #(re-frame/dispatch [::events/update-text (-> % .-target .-value)])}]]
       [:div.column.is-one-fifths]
       [:div.column.is-two-fifths
          [:textarea.textarea]]]]]]])

roelof18:12:17

event:

(re-frame/reg-event-db
 ::update-text
 (fn [db [_ v]]
   (assoc db :text v)))

p-himik18:12:48

Hard to say without having all of the code. But your re-frame-10x panel shows that there was no event other than ::initialize-db. So it narrows it down. Check the browser's JS console and see if there are any errors/warning. Replace that :on-change with a logging function and see if it logs anything. Log the body of the event handler and see if that works. It's all standard debugging procedure - you have a set of premises and a set of observations, and all you have to do is keep on making hypotheses and testing them, starting from the most obvious to the least obvious ones.

roelof19:12:39

so you mean something like this :

(.log js/console 'this is working)
?

p-himik19:12:36

Two things: • CLJS strings must be in double quotes • You can write (js/console.log ...) instead of (.log js/console ...), makes it a tad easier

p-himik19:12:44

Apart from that, yes.

roelof19:12:55

oke, when I do this :

[:textarea.textarea {:on-change #(.log js/console "this is working")}]]
I see the output in the console

roelof19:12:05

so the on-change seems to be working

p-himik19:12:48

Well, there was a hypothesis that :on-change wasn't triggering, and now you refuted it. Now make a new hypothesis and check it. :)

roelof19:12:24

found something wierd

roelof19:12:50

(re-frame/reg-event-db
 ::update-text
 (fn [db [_ v]]
    (.log js/console "this is working")
   (assoc db :text v)))
I see sometimes the text and sometimes not

p-himik19:12:20

And there's nothing in the JS console of your browser?

roelof19:12:23

if you mean this

roelof19:12:34

I see now one time the text appear

p-himik19:12:38

Are you sure that your code is the one running on that web page? Meaning, if your hot code reloading not working properly, you might make a change and not see it until you reload the page or maybe fix something else somewhere.

roelof19:12:30

I start every time again a new server

roelof19:12:03

I can see that every time I press a key the log message is pressed

roelof19:12:11

so that also looks to work fine

roelof19:12:31

so I need another hypothesis and cannot think of one

p-himik19:12:38

You don't need to restart anything UI-related if you properly set up your CLJS development environment. Shadow-cljs has documentation on that. And even if you simply reload something, sometimes browsers cache stuff.

roelof19:12:42

there are no more code involved

p-himik19:12:13

Given that now seemingly everything works, my hypothesis is that your development environment is not set up properly to work with hot reloading and to handle browser caching.

roelof19:12:47

so my edn file is wrong ?

roelof19:12:14

could be a reason because after the 1 press I see the contents of the default-db method

roelof19:12:26

what surprised me

roelof19:12:03

this is my shadow-cls.edn file

;; shadow-cljs configuration
{:source-paths
 ["src"]

 :dependencies
 [
     [reagent "1.1.0"]
     [re-frame "1.2.0"]
     [day8.re-frame/re-frame-10x "1.0.2"]
 ]

 :dev-http {8280 "resources/public"}

 :builds
 {:app {:target :browser
        :output-dir "resources/public/js/compiled"
        :asset-path "js/compiled"
        :modules
         {:app {:init-fn toy-project1.core/init}}
        :devtools
         {:preloads [day8.re-frame-10x.preload]}
        :dev
        {:compiler-options
         {:closure-defines
          {re-frame.trace.trace-enabled?   true
           day8.re-frame.tracing.trace-enabled?  true}}}
        :release 
         {:build-options
         {:ns-aliases
          {day8.re-frame.tracing day8.re-frame-tracing-stubs}}}}}}
   

p-himik19:12:06

The environment is not just that shadow-cljs.edn file. In this case, the second most important part is the actual code since it has to specify what to do upon code reloading. Shadow-cljs has documentation on that, re-frame has documentation on re-frame-specific parts.

p-himik19:12:11

Let's confirm this - when you e.g. add a [:span "hello"] somewhere in your code where it's supposed to make it to the HTML, do you actually see that hello on the page after you simply save that CLJS file?

roelof19:12:50

I think the x10 part is messing things up , I did a very easy one before without x10 and then everything was working fine

roelof19:12:35

yep, it is showing hello

roelof19:12:51

so hot-reloading seems to work fine

p-himik19:12:11

Well, then you have a pretty good lead - try to follow it. Disable re-frame-10x completely, see how that works out. Enable it again, compare. Document your findings.

roelof19:12:45

oke, then I have to make some code to print out the db so I can check it

roelof19:12:19

something lilke this could be working

[:span (:db :text)]

p-himik19:12:58

I have no idea what you want to achieve with that, but that's not valid CLJS. Or rather, it is valid code but it's guaranteed to fail at run time.

roelof19:12:26

I wanted to print out the contents of the db

roelof19:12:44

and yes, it failing

roelof19:12:04

back to the books to look if there is a way I can print the contents of the db without using x10

p-himik19:12:02

You can simply reg a sub that just returns its first argument.

roelof19:12:50

you mean I have to make a subscription

roelof19:12:20

so something like this

[:span #(re-frame/subscription [::subs/read-text])]

p-himik19:12:40

You really gotta get your basics correct. #(...) creates a function, a lambda. It's a CLJS thing - CLJ, even. You don't need that, you need a value from your app-db. Re-frame has numerous examples in its documentation.

roelof19:12:08

oke, I thought you mean that

roelof19:12:53

call a subscriiption and then in subs,clj do this

(re-frame/reg-sub
 :read-text
 (fn [db]
 (db :text)))

p-himik19:12:42

Yes, that's how you register it, but using it is a different deal. Also, replace (db :text) with (:text db). This way, it will work even if db is nil, which happens before the initialization is done.

roelof20:12:09

im givimg up

roelof20:12:18

or do youy mean this :

[:pre (with-out-str (pprint (:part @re-frame.db/app-db)))]    ;; see a part of it!

p-himik20:12:20

I would recommend resting for a bit and going through re-frame documentation while jotting down things you didn't know of things you find useful but can't implement immediately. Like in this case - you don't know how to use a subscription, so when you find the relevant documentation, just write it down and refer back to it when in doubt.

p-himik20:12:39

No, don't use re-frame.db/app-db directly - it's not a public API.

roelof20:12:00

im going tot rest. it;s late here : 21:00 hour

p-himik20:12:27

You can use (fn [db _] db) as your subscription handler to see the whole db. After registering that handler with some ID, you can subscribe to that ID in a view and get the full value.

p-himik20:12:38

Right. Have a good one!

p-himik20:12:44

Yeah, not a great recommendation for newcomers.

p-himik20:12:15

It can be a quick and dirty way to inspect the value for the development purposes - sure. But you must not refer to re-frame.db in actual production code.

roelof20:12:13

I want to use it only to see if 10x is too blame . After that I delete the code

p-himik20:12:17

Then it's alright.

roelof20:12:48

oke, there is something not right with the 10x part

roelof20:12:08

when I do the part to print the db everything works well

👍 1
Braden Shepherdson18:12:00

change events fire on "commit" (eg. blur)

Braden Shepherdson18:12:29

you perhaps want input.

isak18:12:25

Do you mean :on-change ?

isak18:12:03

Never mind, that is what he had

p-himik18:12:47

:on-change events on :textarea fire right then and there, without having to blur anything.

roelof19:12:47

or can this be the culprit

"17.0.1" was required by jar:file:/home/roelof/.m2/repository/day8/re-frame/re-frame-10x/1.0.2/re-frame-10x-1.0.2.jar!/deps.cljs
NPM dependency "react-dom" has installed version "17.0.2"

p-himik19:12:02

Extremely unlikely.