Conversation
|
@zackify Can you fix linting complaints to green the build? It looks like it is a no dangling comma, no semi, no curly-space repo. ;) |
|
What do you think about switching the linting to prettier? A lot of big JS projects are doing it and it removes the need to waste time talking about formatting. My editor runs it on save. Also, if someone more familiar with how this pulls in the base text mask part could help, I would like to switch it from create class so that you don't need that little extra library. Thanks:) |
|
I've been busy lately.. I'll look into this when I get a minute. about the linting.. I'd prefer to leave it as is for now.
The I'm not sure why the other components were built the way they were (they were built before my involvement with text mask)... so I'm not really sure of all the pros and cons to each method.
could you show an example? what changes would be required for this? |
|
@browniefed @mzedeler do you have any thoughts on this |
|
Can we just switch to using |
|
I just figured it out and removed createClass. Let me know if you want me to get rid of prettier, if someone else could update the commit to do that and conform to your styles, go for it. Otherwise if you are interested, I could add it on precommit for you guys :) P.S. Have you guys thought about removing the build code from git? I can understand the frustration of prettier being ran when I save files btw, if you want a new pr with just my changes I will turn it off and branch off again. |
| <form className='form-horizontal'> | ||
| <div className='form-group'> | ||
| <label htmlFor='1' className='col-sm-2 control-label'>Masked input</label> | ||
| export default () => ( |
There was a problem hiding this comment.
does the example app need these changes?
Are the changes this PR makes backwards compatible? will existing users of the react component have to make any changes to their app/implementation for this to work?
There was a problem hiding this comment.
The change is needed to get rid of createClass which is deprecated. Functional components have been around since react 14. This should all be fully backwards compatible. I can run the tests with React 14 and see if you'd like?
|
sorry.. can you limit your changes to only change things that are required to fix or implement your PR.. with so many changes it is difficult to see what has actually changed that matters.. and is gonna take a lot longer to test/merge this. I don't mind fixing a few linting issues before merging, but my time is limited |
|
@lozjackson I should have them fixed, I just need to run the tests through the lint command you have and it should be all set. I only changed what was neccesary minus prettier that was auto linting. Sorry about that! |
|
are any of the changes made to the tests required for your PR? |
| <input | ||
| {...props} | ||
| onInput={this.onChange} | ||
| onInput={event => this.onChange(event)} |
There was a problem hiding this comment.
Yes, createClass autobinds methods on the components, classes do not. So you have to use an arrow function to keep the value of this
There was a problem hiding this comment.
It shouldn't be needed. As I understand it, the old version may perform a little better.
There was a problem hiding this comment.
@mzedeler it most definitely is needed, otherwise the onChange function will not have this
There was a problem hiding this comment.
@zackify Why not put the arrow on the function declaration or bind in constructor?
I see no reason to instantiate a new function at each render.
There was a problem hiding this comment.
Sure I can add it to the constructor. I just don't see it as a big deal since arrow functions are already more performant in node than bound ones nodejs/node#3622
There was a problem hiding this comment.
Let me know if you want me to do that for sure! 😎
| onInput={event => this.onChange(event)} | ||
| defaultValue={this.props.value} | ||
| ref={(inputElement) => (this.inputElement = inputElement)} | ||
| ref={inputElement => this.inputElement = inputElement} //eslint-disable-line |
There was a problem hiding this comment.
The linter complains about assignment to an arrow function, so i disabled the line
There was a problem hiding this comment.
but the commas surrounding it do the same thing - does it need changing?
There was a problem hiding this comment.
It should be ref={inputElement => { this.inputElement = inputElement }} or better, a bound function handle (same as onChange).
| }) | ||
| } | ||
|
|
||
| MaskedInput.propTypes = { |
There was a problem hiding this comment.
why move this code block to the bottom? can this be defined on the class like it was? ..can it be put back where it was? or is there a valid reason for moving it
There was a problem hiding this comment.
proptypes are static methods and have to be added to classes like this unless if you want to add static prop types which isn't a standard in js yet
| showMask: PropTypes.bool | ||
| }, | ||
|
|
||
| createTextMaskInputElement, |
There was a problem hiding this comment.
You don't need to add createTextMaskInputElement to the component, it just gets called in initTextMask
There was a problem hiding this comment.
no it is not needed, true.. however, it was put there for a reason and I don't see the need to remove it
There was a problem hiding this comment.
Because you can't just pass the value into a component class. You would be adding it to the instance, like "this.createttextmask = createTextMask" and then calling it on the instance. It's pointless. There was not a reason it needed to be there in the first place. It could have always been called directly
There was a problem hiding this comment.
ok.. there is a reason for it being there though.. it is to aid testing - so that you can test the function exists and is a function.. i agree it is a little pointless and the component works just the same without it.. I'm unsure if I agree with removing it.. it is up for debate..
It tests that the createTextMaskInputElement function is imported correctly into the react component. I can see that it is "testing for the sake of testing", and perhaps not needed...
There was a problem hiding this comment.
also.. this test and this test are relying on being able to stub the createTextMaskInputElement method - currently they are not failing because the method is not being called on the component class.. again, it is not needed to make the component function.. but is there to aid testing.
It might be that there is a better way to test this.. (ideas/PRs welcome).. but I think this particular PR should not make those changes if it doesn't need to.
There was a problem hiding this comment.
I see, I will make an adjustment to support these test cases for you!
There was a problem hiding this comment.
FYI, tests shouldn't be allowed to successfully skip, I'll fix that as well.
There was a problem hiding this comment.
I just made a new commit that makes the component itself a function that expects createTextMaskInputElement to be passed into it, this way you can pass in a mock easily in tests. All tests pass.
|
I'm not trying to be awkward.. its just that you've made a lot of changes to things that don't need to be changed.. and if a bug is introduced as a result of this PR, then it will make it more difficult to track down the exact changes. If we want to make changes to code formatting, linting or other things then that should be done in a separate PR that targets just those things.. This PR should be focussed and targeted at only making changes that are required to fix the specific issue #496 |
|
I didn't make changes that were unnecessary and explained in each of your comments :) I fixed the test linting right now for you. |
| ) | ||
| expect(typeof maskedInput.createTextMaskInputElement).to.equal('function') | ||
| }) | ||
|
|
There was a problem hiding this comment.
This isn't needed because createTextMaskInputElement is called directly, see the initTextMask function
|
|
||
| createTextMaskInputElement, | ||
| import React from 'react' | ||
| import PropTypes from 'prop-types' |
There was a problem hiding this comment.
does PropTypes need to be imported separately? whats the advantage? .. or is the previous method of importing PropTypes not supported any longer?
There was a problem hiding this comment.
Yes. it's deprecated in React 15.5 and you have to import it from a separate package
|
@zackify thanks for tidying this up.. its much easier to see the relevant changes.. We should be in a better position to merge this now.. Unfortunately I don't have time to do that right now.. hopefully will do later today, or over the weekend. |
|
@lozjackson thanks, sounds good! |
|
@zackify sorry.. I appreciate your efforts but can you revert that last commit., and then make those changes in a new PR so I can review the changes separately.. keep this PR focused. |
|
Sure, but i can't really make that pr without the new version. I'll make
two, one with and without the commit
|

Even better would be to move away from react.createClass. But this will make the component work in React 15.5 and 16.