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

Adding index as a parameter to f when using build-all #890

Open
slipset opened this issue Sep 5, 2017 · 1 comment
Open

Adding index as a parameter to f when using build-all #890

slipset opened this issue Sep 5, 2017 · 1 comment

Comments

@slipset
Copy link

slipset commented Sep 5, 2017

Problem statement:

I have a list of items that I want to output in a table. Before each item, I want to output the rank of the item:

| 1 | First item       |
| 2 | Second item |

To do this I use code along these lines:

(om/build-all display-row rows  {:key :id})

Looking at the source-code,
I see that build-all uses map with an index (why not map-indexed?),
but that index (::index) is lost on the way down to my display-row function.

The only way I've managed to get a hold of the index is by the way of the following code:

(aget (aget owner "props") "__om_index")

which seems a bit hackish to me.

Proposed solution:
Add a :index keyword to the opts map for a component which contains the current index if the component is built using build-all

@wilkerlucio
Copy link
Contributor

@slipset seems like you are still the old Om. I recommend you try to do something using build instead of build-all, I believe you can do the same my doing a map yourself, and with your custom map you can send the :index down as you want, like:

(map-indexed #(om/build display-row (assoc %2 :index %1) rows)

I'm pretty the old Om is not being maintened anymore, so it's unlikely new changes get on it.

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

No branches or pull requests

2 participants