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

refactor(Embed): remove add field #7522

Merged
merged 1 commit into from Mar 2, 2022
Merged

refactor(Embed): remove add field #7522

merged 1 commit into from Mar 2, 2022

Conversation

imranbarbhuiya
Copy link
Contributor

@imranbarbhuiya imranbarbhuiya commented Feb 21, 2022

Please describe the changes this PR makes and why it should be merged:
This PR removes Embed#addField in favour of Embed#addFields because you are just saving a s when using addField.

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating
  • This PR changes the library's interface (methods or parameters added)
  • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)

For those who don't wanna replace all addField manually can try this regex replace. You can ofc make a better one but using these 2 also works fine. Idk how can I use condition in replace string else it can be simplified to one regex using ? after inline.

// 1. use this one first
// regex
.addField\(((.|[\n])*?),((.|[\n])*?),(.*true)\)
//replace with
.addFields({name: $1, value: $3, inline: $5})
// 2. use this one after replacing all inline fields
//regex
.addField\(((.|[\n])*?),((.|[\n])*?)\)
//replace with
.addFields({name: $1, value: $3})

cross verify before replacing.

@ImRodry
Copy link
Contributor

ImRodry commented Feb 21, 2022

I think this method should be changed to match v13’s MessageEmbed#addField instead because it is quite useless as it is right now. I don’t think removing it is the way to go because there are many situations where you may only need one field and creating the object just adds unnecessary visual burden to the code

@vladfrangu
Copy link
Member

I think the method should stay as is, although I can see how it's redundant compared to addFields... 🤷 I'll let the others give in their thoughts too

@nev-r
Copy link
Contributor

nev-r commented Feb 21, 2022

i think it's nicer if d.js is ugly so that downstream code can look clean.
allocating a new array and wrapping it in extra syntax to add a single field

addFields([field])

just to make the method happy, is kind of a tragedy.

i'd personally rather recommend people spread into addField than the above mess

@vladfrangu
Copy link
Member

That's not how the spread arguments work, you don't need to wrap them in brackets

@nev-r
Copy link
Contributor

nev-r commented Feb 21, 2022

i didn't say they need to be in brackets?
i said i would rather do addField(...myfields) or addFields(...myfields)
than be forced to to addFields([myfield])
(if the goal is to narrow to 1 method)

@BenjammingKirby
Copy link
Contributor

BenjammingKirby commented Feb 21, 2022

why just remove addField and not other builder methods like addChoice an such?

@BenjammingKirby
Copy link
Contributor

i didn't say they need to be in brackets?
i said i would rather do addField(...myfields) or addFields(...myfields)
than be forced to to addFields([myfield])
(if the goal is to narrow to 1 method)

the methods exclusively take a rest parameter since #7395

@nev-r
Copy link
Contributor

nev-r commented Feb 21, 2022

the methods exclusively take a rest parameter since #7395

ah, thanks. then yeah, such a little stub passthrough function like addField seems unnecessary

@suneettipirneni
Copy link
Member

why just remove addField and not other builder methods like addChoice an such?

If this goes through they should be removed.

@BenjammingKirby
Copy link
Contributor

I think this method should be changed to match v13’s MessageEmbed#addField instead because it is quite useless as it is right now. I don’t think removing it is the way to go because there are many situations where you may only need one field and creating the object just adds unnecessary visual burden to the code

you are forgetting why the change was made
changing to objects was the right call since some of the methods may take multiple optional properties, like setAuthor
what do you want? setAuthor(something, undefined, something)? an object is much better
and with this change they are now useless

@ImRodry
Copy link
Contributor

ImRodry commented Feb 21, 2022

That argument makes no sense because fields are composed of 2 required parameters and 1 optional one

@BenjammingKirby
Copy link
Contributor

BenjammingKirby commented Feb 21, 2022

That argument makes no sense because fields are composed of 2 required parameters and 1 optional one

i never said this particular one does, but i did give you an example didn't i?
so what do you suggest? keep it like this for just this one method but for the others use objects? that to me makes no sense, we should try to stay consistent

@ImRodry
Copy link
Contributor

ImRodry commented Feb 21, 2022

The example you gave is invalid because it comes from a situation with many optional parameters, which this one isn’t and you’d never be passing undefined for the first or second values because that would be an error

@advaith1
Copy link
Contributor

If the goal is to remove redundancy then imo addFields should be removed instead of addField, which is probably used a lot more.

@almostSouji
Copy link
Member

Semantically, addFields makes much more sense, you can add multiple, but adding one is fine too. Whereas adding multiple to addField is not nearly as intuitive

@suneettipirneni
Copy link
Member

If the goal is to remove redundancy then imo addFields should be removed instead of addField, which is probably used a lot more.

Considering what's used more it's kinda hard to tell I wouldn't say for certain that one is used a lot more than the other. However, grammatically it makes more sense for it be plural since it accepts a rest parameter which is 1..n.

@iCrawl iCrawl merged commit 8478d2f into discordjs:main Mar 2, 2022
@imranbarbhuiya imranbarbhuiya deleted the remove-setX branch March 2, 2022 09:41
imranbarbhuiya added a commit to imranbarbhuiya/pagination.djs that referenced this pull request Jun 7, 2022
Breaking Change: Removed singular methods.
Breaking Change: ExtraRowPosition is an enum now.

More infos in discordjs/discord.js#7522
and discordjs/discord.js#7874
imranbarbhuiya added a commit to imranbarbhuiya/pagination.djs that referenced this pull request Jun 23, 2022
Breaking Change: Removed singular methods.
Breaking Change: ExtraRowPosition is an enum now.

More infos in discordjs/discord.js#7522
and discordjs/discord.js#7874
imranbarbhuiya added a commit to imranbarbhuiya/pagination.djs that referenced this pull request Jun 24, 2022
Breaking Change: Removed singular methods.
Breaking Change: ExtraRowPosition is an enum now.

More infos in discordjs/discord.js#7522
and discordjs/discord.js#7874
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet