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

[MAJOR] rename addItemFilterFn and allow string and RegExp #699

Merged
merged 3 commits into from
Oct 29, 2019
Merged

[MAJOR] rename addItemFilterFn and allow string and RegExp #699

merged 3 commits into from
Oct 29, 2019

Conversation

tinovyatkin
Copy link
Contributor

@tinovyatkin tinovyatkin commented Oct 25, 2019

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 conventional addItemFilter and allow to be RegExp 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.

@tinovyatkin tinovyatkin changed the title rename addItemFilterFn rename addItemFilterFn and allow string and RegExp Oct 25, 2019
@tinovyatkin tinovyatkin changed the title rename addItemFilterFn and allow string and RegExp [MAJOR] rename addItemFilterFn and allow string and RegExp Oct 25, 2019
// Convert addItemFilter to function
if (
userConfig.addItemFilter &&
typeof userConfig.addItemFilter !== 'function'
Copy link
Collaborator

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

Copy link
Contributor Author

@tinovyatkin tinovyatkin Oct 25, 2019

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.

Copy link
Contributor Author

@tinovyatkin tinovyatkin Oct 25, 2019

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

Copy link
Collaborator

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

@jshjohnson jshjohnson merged commit b080bcd into Choices-js:master Oct 29, 2019
@tinovyatkin tinovyatkin deleted the rename-addItemFilterFn branch October 29, 2019 17:31
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.

2 participants