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
added: Support to disable named elements on loops #1806
Conversation
This looks good, I like the idea of it being optional. I almost lean toward holding off for v3 and make the named elements an option rather than the default, curious about what others think. |
@imagentleman thanks for your patch but here I get slowly the impression we are patching the issue instead of fixing it. I will refactor the loop rendering in riot 3.0.0 and the current version without my new implementation runs already a bit faster https://plnkr.co/edit/FPOPNLVXoXaIr9LnaRVj?p=preview |
To be honest, I never liked the automatic access when using |
I also do not really like the feature as it is, even if it is sometimes quite handy. I would prefer named elements binding to be optional by default. How about a something like |
I would suggest something like how the React world do it, using ref="my-unique-name" |
@GianlucaGuarini sure, I'll try that 😉 |
A list should be kept about breaking changes like this one, so update will On Fri, Jun 24, 2016 at 4:51 PM, Tsutomu Kawamura notifications@github.com
|
I also like the idea of changing it to |
@cognitom https://facebook.github.io/react/docs/more-about-refs.html#the-ref-callback-attribute I suppose from React it would be more like ref="{ checkboxes }" where checkboxes would be an array defined on the instance? So when mounted it would automatically add a reference to itself.
Perhaps? Where the reference would be to the Tag, and not the DOM element? |
@TrajEdy it makes sense. Gotcha. Thank you! |
we are going to merge the |
Glad i could help start the discussion. The ref approach looks definitely better. : ) |
Content
When you add an id or name to an element, it gets automatically added to the context for easy access (http://riotjs.com/guide/#named-elements).
But, that feature turns out to be a big performance hit on loops.
Here is an example of a loop of 500 elements with ids:
https://plnkr.co/edit/FPOPNLVXoXaIr9LnaRVj?p=preview
It takes about 400ms to 2s to render in my machine. : S
The same exact html without ids on the elements of the loop:
https://plnkr.co/edit/GdWFFekcbvBvW2bdCdSq?p=preview
Renders in about 10-20ms.
This pr adds support to disabling that automatic bounding of named elements via a 'no-named-elements' attribute:
<div id={ id } each={ items } no-named-elements></div>
We could argue that we just shouldn't use ids on loops, but there might be scenarios where we just have to (e.g. third party libraries that depend on ids).
We could also workaround this issue by preventing the UI from having so many elements, but working with hundreds of nodes doesn't sound like an unreasonable front end use case, and again, there might be an scenario when this isn't possible (e.g. a search widget where the backend api can't provide paginated results and we just filter on the UI).
Code
Yes.
Example with the new riot+compiler.js, that uses the attribute to disable the named elements:
http://plnkr.co/edit/lV2c26h1HW0q9CK7Ssvt?p=preview
Example with the new riot+compiler.js, that doesn't use the attribute to disable the named elements:
https://plnkr.co/edit/E4w0PJECkT1zBvtVXN9b?p=preview
No.