Fork me on GitHub
#re-frame
<
2017-08-31
>
deg08:08:19

I've started using this shorthand for most of my subs. Does this make sense as something to add to re-frame, or is it just noise? (FWIW, I'm not crazy about the sub2 name I chose):

(defn sub2
  "Shorthand for simple 'layer 2` usage of re-sub"
  [key db-path]
  (re-frame/reg-sub
   key
   (fn [db _] (get-in db db-path))))

(sub2 :page     [:page])
(sub2 :user     [:user])
(sub2 :uid      [:user :uid])
...

kasuko16:09:30

One thing to be mindful of is that this makes it real easy to make a subscription that just returns data from the app-db. Which if used correctly is fine. Though I could see this leading to an incline to make a simple subscription and then do more data manipulation in a view.

stvnmllr220:09:54

sub-path might be a good name?

sandbags09:08:12

I have a similar method reg-path-sub in most of my projects for simple subscriptions

danielneal09:08:37

Hey, I don't know if anyone can help with this, but I"m going a bit crazy trying to figure out what's wrong. I'm using re-frame test to test my react native app, and getting the following error:

e),c.call(null,b,this.queue),d=cljs.core.next.call(null,e),e=null,f=0),g=0;else return null};re_frame.router.EventQueue.prototype.re_frame$router$IEventQueue$_exception$arity$2=function(a,b){this.queue=re_frame.interop.empty_queue;throw b;};

sandbags09:08:37

I think you may need to give just a tiny bit more context @danieleneal

sandbags09:08:03

(also remember snippets (use the '+' button <---))

danielneal09:08:37

It's a bit involved

danielneal09:08:41

so I've got a react native app, which I'm testing with reframe test

danielneal09:08:02

recently, I've needed to add assets to the app - pictures, fonts etc

danielneal09:08:17

this is done with (js/require "<asset-path>") calls

danielneal09:08:53

however then my tests (which are running on node) complained, because require works differently in that context ->

<asset-path> is not a module

danielneal09:08:09

So I can get rid of these asset requires by monkey patching require, adding a bit of js before the app gets loaded

sandbags09:08:18

if you take re-frame-test out of the equation everything works fine?

danielneal09:08:26

Yeah, my app is fine

danielneal09:08:44

even the tests run ok, but something breaks right at the end and dumps the message above

danielneal09:08:25

I think my understanding is a bit lacking - I guess there's a lot of asynchronous stuff going on with re-frame test - snapshotting state, restoring it etc

danielneal09:08:24

are you using re-frame-test?

sandbags09:08:22

to the extent i might be able to help you it would only be in pointing out that kind of assumption that it's easy to make and then miss later when you're tired and stressed 🙂

danielneal09:08:15

ah yeah, those "can't see the wood for the trees" errors...

sandbags09:08:11

but it does look like re-frame-test is doing some funky stuff with asynchrony

sandbags09:08:27

is it expecting to be in a node environment?

danielneal09:08:50

I don't think it is expecting to be, but I think it should be able to work there

sandbags09:08:23

actually the CLJS line is simpler, it looks like the CLJ line is having to work hard to pretend to be a single-threaded environment 🙂

danielneal09:08:25

it has been so far - I've just separated my react-native bits from the handlers and subs, and testing the handlers and subs (which is where my mistakes always are)

sandbags09:08:24

well i got nuthin

danielneal09:08:40

a problem shared is a problem halved

sandbags09:08:42

this code is too complex for me to grok at a glance and i've not used it so I doubt i will be of much help to you

danielneal09:08:44

now I have half a problem 😄

sandbags09:08:54

hopefully not the insoluable half

danielneal09:08:17

gonna try a different tack I think...

sandbags11:08:33

I updated re-frame from 0.9.4 to 0.10.1 (also CLJS) and now I seem to be getting an error "Uncaught TypeError: goog.net.jsloader.load is not a function" from inside FigWheel but lein ancient says I am all up to date. Anyone seen this?

sandbags11:08:41

okay so apparently lein ancient doesn't deal with plugins

kah0ona15:08:35

sidenote really digging this two-layered subscriptions with an ‘extractor function’ and a ‘computation fn’.

kah0ona15:08:47

as you were 😉

sandbags16:08:56

@kah0ona maybe i don't recognise your terminology but what's that?

sandbags16:08:27

do you just mean having one sub depend upon another with the first pulling from a key-path and the second computing on it? or it is something more?

genekim17:08:10

Hello, all! Holy cow, I think re-frame is amazing — I’ve been using it for a week on my first cljs project, rewriting an app that I had written originally in TypeScript/React. I haven’t had this much fun programming in years! I’m amazed at how quickly things have come together (with the exception of hours spent trying to get closure compiler builds w/externs going.) I’m struggling with trying to understand why some re-frame/reg-event-fx :http-xhrio calls always call :on-failure. Looking at TypeScript version and server logs show that it’s returning 200 status code… Am I missing something obvious here? Many things in advance!

(re-frame/reg-event-fx
  :send-scribename
  (fn [{:keys [db]} _]
    {
     :dispatch   [:send-hashtag-ajax-sent]
     :http-xhrio {:method          :post
                  :uri             "/scribe"
                  :params          {:text (:scribename-text db)}
                  :timeout         5000
                  :format          (ajax/json-request-format)
                  :response-format (ajax/json-response-format {:keywords? true})
                  :on-success      [:send-tweet-success]
                  :on-failure      [:send-tweet-failure]}}))
Thanks in advance!

genekim17:08:59

(in short, the ajax call always calls the :send-tweet-failure handler, seemingly regardless of the return code sent by the server. Am I doing something wrong in the code above? Thx!)

genekim18:08:12

..and I’m even forcing the node.js server to always return res.status(200).send('success! changed scribe!'); Which means that it can only be return status code 200 — and yet :on-failure is the what’s being called in my cljs client… 😕

genekim18:08:23

Oh… Looking at re-frisk (which is a freaking technical miracle, IMHO), and saw this rather surprising result… Clearly, I’m doing something wrong in processing the return result…

genekim18:08:38

Solved the issue… My server code was returning a string, not a JSON object. Fixed with this:

res.status(200).send({ text: "success! changed scribe!");
Neat!

genekim18:08:13

PS: holy cow. Being able to see all the events in re-frisk is gobsmackingly awesome. Incredible…

kah0ona19:08:06

@sandbags yes that is what i meant. Im currently refactoring some old reframe code that started out on wrong foot. Now everything is so much cleaner

kah0ona19:08:26

The terminology might be a bit made up by me indeed :-)

leontalbot20:08:23

That is what I do