Fork me on GitHub
#re-frame
<
2016-04-20
>
dragoncube02:04:27

would one more C computation triggered in such case?

mikethompson02:04:49

Short answer: yes. Longer answer: this is about ordering ...

mikethompson02:04:12

In a perfect world, all necessary A and B computation is done before C

mikethompson02:04:33

But it is possible that A might be done, then C. Then B, then C again.

mikethompson02:04:20

So, yes, it is possible that C might be done twice. But more importantly, it means that C might be recomputed with a "glitch" - A is updated, but B is not.

mikethompson02:04:18

Of course, in the vast majority of cases this is simply not an issue. BUT if you have a C which depends on two dependent inputs, then you need to at least be aware of this.

richiardiandrea04:04:52

I have a had a hard question for me to answer today: why it is wrong to dispatch inside a subscription? It feels wrong to me but why? Is it that wrong? I could not come up with an answer. The use case is pagination: the code to review subscribed to :page in app-db and it was triggering a network call with the new page. Then another part was subscribing (inside the same subscritpion) to the data in order to "wait" for the call to succeed

josh.freckleton04:04:25

Has anyone here used re-frame+ReactNative? In production? How performant? Would you recommend it?

mccraigmccraig07:04:39

@mikethompson: so (continuing with C depending on A & B), what i was observing was more than just an ordering problem - (i don't understand the problem yet, but it behaved as if) C ran after A was updated, but the dependency on B was never observed - so when B later updated C was not re-run... making C explicitly deref B whatever the content of A fixes the problem

mikethompson08:04:50

@richiardiandrea: yeah, something is wrong if you are dispatching inside of subscriptions because it means you want to "change the world" from within a subscription. Subscriptions facilitate the transfer of the state, they never try to change it. Only events change the world (their handlers actually). So, instead, figure out what event (button press, mouse click, websocket update, etc) is the trigger for this update. That's the change-the-world moment (event handler), not subscription which just simply transports state.

afhammad10:04:51

I need to trigger a dispatch when a subscription changes since the dispatch needs the changed value. Doing it in the let of a Form-2 isn’t an option since that only gets called once and at the time the value it nil. I’m currently doing it within the component’s fn with some checks to avoid multiple dispatches but obviously thats not ideal. Whats the best way of handling this?

danielcompton12:04:25

@afhammad: take a look at https://github.com/Day8/re-frame/wiki/Subscribing-To-A-Database. You probably don’t want to be dispatching inside a subscription (see above for discussion about this)

danielcompton12:04:09

The question you need to answer is “What is the source of change that is triggering me wanting to dispatch?”, and put your dispatch at that point. Subscriptions don’t change anything, they only reflect the state that already exists in app-db. So wherever app-db is being changed, that’s where your dispatch should go.

afhammad12:04:45

@danielcompton: hmm I see, in this particular case the source of change is the router, i guess I may need an intermediary “controller” to handle these dispatches so that my router doesn’t get messy

danielcompton12:04:29

I’m not too familiar with using re-frame with a router so I can’t be too much help there, but that sounds about right.

afhammad12:04:01

Yeh it makes sense. I’ll read the wiki page first though. Thanks

nberger12:04:38

@afhammad: in our app, we dispatch an event from the router, and then that event handler has this "controller" in the form of a multimethod. By default it just saves the current route in the db (to use it later) but for some routes it does additional updates in the db or dispatches other events

afhammad12:04:36

Thats helpful, thanks @nberger.

richiardiandrea15:04:20

@mikethompson: thanks that was my instinct as well, thanks for confirming it...any performance issue I can point to?

fenton15:04:12

what I percieved as a lack of reloading/refreshing on clicking the browser reload button was in fact something entirely different. I'm using boot for clojurescript development. I used (enable-console-print!) followed by (println "blah") statements. These fail to run on browser refresh/reload. Quite unexpected behaviour. Otherwise they run fine. Anyway, am now switching over to cljs-console which is better anyway.

fenton15:04:37

Lesson learned: DONT have (enable-console-print) be in any tutorials anywhere anymore...

afhammad15:04:06

@fenton: i’ve never experienced that with lein, must be a boot thing?

martinklepsch15:04:28

@fenton: I don't think this is specific to boot or leiningen. Also using enable-console-print! is just fine. I guess you removed it from a file that still had a println? (`enable-console-print!` is a per namespace thing)

fenton15:04:18

@martinklepsch: no confirmed it with another programmer too... its just the reload/refresh of browser that causes the issue...other times it works ok.

fenton15:04:52

if i reload browser, nothing prints, if i update the file, it all prints just fine.

martinklepsch15:04:31

that is not printing "test" when the page is reloaded?

fenton16:04:12

hmm: boot dev gives me an error on going to localhost:3000 Uncaught TypeError: Cannot read property 'appendChild' of null

martinklepsch16:04:55

hm, that works for me. Did you check the output of boot dev for warnings/other issues? (maybe you're serving something else on 3000?

fenton16:04:09

@martinklepsch: okay leave with me for now, I'll try to find what part of my project is causing this.

martinklepsch16:04:37

@fenton: is this still the appendChild error?

fenton16:04:53

no error is gone when i re-ran boot dev

martinklepsch16:04:05

so you see "test"? simple_smile

fenton16:04:28

even on reload

richiardiandrea16:04:05

I had the same problem in btw

fenton18:04:00

@martinklepsch: created a pull request that demos the bug...basically move println into init function and add cljs-repl functionality

martinklepsch19:04:18

@fenton: thanks, repro case always helps a lot.