Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle sequences in hiccup like hiccup does #186

Closed
wants to merge 3 commits into from

Conversation

timothypratley
Copy link

Splices in sequences so you don't need to write syntax to do it:

[:div
   [:h2 "Seq of divs without ids"]
   (for [i (range 3)]
     [:div (str "A" i)])

   [:h2 "Nested sequences"]
   (for [i (range 3)]
     [:div
      (for [j (range 3)]
        [:div (str "G" i j)])])

   [:h2 "Sequence of divs"]
   '([:div "D0"] [:div "D1"])
   [[:div "D2"] [:div "D3"]]]

Here is an example where the (into) (concat) are just noise:

(defn draw-graph [drawable mutable-graph force-layout]
  (let [{:keys [nodes paths]} @drawable]
    (into
     [:svg 
      (concat
       (for [path paths]
         [blink path mutable-graph force-layout nodes])
       (for [[node idx] (map vector nodes (range))
             :when (not (vector? (:id node)))]
         [bnode node idx mutable-graph force-layout])))))

Related discussion:
r0man/sablono#40

Hiccup ignores the extra list generated, so this change would be both more convenient, and closer to the behavior of hiccup.

@mainej
Copy link
Contributor

mainej commented Sep 12, 2015

👍 for splicing in sequences

@snoe
Copy link

snoe commented Sep 13, 2015

👍

@GetContented
Copy link

This may bring in subtle issues around collision of keys when we're needing to uniquely key items in a for or map. So long as we "namespace" our keys - so to speak - there shouldn't be any issue. (ie write ^{:key (str "some-name" id)} rather than ^{:key id}) - assuming id is our unique identifier here.

@holmsand
Copy link
Contributor

holmsand commented Nov 3, 2015

While I agree that it would be nice to not have to supply keys, this patch would change the performance characteristics of Reagent fundamentally.

React uses the key attribute to avoid re-rendering of components when their order changes (see for example https://facebook.github.io/react/docs/multiple-components.html). React uses arrays to signal that a bunch of components are "dynamic", and so can be re-ordered – in Reagent we use seqs for the same thing.

We could generate keys automagically when they're not present – that would get rid of the warnings from React. But then it would be very easy to forget the keys, and very hard to tell if you have keys in the right place. I still think it is better to warn about missing keys always, even if it is slightly less convenient...

@timothypratley
Copy link
Author

Yeah this is a bad idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants