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

Added lodash and merge option in mapAST #1120

Merged
merged 12 commits into from
May 22, 2020

Conversation

chaosmaker
Copy link
Contributor

Dear maintainers of react-i18next,

Below is my pull request for #1117 where I initially requested the option to have props within a <0 ...props></0> passed to its final component. It is a very simple fix.

I have tried running npm run test but it seems the distribution lacks dtslint/dtslint.json - I have tested the code extensively and don't see any issues that may occur.

I also wasn't sure where to change the documentation. If you point me in the right direction I will adapt where necessary.

Checklist

  • only relevant code is changed (make a diff before you submit the PR)
  • run tests npm run test
  • tests are included
  • documentation is changed or added

@coveralls
Copy link

coveralls commented May 20, 2020

Coverage Status

Coverage increased (+0.04%) to 95.775% when pulling adb6b07 on chaosmaker:FR-prop-passing into 6001a31 on i18next:master.

Added !== instead of !=
@adrai
Copy link
Member

adrai commented May 20, 2020

Is full lodash dependency really needed?

Can't the same be achieved also with: const child = Object.keys(node.attrs).length !== 0 ? { props: node.attrs, ...tmp } : tmp; ?

Remove full lodash loading
change to lodash.merge
@chaosmaker
Copy link
Contributor Author

I tried that first and couldn't get it to work, the props are overwritten by {} that is in tmp. _.merge has the advantage that it will deep merge the properties, so if there are defined properties like class etc, they will be merged together as opposed to replaced. To reduce full lodash I have changed it to load lodash.merge only.

@adrai adrai requested a review from jamuhl May 20, 2020 12:04
@jamuhl
Copy link
Member

jamuhl commented May 20, 2020

sadly won't accept any lodash dependency...this adds over 3.7kb gzipped: https://bundlephobia.com/result?p=lodash.merge@4.6.2

also please add some test cases for future regression:

  • asserting feature works
  • not overwrites props set in code (props already on the node)

thank you 👍

Remove lodash
Slimline prop match. Only accept new values, if node values in translation weren't set.
Fix camelCase and remove lodash loading
@chaosmaker
Copy link
Contributor Author

Ok I have removed lodash and just focused on merging the props using a small function. So nice and light. The code is set in such a way that original values in <Trans><anything ...prop></Trans> are not overwritten when set in the language file. Only missing props are added.

Also not sure why coverage decreased? I didn't remove anything?

I am a bit new to github/code reviews - how/where do I add some test cases?

also please add some test cases for future regression:

  • asserting feature works
  • not overwrites props set in code (props already on the node)

@jamuhl
Copy link
Member

jamuhl commented May 20, 2020

test can be added here: https://github.com/i18next/react-i18next/blob/master/test/trans.render.spec.js

coverage decreased as your newly added code is not covered.

@chaosmaker
Copy link
Contributor Author

I added some tests which seem to work. Hope that is all you need!

@jamuhl
Copy link
Member

jamuhl commented May 20, 2020

looks ok...will check this in detail tomorrow (merge & publish)

@adrai adrai merged commit 5847def into i18next:master May 22, 2020
@adrai
Copy link
Member

adrai commented May 22, 2020

Thanks, it's included in v11.5.0

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

Successfully merging this pull request may close these issues.

4 participants