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

feat: Randomize holder id (#76) #76

Merged
merged 3 commits into from
Nov 28, 2020

Conversation

jakekara
Copy link
Contributor

This is meant to address #11. As I mentioned in the thread I'm not that familiar with the overall code base, but I figured I'd make a PR in case it works for your project.

@Jungwoo-An Jungwoo-An self-requested a review October 19, 2020 02:49
@Jungwoo-An Jungwoo-An added the enhancement New feature or request label Oct 19, 2020
lib/EditorJs.tsx Outdated
@@ -20,6 +20,7 @@ export type Props = Readonly<EditorJS.EditorConfig> & Readonly<EditorJsProps>

class EditorJsContainer extends React.PureComponent<Props> {
instance?: EditorJS
holderID: string
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
holderID: string
holder: string

This option must remain same name as the original option. It makes editor-js users predict the available options.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This looks good. Should I add a commit to change this and all the other references from holderID to holder?

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made a new commit that I believe addresses all of the issues you've raised in this review. This is my first time contributing to someone else's GH project and going through this PR/review process, so hopefully I've done so correctly.

jakekara@7cdf3db

Copy link
Owner

Choose a reason for hiding this comment

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

Yes, that's right. 😄

lib/EditorJs.tsx Show resolved Hide resolved
lib/EditorJs.tsx Outdated
Comment on lines 130 to 134
const randomString = () => {
const min = 1000 * 1000 * 1000
const max = 9999 * 1000 * 1000
return (Math.round(Math.random() * (max - min * min)) + min).toString(36)
}
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
const randomString = () => {
const min = 1000 * 1000 * 1000
const max = 9999 * 1000 * 1000
return (Math.round(Math.random() * (max - min * min)) + min).toString(36)
}
this.holderID = `editor-js-${Date.now().toString(36)}`

If you don't mind, how about generating string based on Date object?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This makes sense, but in theory, couldn't this lead to a collision if two instances are added at the same exact time? What about adding random jitter of about 1000 to the Date.now() value?

Date.now() + Math.floor(Math.random() * 1000)

Copy link
Owner

Choose a reason for hiding this comment

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

Wow! that's great!

@Jungwoo-An
Copy link
Owner

I'm sorry for the late reply! Thanks for your pull request!

lib/EditorJs.tsx Outdated
constructor(props: EditorJsProps) {
super(props)

this.holder = `editor-js-${(
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
this.holder = `editor-js-${(
class EditorJsContainer extends React.PureComponent<Props> {
holder = `editor-js-${...}`;

Why don't you try using class field? It's simple to initialize

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've switched to that approach here: 71a71dc

@Jungwoo-An Jungwoo-An self-assigned this Nov 2, 2020
@Jungwoo-An Jungwoo-An changed the title Randomize holder id feat: Randomize holder id Nov 2, 2020
@Jungwoo-An
Copy link
Owner

I'm waiting for your contribution. I hope you'll be enthusiastic again. 😢

@jakekara
Copy link
Contributor Author

jakekara commented Nov 3, 2020

I'm waiting for your contribution. I hope you'll be enthusiastic again. 😢

I have become very busy this past week, but don't fret. I do intend to push another commit in the next couple of days.

Copy link
Owner

@Jungwoo-An Jungwoo-An left a comment

Choose a reason for hiding this comment

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

LGTM 👍 I'll update code style and merge to master

@Jungwoo-An Jungwoo-An changed the title feat: Randomize holder id feat: Randomize holder id (#76) [ci skip] Nov 28, 2020
@Jungwoo-An Jungwoo-An merged commit 19b1c64 into Jungwoo-An:master Nov 28, 2020
Jungwoo-An pushed a commit that referenced this pull request Nov 28, 2020
## [1.7.0](1.6.2...1.7.0) (2020-11-28)

### Features

* Randomize holder id ([#76](#76)) [ci skip] ([19b1c64](19b1c64))
@Jungwoo-An
Copy link
Owner

🎉 This PR is included in version 1.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Jungwoo-An Jungwoo-An changed the title feat: Randomize holder id (#76) [ci skip] feat: Randomize holder id (#76) Nov 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants