Skip to content

Update for react 15.5#497

Merged
lozjackson merged 7 commits intotext-mask:masterfrom
zackify:master
Apr 15, 2017
Merged

Update for react 15.5#497
lozjackson merged 7 commits intotext-mask:masterfrom
zackify:master

Conversation

@zackify
Copy link
Copy Markdown
Contributor

@zackify zackify commented Apr 10, 2017

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

@bbenezech
Copy link
Copy Markdown

@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. ;)
@lozjackson can you merge this? React "warnings" are console errors, are very noisy and fail CIs.

@zackify
Copy link
Copy Markdown
Contributor Author

zackify commented Apr 14, 2017

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:)

@lozjackson
Copy link
Copy Markdown
Member

lozjackson commented Apr 14, 2017

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.

Also, if someone more familiar with how this pulls in the base text mask part could help

text-mask-core is imported into the react component like this

import createTextMaskInputElement from '../../core/src/createTextMaskInputElement'

The angular2-text-mask and ember-text-mask components both import the text-mask-core package from npm as a dependency.. personally I prefer this approach.

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.

I would like to switch it from create class so that you don't need that little extra library

could you show an example? what changes would be required for this?

@lozjackson
Copy link
Copy Markdown
Member

@browniefed @mzedeler do you have any thoughts on this

@browniefed
Copy link
Copy Markdown
Member

Can we just switch to using Component? No reason to bring in create-class

@zackify
Copy link
Copy Markdown
Contributor Author

zackify commented Apr 14, 2017

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.

Comment thread react/example/app.js
<form className='form-horizontal'>
<div className='form-group'>
<label htmlFor='1' className='col-sm-2 control-label'>Masked input</label>
export default () => (
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

@lozjackson
Copy link
Copy Markdown
Member

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

@zackify
Copy link
Copy Markdown
Contributor Author

zackify commented Apr 14, 2017

@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!

@lozjackson
Copy link
Copy Markdown
Member

are any of the changes made to the tests required for your PR?

<input
{...props}
onInput={this.onChange}
onInput={event => this.onChange(event)}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this change required?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, createClass autobinds methods on the components, classes do not. So you have to use an arrow function to keep the value of this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oh, ok fair enough

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It shouldn't be needed. As I understand it, the old version may perform a little better.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mzedeler it most definitely is needed, otherwise the onChange function will not have this

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let me know if you want me to do that for sure! 😎

Comment thread react/src/reactTextMask.js Outdated
onInput={event => this.onChange(event)}
defaultValue={this.props.value}
ref={(inputElement) => (this.inputElement = inputElement)}
ref={inputElement => this.inputElement = inputElement} //eslint-disable-line
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is this change required?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The linter complains about assignment to an arrow function, so i disabled the line

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

but the commas surrounding it do the same thing - does it need changing?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

screen shot 2017-04-14 at 12 34 04 pm

Without that line I get this.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It should be ref={inputElement => { this.inputElement = inputElement }} or better, a bound function handle (same as onChange).

})
}

MaskedInput.propTypes = {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why remove this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You don't need to add createTextMaskInputElement to the component, it just gets called in initTextMask

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

no it is not needed, true.. however, it was put there for a reason and I don't see the need to remove it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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...

Copy link
Copy Markdown
Member

@lozjackson lozjackson Apr 14, 2017

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see, I will make an adjustment to support these test cases for you!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

FYI, tests shouldn't be allowed to successfully skip, I'll fix that as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@lozjackson
Copy link
Copy Markdown
Member

lozjackson commented Apr 14, 2017

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

@zackify
Copy link
Copy Markdown
Contributor Author

zackify commented Apr 14, 2017

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')
})

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This isn't needed because createTextMaskInputElement is called directly, see the initTextMask function


createTextMaskInputElement,
import React from 'react'
import PropTypes from 'prop-types'
Copy link
Copy Markdown
Member

@lozjackson lozjackson Apr 14, 2017

Choose a reason for hiding this comment

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

does PropTypes need to be imported separately? whats the advantage? .. or is the previous method of importing PropTypes not supported any longer?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. it's deprecated in React 15.5 and you have to import it from a separate package

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok

@lozjackson
Copy link
Copy Markdown
Member

@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.

@zackify
Copy link
Copy Markdown
Contributor Author

zackify commented Apr 14, 2017

@lozjackson thanks, sounds good!

@lozjackson
Copy link
Copy Markdown
Member

@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.

@zackify
Copy link
Copy Markdown
Contributor Author

zackify commented Apr 14, 2017 via email

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.

5 participants