amp icon indicating copy to clipboard operation
amp copied to clipboard

adding a global for unique-id is mega gross

Open jdalton opened this issue 10 years ago • 10 comments

If there's nested deps, it happens in node land. This could pave over another instances unique id counter.

jdalton avatar Dec 19 '14 05:12 jdalton

Not pretty, indeed. But it's done this way precisely because of the scenario you mention. Without it, we can't ensure uniqueness of incrementing IDs if you somehow end up with two instances/versions of this module. Cheap, global uniqueness for throw-away ids is the primary usecase here.

HenrikJoreteg avatar Dec 20 '14 07:12 HenrikJoreteg

Not pretty, indeed. But it's done this way precisely because of the scenario you mention.

You missed my point. You're not ensuring uniqueness. Package A requires amp-unique-id, starts using it, the counter increments. Later it uses Package B which has a dep of a dep on amp-unique-id, which is a different module than the one Package A is using, it loads it up, it paves the counter, the ids are now zeroed, the Package A continues to use the method now with its ids reset (yikes).

I think Underscore's approach is OK here. It's unique for the package that depends on it. While different instances of a module are possible its not as likely that 1 package depends on two different instances.

jdalton avatar Dec 20 '14 10:12 jdalton

Oh shoot, it does zero it out, thanks.

I mistook this issue as you just saying it was ugly (as it is) but the fact that it zeros it out is a bug.

It being unique for the module that requires it is good, but say you're using two different view modules that generate instances in the client and you're generating DOM ids. It's uniqueness isn't actually guaranteed without the global. Seems quite unlikely, but... is that reason enough to avoid it?

HenrikJoreteg avatar Dec 20 '14 15:12 HenrikJoreteg

Seems quite unlikely, but... is that reason enough to avoid it?

Ya, dumping to a global is something to be avoided. I imagine if it was an issue Underscore or Lo-Dash would have picked it up and adjusted. Have you looked at other uid implementations. I have a feeling the one that Underscore uses isn't what you're looking for.

jdalton avatar Dec 20 '14 15:12 jdalton

@AmpersandJS/core-team @AmpersandJS/community-leaders thoughts on this?

HenrikJoreteg avatar Jan 09 '15 04:01 HenrikJoreteg

OT: Is it possible to make core-team & community-leaders public?

jdalton avatar Jan 09 '15 04:01 jdalton

@jdalton i don't see any way to change it. Why does it matter?

HenrikJoreteg avatar Jan 09 '15 05:01 HenrikJoreteg

also, http://ampersandjs.com/contribute

HenrikJoreteg avatar Jan 09 '15 05:01 HenrikJoreteg

i don't see any way to change it. Why does it matter?

It'd be rad if Ampersand core, & relevant teams that make decisions in core, were public.

also, http://ampersandjs.com/contribute

Rock! That covers core-team.

jdalton avatar Jan 09 '15 05:01 jdalton

we should add the other group there too.

HenrikJoreteg avatar Jan 09 '15 05:01 HenrikJoreteg