Skip to content
This repository has been archived by the owner on Sep 8, 2020. It is now read-only.

Prevent duplicate ID's #295

Closed

Conversation

roelplieger
Copy link

We had a problem using multiple inline tinymce editors. Because the code used a timestamp for generating unique ID's some were generated in the same millisecond resulting in duplicate ID's.
As a solution I wrote a service (which is a singleton) that provides a unique ID. All directives ask a unique ID from this service guaranteeing its uniqueness.

FYI: I also tried the supplied unit test agains the old code, then it fails which proves the problem.

Cheers, Roel Plieger.

A service provides unique ID's using a counter instead of a timestamp.
@@ -53,7 +53,7 @@ describe('uiTinymce', function () {
expect(tinymce.init).toHaveBeenCalled();
expect(tinymce.init.calls.mostRecent().args[0].tinymce.bar).toBe('baz');
});

/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this was commented out?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test failed but had nothing to do with my piece of code... Sorry, should have mentioned it ;-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything else I should do?

@deeg deeg self-assigned this Oct 7, 2016
@deeg
Copy link
Contributor

deeg commented Oct 19, 2016

It was actually doing this recently, and was changed by 15c64f1.

I just want to do some investigation tonight to see if there are any implications for changing that back.

I have another possible fix, for what that commit was trying to solve, so I will take another look tonight at everything.

@roelplieger
Copy link
Author

Ok, checked it with the generatedIds var, this also passes my unit test so you don't need the service. I thought every directive would get its own instance so the counter var would start at zero all the time, but this isn't true (at least if the var is initialized above the return of course).

@Bradleycorn
Copy link

Bradleycorn commented Nov 1, 2016

I'm running into the same issue (duplicate id's for multiple instances are generated with the same timestamp) ... Hope this PR can be resolved soon!

Also, love me some Phish band. Been touring since '94 ;)

@ClickerMonkey
Copy link

How in the world isn't this fixed yet - and how did someone think it was a good idea to use a timestamp?

@deeg deeg closed this in 211b756 Dec 16, 2016
@deeg
Copy link
Contributor

deeg commented Dec 16, 2016

@ClickerMonkey, thanks for the helpful input!

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

Successfully merging this pull request may close these issues.

None yet

4 participants