Fork me on GitHub
#om
<
2016-12-13
>
tony.kay03:12:29

@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.

eric.shao03:12:19

@tony.kay Mr Kay,Thank you for your reply,and thank for your tutorials and videos.I am studying on them.Thx!

danielstockton09:12:51

@anmonteiro @jonsmock

(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...

danielstockton09:12:05

Perhaps it's incompatible with the default-merge in some way?

danielstockton09:12:19

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)))

anmonteiro09:12:10

@danielstockton if you suspect it's a bug in Compassus, a minimal failing case would be much appreciated!

danielstockton10:12:19

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.

danielstockton10:12:41

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.

danielstockton10:12:48

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

deplect10:12:03

@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 ..

danielstockton10:12:05

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..

danielstockton10:12:28

I have two remotes :api and :login. The read is called twice with :api, :login and nil (6 times in total).

danielstockton10:12:27

Do links work at the root query level?

danielstockton10:12:07

i.e. are [:current-user] and '[[:current-user _]] equivalent?

danielstockton10:12:26

When I replace with a link, its nil

anmonteiro10:12:22

@danielstockton links don't make sense at the root level

anmonteiro10:12:42

@deplect hrm, I think you can use them, but I have stayed away from query parameters

danielstockton10:12:04

They don't make sense no, so I guess it's intentional that they don't work then

danielstockton10:12:45

Perhaps it would be possible to detect links in the root query and give a warning?

danielstockton10:12:59

It can be confusing to newcomers if they read about links and decide to try it, then wonder why it isn't working.

danielstockton10:12:47

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

anmonteiro10:12:44

I'm trying it out

anmonteiro10:12:30

@danielstockton hrm actually it seems to just work

anmonteiro10:12:46

cljs.user=> (om/db->tree '[[:x _]] {:x 1} {:x 1})
{:x 1}

danielstockton10:12:03

think it would make a difference, this being on a compassus wrapper component?

anmonteiro11:12:09

I'd be happy to look at a minimal case

danielstockton11:12:06

@anmonteiro: https://github.com/danielstockton/test started a new oriens project and simply changed :app/title to [:app/title '_]

anmonteiro11:12:51

awesome, I'll have a look later

danielstockton12:12:47

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) .. )

danielstockton12:12:41

I must have been calling set-route! twice without that check

anmonteiro12:12:26

We should also probably link to Oriens in the Compassus README

danielstockton14:12:46

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.

danielstockton14:12:41

Basically, compassus does an initial set-route and pushy/start! causes one too

danielstockton14:12:47

Triggering two remote reads

danielstockton14:12:01

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?

danielstockton14:12:59

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 👍

danielstockton14:12:12

Solved it by setting my :index-route to (def index-route (:handler (bidi/match-route bidi-routes (pushy/get-token history)))).

danielstockton14:12:51

i.e. index-route depends on the url, it isn't fixed

ag19:12:27

@anmonteiro trying to wrap my head around “prop. based testing components in compassus app”, you have any snippets I can steal ideas from?

anmonteiro20:12:24

@ag I don't understand why you'd wanna do that

anmonteiro20:12:31

there are no examples available AFAIK

anmonteiro20:12:47

from my perspective, components should be pure functions of data->DOM

anmonteiro20:12:02

Property-based testing will be much more helpful to test your parser for example

ag20:12:42

ehm, mkay… I think I need to read om’s official wiki page more thoroughly on that matter

anmonteiro20:12:13

there's a neat example in the Wiki about Property-based testing the parser