Fork me on GitHub

@kenny I'm not aware of a way to keep local state


I imagine there is probably a way to get it to work. Often times I have cases that really seem like they are so isolated. This causes me to ask myself "why pollute the global state with this?" Perhaps this is flawed thinking. Though, I cannot see myself running into any issues down the road with this.


The conclusion I've come to: the more state is in one place the better


The moment we start to distribute state ... there are complications


Now, sometimes distributed state is unavoidable. So we live with it.


But if you can avoid it ... do


That's where my thinking is at these days (I always reserve the right to completely change my mind :-))


So I wouldn't be thinking that you were "polluting global state". I'd control where you put this state within app-db, sure. But it's okay for it to go centrally.


Out of curiosity, what are the complications that you have ran into? It seems like local state in an entirely independent component would be ok. This would give the user of this component one less thing to manage.


^ for me, the complications comes when I need to so something with that local state in another component... you never know what pieces of state the next feature your client wants will need. I find it easier to have everything in one place too.


if i wanted to redirect to another page after a :login event gets handled successfully, whats the standard way of doing it in re-frame?


in vanilla react, I would check in componentWillRecieveProps to see if the new props show that the user is now logged and then dispatch the redirect


I could do something similar in re-frame with it's form-3 components, but I'm wondering if im missing something simpler


@yedi in plain react way, I will not have a check in componentWillRecieveProps. On click of Login --> Make Ajax request --> Check for success/failure --> if Failure, then update props (you can update db and then subscribe) --> if success, then route to another URL (do the same in re-frame)


thanks @rnagpal im attempting something lik ethat


so i'm returing this effect dict in my event handler

{:dispatch-n (list [:status :login :success]
                       [:set-user user]
                       (when redirect-to [:change-url redirect-to]))}


which ends up looking like this: ([:status :login :success] [:set-user {...}] nil)


but I get this error: re-frame: you called "dispatch" without an event vector.


but I thought you were allowed to have nil values in a dispatch-n list


i got it to work by changing the code to:

  (fn [{:keys [db]} [_ redirect-to user]]
    (let [dispatch-list (list [:status :login :success]
                              [:set-user user])]
      {:dispatch-n (if redirect-to (conj dispatch-list [:url-change redirect-to]) dispatch-list)})))


but appears that docs were incorrect about dispatch-n ignoring nil values