Fork me on GitHub
#reagent
<
2018-08-15
>
abdullahibra09:08:36

guys when i define a route with secretary within reagent app, when reload the page i got page not found why?

jjfine14:08:35

is your backend is serving your js and executing it for that route?

athomasoriginal19:08:08

Hey all, I have seen this pattern, only once, but I wanted to get opinions on it: Example 1

(defn form-3-component
  [props]
  (let [state (atom {:list [] :contacts []})
         on-click! (fn [] (reset! @atom []))]))  <--- take note of this
Example 2
(defn delete-list-items 
  [list-state]
  (reset! @list-state []))

(defn form-3-component
  [props]
  (let [state (atom {:list [] :contacts []})
         on-click! delete-list-items]   <--- extracted the function from example 1 and brought it outside the component
    ;; lots of stuff happening
    (on-click! (:list @state))))
So the idea is, to extract event-handlers, or functions that manipulate state, from the container component (form-3) itself. Has anyone seen this pattern used in the wild or think there can be benefits in some situations? This pattern never really comes up in React applications, but I thought maybe there is some idiom in clojure which makes this make sense?

lilactown21:08:11

I was a bit confused at first. I think that's a form-2, not a form-3 component

lilactown22:08:19

and I think that's mostly fine. you'd actually pass in the whole state atom into delete-list-items, and I would usually bind the on-click! to the state when you create the atom

lilactown22:08:58

(defn delete-list-items 
  [state]
  (swap! state assoc :list []))

(defn form-2-component
  [props]
  (let [state (atom {:list [] :contacts []})
         on-click! #(delete-list-items state)]
    ;; ...
    [:button {:on-click on-click!} "Delete list"]))

polymeris22:08:15

I don't think you should deref the atom in reset!... also the arity is wrong, I belive

polymeris22:08:38

Maybe you want (swap! state assoc :list [])

👍 4