-
Notifications
You must be signed in to change notification settings - Fork 618
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
[MAJOR] rename addItemFilterFn and allow string and RegExp #699
[MAJOR] rename addItemFilterFn and allow string and RegExp #699
Conversation
// Convert addItemFilter to function | ||
if ( | ||
userConfig.addItemFilter && | ||
typeof userConfig.addItemFilter !== 'function' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using isType('Function', this.config.addItemFilter)
would be consistent with the rest of the codebase. I've avoided using typeof due to this: https://bonsaiden.github.io/JavaScript-Garden/#types.typeof
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will submit a PR later to refactor/remove isType, etc. If you are going to TypeScript you probably will do it yourself too.
typeof
together with instanceof
are major type of tools TypeScript/VSCode type Intellisence relays on. They are the type guards. While they have an edge cases (like typeof new String('who is doing that?!') !== typeof String('🤷🏼♂️')
, for simply checking that something is a function typeof fn === 'function'
is flawless as well as r instanceof RegExp
and the last one helps a lot to prevent further developer error with automatic type checking.
And of course it's faster here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jshjohnson by the way, here are some breaking tests for your current implementation of isType
:
expect(isType("Function", async () => {})).to.equal(true);
expect(
isType("Function", function* gen() {
yield false;
})
).to.equal(true);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough - in that case it's probably worth just ditching isType
addItemFilterFn
is not the only options parameter that expects a function, but it's the only one with pseudo-typings in name. This PR is to rename it to conventionaladdItemFilter
and allow to beRegExp
instance or string to create regular expression (that will cover 90% of real life use cases I believe).I will later submit a separate PR to use standard
pattern
parameter and constrains validation, but for now it's to include this breaking changes in upcoming major release.