This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-06
Channels
- # adventofcode (181)
- # aws (6)
- # beginners (112)
- # boot (38)
- # cider (11)
- # cljs-dev (12)
- # cljsrn (2)
- # clojure (187)
- # clojure-greece (31)
- # clojure-italy (19)
- # clojure-new-zealand (1)
- # clojure-poland (1)
- # clojure-spec (20)
- # clojure-uk (114)
- # clojurescript (97)
- # core-logic (25)
- # cursive (3)
- # data-science (17)
- # datascript (3)
- # datomic (23)
- # defnpodcast (1)
- # duct (5)
- # emacs (3)
- # fulcro (299)
- # graphql (108)
- # jobs (1)
- # juxt (4)
- # lein-figwheel (7)
- # leiningen (1)
- # lumo (9)
- # nrepl (2)
- # off-topic (10)
- # om (2)
- # onyx (36)
- # pedestal (1)
- # perun (3)
- # re-frame (14)
- # reagent (12)
- # ring (2)
- # rum (11)
- # shadow-cljs (6)
- # spacemacs (4)
- # unrepl (8)
releasing 2.0.0-beta4 to clojars. Found a bug in defsc
. Also expanded defsc
to support react lifecycle with simple keywords in options:
:shouldComponentUpdate (fn [props state] …)
live developer’s guide update coming to the website in just a min. I’m through the (second) refinement up to section G
http://fulcro.fulcrologic.com/guide.html has updated. You may need to clear cache.
http://fulcro.fulcrologic.com/guide.html#!/fulcro_devguide.G_Mutation should talk about intern’ing mutations at the very end (if you have the latest version)
[(gs/> :.table-header "div") {:font-weight "normal"
:text-align "left"
:padding "5px 4px"
:border-right border}
[:&.flex {:flex 1}]
[(gs/& gs/last-child) {:border-right "0"}]]
Any recommendations for how to learn this stuff when you don't have great browser/web experience? That happens to be a snippet from Fulcro Inspect.
The functions are in garden…so I think gs/>
is just the css >
relation operator…like .table-header > div
https://github.com/noprompt/garden in the “garden.selectors” part
Just trying to understand every little bit of Fulcro Inspect. Lots of good stuff there. The ref
thing is confusing as its always in env. Its certainly good to learn from thou...
@cjmurphy learning more about CSS can help a lot, the selector you sent has indeed some mixed features of CSS that you have to know to understand it, but I can break those down for you:
(gs/> :.table-header "div")
-> .table-header > div
-> this selector affects only the div
tags that are direct children (first child level on tree) of the element with the classname table-header
:&.flex
-> .table-header > div.flex
-> for those same div
from the previous selector, if it has the class flex
, add the flex property
(gs/& gs/last-child)
-> .table-header > div:last-child
from those same div
selection as before, affect only the last child on that level
<div class="table-header">
<div>I'm affected</div>
<div>
Me Too
<div>But I'm not</div>
</div>
</div>
@cjmurphy makes sense?
Not yet, but can I come back to you, just heading out and need a rest from the screen. Thanks a lot and I'll come back...
no problem
Hello! I am learning Fulcro and I’m stuck with (I am sure) a silly issue - I have created a new project with lein new fulcro fulcro-playground
and I started it from Intellij with -Dcards -Dtest -Ddev
and figwheel script.
The issue is that I have added :started-callback
to src/main/fulcro_playground/client.cljs
:
(defonce app (atom (fc/new-fulcro-client
{:started-callback
(fn [app]
(js/console.log "Loading data..."))})))
but it is not being called when I open http://localhost:3449/index.html
Have I missed anything?(defonce app (atom (fc/new-fulcro-client
:started-callback (fn [{:keys [reconciler] :as app}]
(console.log "started ? ...")))))
@wilkerlucio do you have a pathom version that works without om.next?
@roklenarcic no, pathom uses the om.next/query->ast
and om.next/ast->query
quite a lot, that would have to be re-implemented in order to remove om.next
dependency, that said, this is something I would like to have in Pathom on future
ah snap
@wilkerlucio could you publish a non-snapshot version of fulcro.inspect
? I don’t like adding snapshot deps.
I’m trying to hook up the server interop. I get the request, I answer it but the data turns up empty on the client
@thheller So, you can use the regular network panel in Chrome and look at the response. Transit isn’t too terrible to at least make out the basic structure.
{:q/builds
({:target :browser,
:output-dir "target/dce-test",
:compiler-options {:fn-invoke-direct true},
:modules
{:core {:entries [cljs.core]},
:main {:entries [demo.dce], :depends-on #{:core}}},
:id :dce,
:build-id :dce}
{:target :node-script,
:main demo.errors/main,
:output-to "out/demo-errors/script.js",
:id :errors,
:build-id :errors} ...
(defsc BuildItem [this props]
{:initial-state (fn [p] p)
:query [:build-id]
:ident [:builds/by-id :build-id]}
(html/div (pr-str props)))
(def ui-build-item (fp/factory BuildItem {:keyfn :build-id}))
(defsc BuildList [this {:keys [builds] :as props}]
{:initial-state
(fn [p]
{:page :build-list
:builds [(fp/get-initial-state BuildItem {:build-id :foo})]})
:query
[:page
{:builds (fp/get-query BuildItem)}]}
(html/for [build builds]
(ui-build-item build)))
1. lists are not valid data in Fulcro, only vectors. 2. Your query in BuildList is not asking for what you called it
(defmethod fs/read-root :q/builds [env _ params]
{:value
(-> (config/load-cljs-edn)
(get :builds)
(vals)
(into []))})
I tried adding {:target [:somewhere]}
on the df/load
but wherever I put it it ends up as an empty vector
That’s where you asked it to go. If you want it to go elsewhere, use (load :q/build BuildList {:target [:builds]})
I love developing in devcards…the inspect-data true
option shows your whole database…so you can tell the difference between what is in your database vs what you’re getting out with the query.
fulcro-inspect
works with 2.0 now, and will also show you this kind of stuff
defmethod fs/read-root :q/builds [env _ params]
{:value
(-> (config/load-cljs-edn)
(get :builds)
(vals)
(into []))})
(defn fulcro-request [{:keys [transit-read transit-str fulcro-parser ring-request] :as req}]
(let [body (-> req :ring-request :body slurp transit-read)
result (fulcro-parser
{:app req
:parser fulcro-parser
:ast body}
body)]
(prn [:request body])
(pprint result)
{:status 200
:header {"content-type" "application/transit+json"}
:body (transit-str result)
}))
there is plumbing you definitely want to have in that. See the dev guide on Rolling Your own Server
then if you don’t want to use the macros (which separate out the traffic between entities and root) you might want to use your own parser and multimethod, or whatever, just make a new parser…
as long as you’ve read the macros, you can use the multimethods…just saying, parser is completely open and standard component.
switched to handle-api-request
but AFAICT the response from the server is identical to before
{:status 200,
:body
{:q/builds
[{:target :browser,
:output-dir "target/dce-test",
:compiler-options {:fn-invoke-direct true},
:modules
{:core {:entries [cljs.core]},
:main {:entries [demo.dce], :depends-on #{:core}}},
:id :dce,
:build-id :dce}
{:target :node-script,
:main demo.errors/main,
:output-to "out/demo-errors/script.js",
:id :errors,
:build-id :errors} ...
what is empty? Are you looking at the entire database, or the result of the broken query?
[ 0.845s] [fulcro.client] Mutation fulcro.inspect.ui.transactions/add-tx failed with exception Error: Assert failed: Path [:fulcro.inspect.ui.transactions/tx-list-id [:fulcro.inspect.core/app-id nil] :fulcro.inspect.ui.transactions/tx-list] for append must target an app-state vector.
(vector? (get-in state data-path))
@wilkerlucio is doing that project…not sure either
sounds like the app ID thing in it didn’t work, and it isn’t able to put the tx on a list at the missing storage location
(defn start []
(reset! app-ref
;; I really don't like putting this in a defonce seems to break often
(fc/new-fulcro-client
:started-callback
(fn [app]
(js/console.log "fulcro started")
(fdf/load app :q/builds BuildList {:target [:builds]})
(when-let [prev-state @state-ref]
;; can't figure out how to restore app state otherwise
(let [app-state (get-in app [:reconciler :config :state])]
(swap! app-state merge prev-state))))))
(swap! app-ref fc/mount Root "root"))
(defn stop []
(reset! state-ref @(get-in @app-ref [:reconciler :config :state])))
so, the return value from your server function must match the query of the component. In your case [:page {:builds ...}]
You want (load app :q/builds BuildItem {:target [path-to-component-field-where-builds-should-live]})
https://github.com/thheller/shadow-cljs/blob/fulcro/src/main/shadow/cljs/ui/app.cljs
If you send a query for [{:person (get-query Person)}]
you have to respond with {:person {:db/id ...}}
OR {:person [{:db/id ...} ...]}
(to-many)
The keyword in (load :keyword ...)
becomes part of the query, as a join (you don’t have to care about that part, since the parser is already taking care of that level of the response). So, you’re asking for [{:q/build (get-query BuildList)}]
, but you’re responding with {:q/build [ list of build items]}
but load will load it where you said to load it, and try to normalize it with the query you gave
So, simple rule really: Return one or to-many of what you asked for. You didn’t do either. You asked for BuildList, but returned many BuildItem
If you pull the query
from the env
on the server, you’ll see that what you’re being asked for does not match what you’re returning
Technically Fulcro does not require you to normalize anything…so this is why it visibly seems to work.
yep…your db is now one level deeper, because you targeted a BuildList at BuildItems 😜
better to get the query norm/loading basics down before throwing more potential errors in the mix
just got back people
@thheller I'm planning making a release by today or tomorrow, most of the current things were mostly dev snapshots, that's why I kept snapshooting 😛, but yes, we will have a non-snapshot soon
the error you posted I haven't seen before, are you using Fulcro 2.0 with inspect 0.2.0?
@tony.kay can I query for *
somehow? just gimme all the props or do I need to list them all?
that might work…`db->tree` does thngs left-to-right, so the join might just overwrite the thing it pulled as a pro
(defsc BuildItem [this props]
{:initial-state (fn [p] p)
:query ['*]
:ident [:builds/by-id :build-id]}
(html/div (pr-str props)))
oh, not sure if is that, but in fulcro-4 the defsc
macro had a breaking change, inspect
isn't up to date with that yet
not sure how you that even to compile :thinking_face:
(defsc BuildItem [this {:keys [build-id target] :as props}]
{:initial-state (fn [p] p)
:query
(fn [] ['*])
:ident [:builds/by-id :build-id]}
(prn [:build-item/render props])
(if-not (map? props)
(pr-str props)
(html/div
(html/h2 {} (name build-id))
(html/p {} (pr-str props)))))
[:build-item/render [:ui/fetch-state {:fulcro.history/tx-time 2, :fulcro.client.impl.data-fetch/uuid "79ae0bdc-e8f5-49da-a360-857eaad6fa5c", :fulcro.client.impl.data-fetch/parallel false, :fulcro.client.impl.data-fetch/target [:pages/builds :top :builds], :fulcro.client.impl.data-fetch/original-env {}, :fulcro.client.primitives/ident nil, :fulcro.client.primitives/remote :remote, :fulcro.client.primitives/query [{:q/builds [*]}], :fulcro.client.impl.data-fetch/refresh [[:pages/builds :top]], :fulcro.client.impl.data-fetch/type :ready, :fulcro.client.impl.data-fetch/post-mutation-params nil, :fulcro.client.impl.data-fetch/fallback nil, :fulcro.client.impl.data-fetch/marker true, :fulcro.client.impl.data-fetch/post-mutation nil, :fulcro.client.impl.data-fetch/field nil}]]
@tony.kay is there a reason you're not using the lein figwheel
command in the getting started docs?
@thheller I just pushed a new snapshot to 0.2.0, with changes for fulcro 2.0.0-beta4, I think you problem seems different, but can you try that please?
ah, but question, are you using figwheel or shadow-cljs to build?
because I remember Mitchel tried and wasn't working with shadow-cljs, but I don't understand why
nope, pretty standard stuff
is there are difference regarding preloads?
can you try compiling with figwheel once just to isolate if it's that?
is the project you are toying around public?
@grzm better REPL integration with Cursive, and being able to start arbitrary builds via a JVM prop (also better in Cursive)
@tony.kay yes, but its a vector? should that not be a map? given that it comes in as props?
@tony.kay gotcha. Thanks. I'm trying to debug a situation where my dev/cljs/user.cljs file is only getting loaded in one of my builds. Trying to cut down what it might be.
(load app :bi BuildItem {:marker :kw})
See the new dev guide about loading indicators…just use false
for now if you want to get it out of the way
@thheller I mean the fulcro example, are you writing that code directly on shadow-cljs lib code?
@wilkerlucio I think Mitchel’s issue was a regression in the compiler that got fixed
https://github.com/thheller/shadow-cljs/blob/fulcro/src/main/shadow/cljs/ui/app.cljs
@tony.kay I'd rather not, frankly. I'm feeling there's too much magic in general in the build tools, both lein and boot. Right now I'm just trying to figure out this bug I'm seeing between different figwheel builds.
@thheller I don’t see a substantial difference there…you’re still defonce the atom to make sure it sticks around through hot code reload
the inspector is started for the app when you mount it, this initialisation should not be a problem
@tony.kay talking to @wilkerlucio about the fulcro-inspect
issue. solved the load issue by just checking if props is a map
@thheller how can I run that? I would like to see what you are seeing
just thought it was odd that I got a vector with two elements which looked like it wanted to be a map 😉
its a bit weird right now to compile shadow-cljs with shadow-cljs itself so that might not work properly
@thheller ok, one thing that might be a problem it seems on your app launch, is that your start always generate a new app
you should just create one app, and re-use that if possible, just re-mounting, but not re-initializing
(I didn't finish running yet, just a guess)
yeah but that seems to require the occasional page reload for initial state and stuff
yeah, well, it's a 2 edge sword, because we can argue that you might want to keep state as you develop 😛
but I guess how much you want each depend on how far you project are (in beginning you usually want more of data refresh, and later less)
but then you are triggering the data fetch load every time becasue the app is getting re-initialized
start from scratch with each reload basically until I understand the moving parts better
ah, if you undestand what's going on, all good 🙂
I got this when I tried to compile:
[19:22:25,052] failed to inspect resource "jar:file:/Users/wilkerlucio/.m2/repository/fulcrologic/fulcro/2.0.0-beta4/fulcro-2.0.0-beta4.jar!/fulcro/client/core.cljc", it will not be available.
clojure.lang.ExceptionInfo: failed to inspect cljs file: jar:file:/Users/wilkerlucio/.m2/repository/fulcrologic/fulcro/2.0.0-beta4/fulcro-2.0.0-beta4.jar!/fulcro/client/core.cljc {:tag :shadow.build.classpath/inspect-cljs, :resource-name "fulcro/client/core.cljc", :url #object[java.net.URL 0xa58a099 "jar:file:/Users/wilkerlucio/.m2/repository/fulcrologic/fulcro/2.0.0-beta4/fulcro-2.0.0-beta4.jar!/fulcro/client/core.cljc"]}
at clojure.core$ex_info.invokeStatic(core.clj:4739)
[:ui] Build failure:
The required JS dependency "intl-messageformat" is not available, it was required by "yahoo/intl_messageformat_with_locales.cljs".
we will see 🙂
it missed create-react-class
on the second time
yup, that will help
I think it's running now
btw is there a fulcro/stop
or shutdown
or so? something I can call so it removes all traces of itself?
not that I know, just unmount should be fine
ok, it siad it compiled, but the page is not finding hte js
@thheller seems to be working https://www.dropbox.com/s/6tx5dfa0gexiksz/Screenshot%202017-12-06%2019.38.31.png?dl=0
did you tried the latest snapshot?
I noticed this on the compilation:
Failed reading cache for fulcro.inspect.ui.events: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Array (start marker at [Source: java.io.FileInputStream@1859955a; line: 1, column: 93414])
at [Source: java.io.FileInputStream@1859955a; line: 1, column: 98851]
develop
yeah dunno why that happens but its just a cache read error, if that fails it just will recompile and not use the cache
you can looking at the .m2
, not ideal I agree
but you can try this: ls ~/.m2/repository/fulcrologic/fulcro-inspect/0.2.0-SNAPSHOT/
it will show all the versions, they have suffix
@thheller the latest for fulcro-inpect
is 6
I don't trust checkouts for CLJS, they never worked properly in my experience
"fulcro/inspect/preload.cljs")
=> #object[java.net.URL 0x56fe464c "file:/Users/zilence/code/shadow-cljs/checkouts/fulcro-inspect/src/fulcro/inspect/preload.cljs"]
can you try removing the checkout and updating the snapshot?
chrome
ah, but one thing, I got that error message you got anyway
but works
just start with ctrl+f
well, Element
seems broken, worth investigation
thanks 🙂
humm, never though of that, let me check
(fulcro.client.primitives/transact! (:reconciler (fulcro.inspect.core/global-inspector))
[:fulcro.inspect.core/floating-panel "main"]
[`(fulcro.client.mutations/set-props {:ui/visible? true})])
I’m really starting to like this. nice work everyone. still lots to process but I’m making progress 🙂
What kind of UI are you building @thheller something for shadow-cljs?
something like https://github.com/oakmac/cuttle to start with. starting/stopping/inspecting builds via web ui