javascript icon indicating copy to clipboard operation
javascript copied to clipboard

[FIX] getCities

Open hyanmandian opened this issue 6 years ago • 26 comments

Today getCities return just city name, but in Brazil, we have some cities with same name in different states... So I think that we should return stateCode and maybe code (IBGE id) in the returned data.

Something like that:

[
  {
    code: 14324,
    name: 'Bom Jesus',
    stateCode: 'SC',
  },
  {
    code: 14324,
    name: 'Bom Jesus',
    stateCode: 'RS',
  },
  {
    code: 14324,
    name: 'Bom Jesus',
    stateCode: 'RN',
  },
  {
    code: 14324,
    name: 'Bom Jesus',
    stateCode: 'PB',
  },
  {
    code: 14324,
    name: 'Bom Jesus',
    stateCode: 'PI',
  }
]

I know this change will break our API, but since we're still in RC, maybe it's not a big problem. What do you think about it @arantespp @andreoav ?

hyanmandian avatar Aug 07 '20 17:08 hyanmandian

@hyanmandian RC should not introduce new breaking changes. I think it is better to deprecate the current API and introduce the new API as another helper.

andreoav avatar Aug 08 '20 01:08 andreoav

Maybe we should remove this utility... Talking to @andreoav we discover that this function adds a lot of unnecessary bytes and this type of utility should have an API to consume. We concluded that this is out of our scope.

hyanmandian avatar Aug 21 '20 13:08 hyanmandian

Good point about the cities with the same name, but with a different state. I didn't consider this because I've never seen an usage of all cities together because it returns a huge amount of data. The application gets the state first and after the cities of the selected state.

About

Maybe we should remove this utility...

are you talking about removing getCities @hyanmandian?

arantespp avatar Aug 25 '20 18:08 arantespp

Yes @arantespp :( This util increase a lot of bytes in our library.

Look that: https://bundlephobia.com/result?p=@brazilian-utils/[email protected]

Jumps from 18.3kb to 102.4kb

hyanmandian avatar Aug 25 '20 18:08 hyanmandian

I see. Is the size huge even with tree shaking? About the project scope, if getCities not fit, I agree that the best is to remove it.

Make sense for the project to create a package called @brazilian-utils/cities?

arantespp avatar Aug 25 '20 19:08 arantespp

Yes, even with tree shaking we have a problem because today our tree shaking is not so good :(

I think that we have 2 ways to fix that, the first and easier to do is just remove that function, another way is fixing our tree shaking and maybe create a babel-plugin to remove from our users the knowledge of how to handle with that, for example:

Today we import something like that: import { isValidCPF } from" @ brazilian-utils/brazilian-utils" in a tree shakable way we import something like this: import isValidCPF from" @brazilian-utils/brazilian-utils/is-valid-cpf ";, so the babel plugin will help just replacing @brazilian-utils / brazilian-utils to @brazilian-utils/brazilian-utils. You can see something like that in date-fns or lodash libraries.

I think the second approach is better for our future, but in that case, I don't know if it's applicable. Interacting with IBGE API I discovered that the names of cities changes more frequently then I expect (seriously, every new build that I've generated the cities JSON was updated) and for things like this that are is so variable is better to use an API to consume that. Maybe this function could make a part of BrasilAPI (I saw some issues related to IBGE API).

hyanmandian avatar Aug 26 '20 13:08 hyanmandian

I didn't know that the cities name changed a lot. So it's better remove getCities by now, because it fits better with BrasilAPI.

arantespp avatar Aug 26 '20 17:08 arantespp

Should another issue be opened regarding the tree-shaking problem? This way we can proceed removing getCities.

pedrovsp avatar Sep 30 '20 20:09 pedrovsp

Also removing the getCities() method would be a breaking change. Should it be deprecated first and then removed in a next major release?

pedrovsp avatar Oct 01 '20 15:10 pedrovsp

Nice idea @pedrovsp ! First, we need to deprecate this function with // @deprecated annotation with the reason and maybe provide some alternative (like @brazilian-utils/getCities or something like that). After that, we can remove and increase the version.

Are you guys ok with that?

hyanmandian avatar Oct 27 '20 13:10 hyanmandian

Yes, sounds good to me! Should another issue be opened regarding the creation of @brazilian-utils/getCities? Will it be a new repo inside the brazilian-utils organization?

pedrovsp avatar Oct 27 '20 16:10 pedrovsp

I agree with moving cities to another package, because that will make the core utils much smaller when someone looks in bundlephobia

The "size" ins't really an issue, as I pointed in https://github.com/brazilian-utils/brazilian-utils/issues/157#issuecomment-720021547, but the majority of users will feel afraid after seeing the size of the whole package

and the name maybe something like @brazilian-utils/cities will be better, maybe new utilities related to cities appear, what do you think?

hexetia avatar Nov 01 '20 04:11 hexetia

Nice thoughts @saculbr ! I prefer @brazilian-utils/cities, as you said, makes more sense, but since tree shaking works fine like you comments in #157 , I don't know if we need to spend more time discussing if we remove or not this function (because we can do it after some feedback from our users). For me, is better to just can fix the return as I mentioned in this issue.

What do you guys think about that?

hyanmandian avatar Nov 03 '20 14:11 hyanmandian

@hyanmandian how is the status of this issue? First will we deprecated the API and after creating @brazilian-utils/cities if code and stateCode?

arantespp avatar Dec 07 '20 19:12 arantespp

We just need to decide what we should do. At first, I thought that deprecate this function and create another package make sense, but after @morhogg discovered in #157 that the tree shake works fine, I think we can just improve the current behavior to what I've suggested in this issue and finally publish v1 with a note in the changelog explaning about the API changes.

hyanmandian avatar Dec 07 '20 19:12 hyanmandian

can just improve the current behavior to what I've suggested in this issue

Does this mean that we change the getCities return values instead of creating a getCitiesV2?

arantespp avatar Dec 07 '20 19:12 arantespp

Yes.. What do you think about it?

hyanmandian avatar Dec 07 '20 19:12 hyanmandian

Or we can do what @andreoav suggested. I know that this approach it's correct, but I would not like to do that :(

hyanmandian avatar Dec 07 '20 19:12 hyanmandian

I prefer keeping getCities, but I don't know the strict rules of a package in an RC. If this package wasn't in RC, I'd agree with @andreoav.

@hyanmandian have you ever considered creating a method with a name like getDetailedCities?

arantespp avatar Dec 07 '20 19:12 arantespp

Because today getCities (without the state) returns the wrong data and can cause issues. For example, in the current project that I work on, we replace getCities with a call for internal API because we need more data. I know that getCities(state) (with the state) return the right data, but I think that this behavior is so confusing and makes trouble in the future.

hyanmandian avatar Dec 07 '20 20:12 hyanmandian