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

fix(text-field): Made handleValidationAttributeMutation to accept attribute list #2794

Merged
merged 8 commits into from
May 24, 2018

Conversation

abhiomkar
Copy link
Contributor

@abhiomkar abhiomkar commented May 23, 2018

Fixes #2717

BREAKING CHANGE:

  • Changed the signature of Adapter method - registerValidationAttributeChangeHandler.
  • Renamed and changed signature in Foundation: handleValidationAttributeMutation => handleValidationAttributeChange.

@moog16
Copy link
Contributor

moog16 commented May 23, 2018

Please fix lint issues

* @param {!Array<!MutationRecord>} mutationsList
* @return {!Array<string>} Returns list of attribute names.
*/
getMutationAttributeNames_(mutationsList) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be an adapter method. We should be removing the MutationRecord from the foundation, since its environment specific.

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 method is no longer required here since this part is moved to index.js (registerValidationAttributeChangeHandler's implementation) to separate the concerns of MutationRecord logic. PTAL.

@kfranqueiro
Copy link
Contributor

Discussed this with Abhinay, and we realized we should be able to solve this with a 1-2 line change in the vanilla DOM adapter implementation for registerValidationAttributeChangeHandler and a small change to the foundation's handleValidationAttributeMutation.

The adapter will be changed to expect the handler to handle an array of strings rather than an array of mutation objects, so it'll require a README update and a BREAKING CHANGE note in the commit description.

The foundation method will also change to require an array of strings, which also needs a doc update but isn't a breaking change itself since we only just made the method public after the last release. (Should we change the name to Change instead of Mutation?)

This way, no additional adapter methods need to be implemented.

In MDC React, the logic should change to look at Object.keys(nextProps), filter to only include properties that actually changed, then pass the resulting filtered array of attributes to handleValidationAttributeMutation. MDC React should not need to mirror the attribute whitelist array; the foundation is already doing that work.

…geHandler for handler.

handler in registerValidationAttributeChangeHandler now accepts the list of attribute changes instead of mutations for isolating the MutationRecord off from foundation.
@codecov-io
Copy link

codecov-io commented May 24, 2018

Codecov Report

Merging #2794 into master will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2794      +/-   ##
==========================================
+ Coverage   98.48%   98.48%   +<.01%     
==========================================
  Files          98       98              
  Lines        4231     4232       +1     
  Branches      538      538              
==========================================
+ Hits         4167     4168       +1     
  Misses         64       64
Impacted Files Coverage Δ
packages/mdc-textfield/foundation.js 98.89% <100%> (ø) ⬆️
packages/mdc-textfield/index.js 92.9% <100%> (+0.04%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 917150c...95eeebc. Read the comment docs.

@moog16
Copy link
Contributor

moog16 commented May 24, 2018

The function name change sounds good to me.

w/ regards to the React, if we don't have the list of attributes to look for, we will be calling the handleValidationChange every time a prop changes.

Copy link
Contributor

@moog16 moog16 left a comment

Choose a reason for hiding this comment

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

Looks good!

@kfranqueiro
Copy link
Contributor

Hm. If we move MDC Web's whitelist into constants.js, can MDC React reference it there rather than needing to redefine it?

@moog16
Copy link
Contributor

moog16 commented May 24, 2018

Ya that's a good idea 👍

@@ -102,7 +102,8 @@ class MDCTextFieldAdapter {

/**
* Registers a validation attribute change listener on the input element.
* @param {function(!Array): undefined} handler
* Handler accepts list of attribute changes.
Copy link
Contributor

Choose a reason for hiding this comment

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

changes -> names?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -319,7 +319,7 @@ test('#adapter.deregisterTextFieldInteractionHandler removes an event handler fo
test('#adapter.registerValidationAttributeChangeHandler creates a working mutation observer', (done) => {
const {root, component} = setupTest();
const handler = td.func('ValidationAttributeChangeHandler');
td.when(handler(td.matchers.anything(), td.matchers.anything())).thenDo(() => {
td.when(handler(td.matchers.anything())).thenDo(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

anything -> contains('required')?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@abhiomkar abhiomkar merged commit 8b2bb83 into master May 24, 2018
kfranqueiro pushed a commit that referenced this pull request May 24, 2018
…ribute list (#2794)

BREAKING CHANGE: registerValidationAttributeChangeHandler adapter API now expects the handler to accept an array of strings, not mutation objects
@kfranqueiro kfranqueiro deleted the fix_textfield_mutationrecord_ref_issue2717 branch August 1, 2018 16:21
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.

None yet

4 participants