This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-12-13
Channels
- # bangalore-clj (5)
- # beginners (94)
- # boot (145)
- # cljs-dev (4)
- # cljsjs (79)
- # cljsrn (18)
- # clojure (343)
- # clojure-dev (21)
- # clojure-dusseldorf (6)
- # clojure-india (1)
- # clojure-italy (2)
- # clojure-nl (4)
- # clojure-russia (62)
- # clojure-sanfrancisco (1)
- # clojure-spec (109)
- # clojure-taiwan (1)
- # clojure-uk (103)
- # clojurescript (102)
- # code-reviews (30)
- # component (1)
- # cursive (39)
- # datascript (7)
- # datomic (68)
- # emacs (11)
- # figwheel (1)
- # gorilla (1)
- # hoplon (234)
- # off-topic (46)
- # om (52)
- # onyx (32)
- # planck (9)
- # proton (4)
- # protorepl (5)
- # random (1)
- # re-frame (36)
- # ring (18)
- # ring-swagger (1)
- # specter (6)
- # untangled (3)
- # vim (56)
@eric.shao You might try the Untangled tutorial. It is where i went from when I left off on Om. Covers a lot of the material.
@tony.kay Mr Kay,Thank you for your reply,and thank for your tutorials and videos.I am studying on them.Thx!
(defn merge* [reconciler state res query]
(println "merge*" res)
(when-let [redirect (:redirect res)]
(println (str "redirecting to " redirect))
(compassus/set-route! reconciler redirect))
(om/default-merge reconciler state res query))
This is the merge function I tried. It does print "redirecting to :dashboard" but the view doesn't change...Perhaps it's incompatible with the default-merge in some way?
If I change it to the following then it works:
(defn merge* [reconciler state res query]
(println "merge*" res)
(if-let [redirect (:redirect res)]
(om/default-merge reconciler state
(merge res {::compassus/route redirect})
query)
(om/default-merge reconciler state res query)))
@danielstockton if you suspect it's a bug in Compassus, a minimal failing case would be much appreciated!
I suspect it isn't a bug, there is probably a reason why it doesn't work, it just isn't clear to me. If you think that it should work, I can try to create a test case.
I'm still trying to debug a double remote read. From following the earlier conversion, it sounds like the second one must be caused by a transact. Also, didn't know that you can transact! a read, so thanks for that tip.
My parser seems to be called twice in quick succession with target :api (my remote). I have removed all instances of transact! so it can't be that
@anmonteiro hai, I am using compassus and have a question, I want to use route parameters in om.next/IQuery, before going down the rabbit hole 🙂 how is this anticipated using compassus ..
I've been trying to do something like this to prevent the duplicate request:
(defmethod read :totals
[{:keys [state ast target] :as env} key params]
(println "TARGET" target)
(let [st @state
token (get-in st [:current-user :token])
value (get st :totals)]
(when-not (= value :loading)
{:api (if value false (assoc-in ast [:params :token] token))
:value (or value :loading)})))
Not sure if it's the right approach or not, it was inspired by some things in untangled. Anyway, still happens..I have two remotes :api and :login. The read is called twice with :api, :login and nil (6 times in total).
Do links work at the root query level?
i.e. are [:current-user]
and '[[:current-user _]]
equivalent?
When I replace with a link, its nil
@danielstockton links don't make sense at the root level
@deplect hrm, I think you can use them, but I have stayed away from query parameters
They don't make sense no, so I guess it's intentional that they don't work then
Perhaps it would be possible to detect links in the root query and give a warning?
It can be confusing to newcomers if they read about links and decide to try it, then wonder why it isn't working.
I knew it didn't make any sense but at the same time, I didn't see any reason why it wouldn't work either...I had the impression I was doing something wrong
I'm trying it out
@danielstockton hrm actually it seems to just work
cljs.user=> (om/db->tree '[[:x _]] {:x 1} {:x 1})
{:x 1}
hrm ok
think it would make a difference, this being on a compassus wrapper component?
Maybe
I'd be happy to look at a minimal case
@anmonteiro: https://github.com/danielstockton/test started a new oriens project and simply changed :app/title to [:app/title '_]
https://github.com/danielstockton/test/blob/master/src/main/test1/core.cljs#L12
awesome, I'll have a look later
thanks!
Wow, awesome, fixed the duplicate request problem @anmonteiro You should probably update the readme for pushy:
(def history
(pushy/pushy #(compassus/set-route! app (:handler %))
(partial bidi/match-route bidi-routes)))
This isn't good, the update-route!
method that oriens uses is better because it checks (when (not= handler current-route) .. )
I must have been calling set-route! twice without that check
@danielstockton: PR welcome!
We should also probably link to Oriens in the Compassus README
It still isn't perfect. It fixed it for the :index page but it still causes two requests when reloading a page other than :index and I'm not sure how we should deal with that.
Basically, compassus does an initial set-route and pushy/start! causes one too
Triggering two remote reads
Before the app mounts (compassus/current-route app)
is the same as :index
Could we check the URL token in routes somehow and decide the initial current-route based on that?
Nvm, just realised its not :index but ::compassus/route in initial state, i should be able to work something out to set the initial state properly 👍
Solved it by setting my :index-route
to (def index-route (:handler (bidi/match-route bidi-routes (pushy/get-token history))))
.
i.e. index-route depends on the url, it isn't fixed
@anmonteiro trying to wrap my head around “prop. based testing components in compassus app”, you have any snippets I can steal ideas from?
@ag I don't understand why you'd wanna do that
there are no examples available AFAIK
from my perspective, components should be pure functions of data->DOM
Property-based testing will be much more helpful to test your parser for example
there's a neat example in the Wiki about Property-based testing the parser