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

removeQuery accepts RegExp that filters the keys #204

Merged
merged 1 commit into from
Apr 2, 2015
Merged

removeQuery accepts RegExp that filters the keys #204

merged 1 commit into from
Apr 2, 2015

Conversation

peterwillis
Copy link
Contributor

I added RegExp support to the removeQuery function. It is a bit like passing a string, except if uses the regexp to filter out keys that match the expression. I added a test and updated the docs too.

@rodneyrehm
Copy link
Member

is removeQuery() the only method where accepting a RegExp makes sense?

@peterwillis
Copy link
Contributor Author

Yes, it is already supported by hasQuery, and I don't think it makes sense in add or set

@rodneyrehm
Copy link
Member

I see .hasQuery() accepts a RegExp to validate the value, but not the name. Your PR would apply the RegExp to the name, but not the value.

Should both methods accept RegExps for both name and value?

@peterwillis
Copy link
Contributor Author

I don't think so. When I look at changing hasQuery to support that, I don't know how it should behave. If the regexp matches multiple keys then should it test all the values? To make it support a regexp for the key parameter and also support all the other ways you can use it would be quite complex and I can't think of any use cases for it, so it would just be extra code for no reason. If you look at the way removeQuery works when you give it a single string, the way I have done it fits in nicely with that ie it filters the keys, not the values. I don't think it makes the overall API inconsistent.

@rodneyrehm
Copy link
Member

I don't think it makes the overall API inconsistent.

The one method accepts RegExp for keys, the other method accepts RegExp for values. How is that not inconsistent?

… I can't think of any use cases for it, so it would just be extra code for no reason.

neither can I for the hasQuery() part. for the removeQuery supporting RegExp for values does make a bit more sense, though.

@peterwillis
Copy link
Contributor Author

What I mean is that in hasQuery, the first parameter is the key selector, the second is the value selector, so if the first argument is always a key selector in the methods, the API is consistent.

I can appreciate that someone may want to filter out an option in the query if a value matches a regexp. That would be an additional way of using removeQuery where the value regexp is passed as the second argument, rather than a replacement for this.

I can submit that in another pr if it is also useful?

@rodneyrehm
Copy link
Member

I can appreciate that someone may want to filter out an option in the query if a value matches a regexp.

yes, there was a time when I did this regularly.

I can submit that in another pr if it is also useful?

You could also just add it do this PR, after all it's just extending the RegExp support you introduced here, no?

@peterwillis
Copy link
Contributor Author

Ok, I am away until Wednesday so I can't add that until then.

@rodneyrehm rodneyrehm merged commit 765fb20 into medialize:master Apr 2, 2015
rodneyrehm added a commit that referenced this pull request Apr 2, 2015
@rodneyrehm
Copy link
Member

I merged what you had and added the missing bit myself. thanks for your support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants