4 ms·
This is a weird API for what it’s trying to achieve. Why make every Cleave instance use a boolean to determine its type + some related other field that varies b
by jsf01 8y ago
This is a weird API for what it’s trying to achieve. Why make every Cleave instance use a boolean to determine its type + some related other field that varies based on which type happens to be set to true? Doing it this way prevents tree shaking from getting rid of all the methods you’re not using. If instead it was something like:
cleave.Date(...), cleave.Phone(...), etc.
then each of those constructors could implement specific options that are relevant. As it is now, you could have an onCreditCardTypeChanged() method on a date input. And if you did it in a manner like I’m proposing, you’d be able to import just the specific formatters you need, allowing your module bundler to strip out the rest.
- rounce 8y agoGlad I'm not the only one that thought the API was a bit 'interesting'. I was also wondering what happens when you set `phone`, `date` and `creditCard` to `true` in the same config and pass it to the constructor? Surely this should at least be a single field, if not separate classes/prototype chains (as jsf01 mentioned).