Re: [ClojureScript] "Unexpected token return" in a case form returning a function

2015-04-03 Thread Elliot Bulmer
Thanks for the quick update. I'll use the map version in the meantime. On Friday, April 3, 2015 at 10:28:08 AM UTC+8, David Nolen wrote: > I created an issue, http://dev.clojure.org/jira/browse/CLJS-1187 - I suspect > the underlying problem is a pretty simple one. > > > > David > > > On Thu,

[ClojureScript] [re-frame] Dealing with handlers that depend on certain changes of state

2015-04-03 Thread Rafał Cieślak
I'm writing a tic-tac-toe game (hot seat, not over the Internet) using re-frame and I'm wondering what's the best approach to handling certain actions that depend on a certain transformations of state. A simple example, if a player clicks on a cell, I have to: A. Change the owner of that cell

Re: [ClojureScript] "Unexpected token return" in a case form returning a function

2015-04-03 Thread David Nolen
Should be fixed in master: https://github.com/clojure/clojurescript/commit/49ed83337baf762ef21a907be234ebdbcc105d66 Will be included in the next release (today ;). David On Thu, Apr 2, 2015 at 9:33 PM, Elliot Bulmer wrote: > I get this error when I try to define a case statement that is return

Re: [ClojureScript] [re-frame] Dealing with handlers that depend on certain changes of state

2015-04-03 Thread Colin Yates
In the infuriating style of answering with not-quite-the-answer ;): Number 2 is more clojure-y as it makes things more self-contained/pure. I would also triple check that the order in which events are dispatched are the order in which they are executed. Dispatch is asynchronous so but it might be

Re: [ClojureScript] [re-frame] Dealing with handlers that depend on certain changes of state

2015-04-03 Thread Rafał Cieślak
> I would also triple check that the order in which events are dispatched are > the order in which they are executed. I was worried about it, too, but re-frame docs explain it quite clear. https://github.com/Day8/re-frame#talking-to-a-server > dispatch will cause a handler function to be called

Re: [ClojureScript] [re-frame] Dealing with handlers that depend on certain changes of state

2015-04-03 Thread Daniel Kersten
The queues are FIFO since it's using core.async under the hood. Obviously if you have things like server putting events on the queue, you can't guarantee order, but relative order (eg doing two dispatches one after another) will be in order. Yeah, I'd probably do with something like: (let [player

Re: [ClojureScript] [re-frame] Dealing with handlers that depend on certain changes of state

2015-04-03 Thread Daniel Kersten
Oops, obviously I meant #(dispatch ...) On Fri, 3 Apr 2015 at 12:53 Daniel Kersten wrote: > The queues are FIFO since it's using core.async under the hood. Obviously > if you have things like server putting events on the queue, you can't > guarantee order, but relative order (eg doing two dispat

Re: [ClojureScript] [re-frame] Dealing with handlers that depend on certain changes of state

2015-04-03 Thread Rafał Cieślak
> That is, have the event control which player it gets applied to. This way the > handler does not need any knowledge of this at all and can use path > middleware to focus in on only what it cares about (the game board, in the > case of selecting a cell). I think it's better to fetch the player

Re: [ClojureScript] [re-frame] Dealing with handlers that depend on certain changes of state

2015-04-03 Thread Daniel Kersten
Right, I see what you mean. I think I need to think about it some more :) On Fri, 3 Apr 2015 at 12:58 Rafał Cieślak wrote: > > That is, have the event control which player it gets applied to. This > way the handler does not need any knowledge of this at all and can use path > middleware to foc

Re: [ClojureScript] [re-frame] Dealing with handlers that depend on certain changes of state

2015-04-03 Thread Colin Yates
Thanks for the clarification - I would still be nervous about relying on the sequencing though as that feels like an implementation detail. I am concerned though about the interpretation of "Why? Partially because handlers are given a snapshot of the app-db and can't be nested.". This is still a l

Re: [ClojureScript] [re-frame] Dealing with handlers that depend on certain changes of state

2015-04-03 Thread Daniel Kersten
The relevant code is here: https://github.com/Day8/re-frame/blob/master/src/re_frame/router.cljs#L30-L36 But yes, unless its specifically stated to be ordered, its probably best to treat it as an implementation detail and not rely on it. Somewhat off topic as it doesn't address Rafal's question:

Re: [ClojureScript] [re-frame] Dealing with handlers that depend on certain changes of state

2015-04-03 Thread Daniel Kersten
So, thinking about this some more: If you treat the system as a state machine and the events as the state transitions (which are performed by the handlers) and the db as the current state (basically as described in the readme), then I think changing the active player in the same handler as placing

