This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-12-20
Channels
- # adventofcode (47)
- # announcements (3)
- # aws (29)
- # bangalore-clj (3)
- # beginners (63)
- # boot (2)
- # braveandtrue (40)
- # calva (34)
- # cider (37)
- # cljs-dev (8)
- # clojars (3)
- # clojure (45)
- # clojure-europe (2)
- # clojure-france (4)
- # clojure-india (2)
- # clojure-italy (44)
- # clojure-japan (4)
- # clojure-nl (39)
- # clojure-serbia (1)
- # clojure-spec (21)
- # clojure-uk (75)
- # clojurescript (28)
- # cursive (24)
- # data-science (3)
- # datomic (31)
- # emacs (13)
- # fulcro (35)
- # hoplon (21)
- # jobs-discuss (66)
- # nrepl (18)
- # off-topic (72)
- # pathom (35)
- # re-frame (20)
- # reagent (54)
- # shadow-cljs (35)
- # spacemacs (9)
- # specter (8)
- # sql (13)
- # testing (9)
- # tools-deps (21)
- # vim (3)
Hi, there, I met a problem when I trying to use nubank workspace devcard, I simply changed the original code in demo_ws.cljs to this:
(ws/defcard fulcro-demo-card
(ct.fulcro/fulcro-card
{::f.portal/root c/PlaceholderImage
::f.portal/initial-state {:w 50 :h 50 :label "hello"}}))
I expect it works, but always give me error:
ui.cljs:356 Error mounting card {ns: "app.demo-ws", name: "fulcro-demo-card", str: "app.demo-ws/fulcro-demo-card", _hash: 1665702031, _meta: null, …}cljs$lang$protocol_mask$partition0$: 2154168321cljs$lang$protocol_mask$partition1$: 4096name: "fulcro-demo-card"ns: "app.demo-ws"str: "app.demo-ws/fulcro-demo-card"_hash: 1665702031_meta: null__proto__: Object cljs$core$ExceptionInfo {message: "Invalid join, {:ui/root nil}", data: {…}, cause: null, name: "Error", description: undefined, …}
Does your PlaceholderImage have a query?
What does it look like?
how do I deal with external libraries in my mutations that include asynchronicity? I.e. I have a javascript library that manages authentication tokens for me, but it includes a Promise based interface. How do I add the return value of that promise to my remote mutation params?
I’m currently wrapping my transact!
calls with a callback in the UI layer and adding the params there , but that feels against the promise of Fulcro to add async code to the UI layer. I should be able to handle this within mutations I think.
@currentoor Thanks for the hint, looks it's because it lacks the query, after adding it, it's ok.
this code is generated by template. btw, is there any tutuorial for workspace? it's too complicated for a beginner, not easy and intuitive as devcards.
@thenonameguy the action in transact should be only about local state, for async things/remote changes you should the remote layer (doing on the server or you can make a local implementation)
@wilkerlucio maybe I wasn’t clear, let me demonstrate with a minimal code example:
(defmutation do-thing [params]
(action [env] ...)
(remote [{:keys [ast]}] (assoc ast :params {:secure-token (some-lib/promise-call)}))) ; change the parameters
yeah, you can't, if you need to get the secure token you should do it before, if it's a chain of operations and you depending on something you can use ptransact!
to nest a sequence operations that might include remotes (that can do async). The idea is to avoid uncontrolled async that can generate a lot of confusion as code base grows, makes sense?
ah, ok. So between the two choices of triggering a transact!
from a callback vs. chained mutations the latter is preferred
preferably not from a callback, your UI is better if it doesn't know about async at all
you can make all data works in terms of attributes, and use your remote to pull those out, separating the concerns
yeah, this is calling some-libs
internal API, the reason I’m pulling in the library is not having to write the network code to get the :secure-token
having the secure token on the app db?
yeah, the problem is it’s an Oauth2 token and the lib handles reauthentication, etc. which I don’t want to implement
if they have events, you can hook on those
its totally ok to call transactions from the outside
you need to get a hold of the app atom, from that you can get the reconciler, and you can use it to call transactions from anywhere
// Alternatively, you can subscribe to the 'renewed' event:
authClient.tokenManager.on('renewed', function (key, newToken, oldToken) {
console.log(newToken);
});
so you can still have the lib doing all of this, and syncing the fulcro db when it changews
thanks @wilkerlucio! Awesome pathom talk btw, keep it up 👍
you'r welcome, thanks for the feedback 🙂