Fork me on GitHub
#re-frame
<
2016-09-26
>
andre08:09:48

btw, did someone try it? is it work? 🙂

kalouantonis09:09:47

By the way you made a typo in your description, it should be: >>> Visualize re-frame pattern data in your re-frame apps as a tree structure.

kalouantonis09:09:54

@andre: I get this error trying to compile my app with re-frisk

Invalid :refer, var re-frame.core/def-sub does not exist in file app/resources/js/compiled/dev/re_frisk/core.cljs

kalouantonis10:09:15

I’m using re-frame 0.8.0 and reagent 0.6.0

andre10:09:35

yes have same error

kalouantonis10:09:01

Its (reg-sub :name (fn [db _] …)) in 0.8.0

robewald10:09:34

@shaun-mahood Thanks. Some might read this as a non-answer, but it assures me that I am not missing something obvious.

kalouantonis10:09:35

I think its the same for 0.7.x

andre10:09:47

is where some technics to support different versions?

andre10:09:27

how can i support def-sub and reg-sub?

kalouantonis10:09:50

I’m actually not sure. def-sub is a macro, right?

andre10:09:31

no there are no macro in the re-frame

kalouantonis10:09:06

You could always check if the symbol is defined, like (find-var ‘re-frame.core/def-sub), but I’m not sure if thats necessarily a good idea

kalouantonis10:09:07

I think this is quite a general question anyway, its not just clojure libraries that have this issue.

kalouantonis10:09:31

I’d just create a new release for 0.8.0

kalouantonis10:09:01

So, you have 0.1.2, I’d do something like 0.2.0 supports reframe 0.7.x and upwards

andre10:09:58

i think it was my mistake to use alpha version of re-frame

andre10:09:15

now i think i can support only reg-sub

andre10:09:20

thank you

andre10:09:56

@kalouantonis you can try 0.1.3

kalouantonis10:09:46

Well, that was quick

kalouantonis10:09:59

I wish I could release my apps that fast 😄

kalouantonis10:09:57

Its compiling now, but I’m not seeing anything on the UI:

(defonce debug-setup!
  (do (when config/debug?
        (enable-console-print!)
        (enable-re-frisk!)
        (devtools/install!))))

kalouantonis10:09:01

Ah, never mind, I had to set {:x 200 :y 200}

andre10:09:27

why it wasn't visible in 0,0 ?

kalouantonis10:09:51

Probably because I have a navbar in the way

kalouantonis10:09:23

This is actually really cool. I had to always do (require ‘[re-frame.db :refer [app-db]]) @app-db before

kalouantonis10:09:35

I can’t scroll though, are you planning on adding that?

kalouantonis10:09:13

Also, is re-frisk meant to be emitting console output like "Emit: " 0 :contract ([:app-db])?

andre10:09:59

i'm using https://github.com/Odinodin/data-frisk-reagent lib for showing data, and it emitting console, I'll think about what to do

andre10:09:44

you should be able to scroll, hm

kalouantonis10:09:16

I can scroll horizontally, but not vertically

andre10:09:20

i've tested in all browsers, and both scrolls work

kalouantonis10:09:50

Perhaps its because of the way I have my page configured. It may also be that I’m running it in electron?

andre10:09:27

what happen then you open more data? does window resize? try to resize window before expand data

andre10:09:16

or try to provide :height

andre10:09:39

yes maybe it works not user friendly now

kalouantonis10:09:03

Yea, :height fixes it

andre10:09:40

thank you for your help!! i'll try to improve ui later

kalouantonis10:09:39

One last question. I include re-frisk as only a dev dependency, but I’m supposed to define my views using def-view. What happens when I’m building for production? def-view won’t be available any more

andre10:09:22

good question 🙂

andre10:09:28

I made an option in the compiler for this purpose, in production without this option def-view just generate defn without any re-frisk code

andre10:09:12

But I know that it may cause not to use re-frisk def-view

kalouantonis10:09:37

But if I have it in

:profiles
  {:dev {:dependencies [[com.cemerick/piggieback "0.2.1"]
                        [figwheel-sidecar "0.5.0-2"]
                        [re-frisk "0.1.3"]]
         :source-paths ["src/clj" "src/cljs" "dev"]}}