Re: [ClojureScript] [re-frame] Dealing with handlers that depend on certain changes of state

2015-04-03 Thread Colin Yates
+0.98 - 0.02 reserved whilst I get comfortable with "complexity in middleware" not falling into the same traps as AOP :). On 3 April 2015 at 15:04, Daniel Kersten wrote: > So, thinking about this some more: > > If you treat the system as a state machine and the events as the state > transitions (

[ClojureScript] Re: [re-frame] Dealing with handlers that depend on certain changes of state

2015-04-03 Thread Michael McLellan
On Friday, April 3, 2015 at 6:36:03 AM UTC-4, Rafał Cieślak wrote: > I'm writing a tic-tac-toe game (hot seat, not over the Internet) using > re-frame and I'm wondering what's the best approach to handling certain > actions that depend on a certain transformations of state. > > A simple example,

Re: [ClojureScript] "Unexpected token return" in a case form returning a function

2015-04-03 Thread Sean Corfield
On Apr 2, 2015, at 7:21 PM, Mike Fikes wrote: > Here you go: > > https://gist.github.com/mfikes/b76ad8576b0357f1b617 > Thanks Mike. So, same bug as outside the `apply` context? > (In case you’d like to try different expressions, I’m just sto

Re: [ClojureScript] "Unexpected token return" in a case form returning a function

2015-04-03 Thread Mike Fikes
Hi Sean, Yes, I believe so. Here are all 3 forms and their emitted JavaScript before and after David's change on master: https://gist.github.com/mfikes/8524482fc84c3c2ad4e0 Hope you can rejoin ClojureScript again soon! Things have improved greatly recently, especially in the area of tooling su

[ClojureScript] re-frame - register-sub has no effect when body uses a let-binding

2015-04-03 Thread Colin Yates
I know I am going insane: (register-sub :add-patient/selected-journey-details-field (fn [db] (reaction (-> [:add-patient/local] subscribe deref :selected-journey-details-field)) #_(let [v (-> [:add-patient/local] subscribe

[ClojureScript] Re: re-frame - register-sub has no effect when body uses a let-binding

2015-04-03 Thread AndyR
reaction is a macro that expands to evaluating the passed forms (here: 'v') within a function (make-reaction). I don't know the internals of Reagent but my guess is that Reagent has to figure out which ratoms were used in that function call. This is done somehow (by maybe some context setting et

Re: [ClojureScript] Re: re-frame - register-sub has no effect when body uses a let-binding

2015-04-03 Thread Colin Yates
My insanity must be worse than I thought because I could swear it was working earlier! On 3 April 2015 at 20:45, AndyR wrote: > reaction is a macro that expands to evaluating the passed forms (here: 'v') > within a function (make-reaction). > I don't know the internals of Reagent but my guess is

[ClojureScript] re-frame/react - controlled input losing key presses

2015-04-03 Thread Colin Yates
Hi, If I use :default-value then the input field keeps up no matter how fast I type. If I use :value then I can lose quite a few key presses if I type really quickly. I expect I probably need to break my components into smaller discrete components, which only depend on the absolute minimum, bu

Re: [ClojureScript] Re: re-frame - register-sub has no effect when body uses a let-binding

2015-04-03 Thread Colin Yates
Here is an example that works and uses a let. I wonder if the reaction inside the let is making it work... (defn- render-one [state-key render-key db] (let [id (-> [:add-patient/tree-state state-key] subscribe deref :selected-ids first

Re: [ClojureScript] Re: re-frame - register-sub has no effect when body uses a let-binding

2015-04-03 Thread AndyR
Yes that's expected. The reaction captures deref's (look at the source of ratom.cljs and search for "capture"). So as long as you deref in your reaction block you'll be fine. I'm not an expert on the reagent inner workings so I hope other correct me if I'm wrong :) On Friday, April 3, 2015 at 5

[ClojureScript] re-frame: how to create dependent handlers and run them without delay

2015-04-03 Thread Karsten Schmidt
I've been really enjoying my last month working on a largish app based on re-frame and not run into any probs. However, today I was going to refactor another project using animation and came across an issue which I'm somewhat stumped by: I created a global tick handler, which is supposed to be an

Re: [ClojureScript] Re: re-frame - register-sub has no effect when body uses a let-binding

2015-04-03 Thread Colin Yates
I see - thanks Andy. It is all magic until it clicks :) Sent from my iPhone > On 3 Apr 2015, at 22:45, AndyR wrote: > > Yes that's expected. The reaction captures deref's (look at the source of > ratom.cljs and search for "capture"). So as long as you deref in your > reaction block you'll be

[ClojureScript] Re: re-frame/react - controlled input losing key presses

2015-04-03 Thread AndyR
On Friday, April 3, 2015 at 5:25:24 PM UTC-4, Colin Yates wrote: > Hi, > > If I use :default-value then the input field keeps up no matter how fast I > type. If I use :value then I can lose quite a few key presses if I type > really quickly. > > I expect I probably need to break my components i

Re: [ClojureScript] Re: re-frame/react - controlled input losing key presses

2015-04-03 Thread Colin Yates
The reason I want it controlled is because I need to change the state the input is bound to via another mechanism. If an entity is recognised then I show a "do you want to load the existing user" for example. If they chose to then the atom is updated but not the Input field (with default-value).

Re: [ClojureScript] re-frame: how to create dependent handlers and run them without delay

2015-04-03 Thread Daniel Kersten
Have you tried using dispatch-sync? https://github.com/Day8/re-frame/wiki/Bootstrap-An-Application#a-cheat and https://github.com/Day8/re-frame/blob/master/src/re_frame/router.cljs#L54 On Fri, 3 Apr 2015 at 22:50 Karsten Schmidt wrote: > I've been really enjoying my last month working on a largi

[ClojureScript] [ANN] cljs-pikaday, a reagent date picker

2015-04-03 Thread Tim Gilbert
Hi all... I have just released cljs-pikaday, which is a ClojureScript interface to the Pikaday javascript date-picker. https://github.com/timgilbert/cljs-pikaday/ It's a pretty simple little library in its early stages. Right now there's just a reagent interface where you can pass an atom into

Re: [ClojureScript] Re: re-frame/react - controlled input losing key presses

2015-04-03 Thread Andre Rauh
Other than resorting to more manual steps: One easy "hack" is to just change the ^{:key "..."} meta attribute of your [:input ]. This will unmount and re-mount it and re-populate the :default-value. On Fri, Apr 3, 2015 at 5:59 PM, Colin Yates wrote: > The reason I want it controlled is because I

Re: [ClojureScript] re-frame: how to create dependent handlers and run them without delay

2015-04-03 Thread Karsten Schmidt
Thanks, Daniel. Didn't know about `dispatch-sync` and this would definitely help to avoid the delay, but the fundamental question to me still is how to create reactions to handler changes *outside* reagent components. I'm not sure if re-frame or reagent actually supports this at all. AFAIK `(subsc

Re: [ClojureScript] re-frame: how to create dependent handlers and run them without delay

2015-04-03 Thread Karsten Schmidt
After hours of fiddling around with this and studying the reagent source I came up with this solution using watches: (defn register-reactive "Registers an handler which will be automatically triggered when value at given path in app-db has changed. The new handler will be provided with the n

Re: [ClojureScript] re-frame: how to create dependent handlers and run them without delay

2015-04-03 Thread Mike Thompson
On Saturday, April 4, 2015 at 9:51:07 AM UTC+11, Karsten Schmidt wrote: > Thanks, Daniel. Didn't know about `dispatch-sync` and this would > definitely help to avoid the delay, but the fundamental question to me > still is how to create reactions to handler changes *outside* reagent > components. I

Re: [ClojureScript] re-frame: how to create dependent handlers and run them without delay

2015-04-03 Thread Mike Thompson
On Saturday, April 4, 2015 at 9:07:56 AM UTC+11, Daniel Kersten wrote: > Have you tried using dispatch-sync?  > https://github.com/Day8/re-frame/wiki/Bootstrap-An-Application#a-cheat and  > https://github.com/Day8/re-frame/blob/master/src/re_frame/router.cljs#L54 "dispatch-sync" should never be c

[ClojureScript] reagent canvas updates

2015-04-03 Thread Karsten Schmidt
Hi all, is this component below an idiomatic approach to deal with canvas animations in reagent? I tried googling, but couldn't *any* examples (which I find hard to believe): (defn test-canvas "Creates animated clock based on seconds only." [] (reagent/create-class {:component-did-mount

Re: [ClojureScript] re-frame: how to create dependent handlers and run them without delay

2015-04-03 Thread Karsten Schmidt
Thanks, Mike! Trees and forests... So obvious, I didn't/couldn't think of it! :) Btw. In my above example, dispatch-sync works fine (at least for the physics part), since that is using internally mutable types... but of course, the approach would fail for immutable CLJS data structures. On 4 Apri

Re: [ClojureScript] [re-frame] Dealing with handlers that depend on certain changes of state

2015-04-03 Thread Mike Thompson
On Friday, April 3, 2015 at 11:29:35 PM UTC+11, Colin Yates wrote: > Thanks for the clarification - I would still be nervous about relying > on the sequencing though as that feels like an implementation detail. > > I am concerned though about the interpretation of "Why? Partially > because handler