doesn’t that mean that the entire re-frisk dependency will be removed when building in production mode?

andre10:09:49

yes it will not compile without dependency

andre10:09:23

you can use it, but without def-view

kalouantonis10:09:10

Ok, great. Thanks

andre11:09:44

or you can use it in the project :dependencies and provide compiler option only for dev profile, thank you for your help.

Niclas12:09:54

Is it possible sending multiple dispatches in one single reg-event-fx handler? Ex:

{:db (do something)
 :dispatch [:my-first-event :my-second-event]}

reefersleep12:09:23

@looveh: I think you're looking for the dispatch-n fn

kalouantonis12:09:36

Yes:

{:db (do-something)
 :dispatch-n (list [:my-first-event] [:my-second-event])}

Niclas12:09:58

@reefersleep @kalouantonis Yes that’s it, thank you!

shaun-mahood22:09:15

@mikethompson: I just tried out day8.re-frame.http-fx for the first time, in the readme it says that :response-format is optional. When I leave it out of my map, I get an error from router.cljs of "unrecognied response format: nil" - is this just a problem with the readme or something else?

mikethompson23:09:54

@shaun-mahood I think that's a problem with the README. @superstructor mentioned something similar previously

mikethompson23:09:36

We will have a look at fixing that.

superstructor23:09:26

yep you need to provide a response format fn

superstructor23:09:36

my bad for not submitting that change yet 😞

superstructor23:09:50

we do something like this, which is kind of specialised to our use case:

(defn maybe-empty-json-response-format
  "Returns a JSON response format.  Options include
   :keywords? Returns the keys as keywords
   :prefix A prefix that needs to be stripped off.  This is to
   combat JSON hijacking.  If you're using JSON with GET request,
   you should think about using this.
   
   

   This is identical to cljs-ajax's `json-response-format`  except
   that it permits empty/null values as valid entities regardless of
   response status code, allowing such things as 200 OK with no entity
   body (instead of strictly expecting 204 (No Content))."
  ([] (maybe-empty-json-response-format {}))
  ([{:keys [prefix keywords? raw]}]
   (ajax/map->ResponseFormat
     {:read (fn [xhrio]
              (let [body (ajax.protocols/-body xhrio)]
                (if (empty? (cstr/trim (or body "")))
                  {}
                  (let [text (ajax/strip-prefix prefix body)
                        json (goog-json/parse text)]
                    (if raw
                      json
                      (js->clj json :keywordize-keys keywords?))))))
      :description (str "JSON"
                     (if prefix (str " prefix '" prefix "'"))
                     (if keywords? " keywordize"))
      :content-type ["application/json", "application/hal+json"]})))

superstructor23:09:29

then in xhrio options we do :response-format (maybe-empty-json-response-format)

superstructor23:09:22

I’ve been saying I’ll get around to this for a long time so happy to do a pull request today @mikethompson only question would be would you want all of the above esp regarding: - the support for empty bodies in 200 OKs - the support for prefix stripping / anti JSON hijacking - the hal+json content type support ? (probably not?)

mikethompson23:09:19

The more information the better, I think

mikethompson23:09:33

(Which is very open ended of me, i know)

superstructor23:09:41

you want this purely in the README or do you want to provide a default JSON response format fn impl ?

mikethompson23:09:45

How much variation do you think there will be in terms of needs?

mikethompson23:09:55

If quite some variation, we could go Wiki

mikethompson23:09:05

Making it easy to add further variation?

mikethompson23:09:35

Let me put it this way ... which way would have made more sense for you and @shaun-mahood?

superstructor23:09:21

Having a default would be a nice convenience in my opinion

superstructor23:09:23

I can see at least 3 variations in the above example (empty body on 200 OK, prefix stripping and hal+json)

superstructor23:09:57

I would suggest parameterizing the first two and omitting hal+json but allowing overriding content types as another parameter

mikethompson23:09:00

You have a better diea about this stuff than I ... so I'm very happy to go with whatever you think

superstructor23:09:51

I think something like that would get most people up and running with JSON-based APIs more quickly.

mikethompson23:09:08

That would be terrific, thanks.

superstructor23:09:45

Otherwise we found we had to delve deep into cljs-ajax to work out how response format fns work, which is feasible, but not ideal to be thinking about all that when all you want is a response map in your handler