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

toggle is not working #5

Open
Lefthandmedia opened this issue Apr 15, 2020 · 2 comments
Open

toggle is not working #5

Lefthandmedia opened this issue Apr 15, 2020 · 2 comments
Assignees

Comments

@Lefthandmedia
Copy link

Lefthandmedia commented Apr 15, 2020

I cant get the toggle function to work.
first i set a few params with:

qsm('https://www.google.cz/search?q=hello+world&num=20', {
  set: {
    num: [20, 40, 60],
  }
});

then i try to remove one of the with:
qsm('https://www.google.cz/search?q=hello+world&num=20', {
toggle: {
num: 40,
}
});

then the all other params 'num' are gone.

Can it be that the function toggleParams is not returning anything? looks like it should return urlParamsNext
Im using the NPM version

RDG

@just-paja
Copy link
Owner

Hi @Lefthandmedia, thanks for the question.

The toggle was never made to work with arrays. Basically, it looks to the URL and if the value is equal to what you send, it removes it. If the value is not equal to what you send, it adds it.

Aa a workaround, you could use set, but I understand that it is not as convenient.

qsm('https://www.google.cz/search?q=hello+world&num=20&num=40&num=60', {
  set: {
    num: [20,60],
  }
});

Introducing such functionality would be a breaking change and I'm not sure it would be straightforward enough, beacuse we would be treating two values with different behaviour.

What do you think?

@just-paja just-paja self-assigned this Apr 15, 2020
@Lefthandmedia
Copy link
Author

I think that when it is possible to add values as an array a remove method for 1 value should also exist. I see a discussion at whatwg going on on the same topic. whatwg/url#335
But until that time URLsearchparams will incorporate this i think it would be a usefull addition to Qsm.
instead of Qsm.delete(),as suggested in the Whatwg discussion, i would opt for a Qsm.remove() method so not to confuse the standard delete functionality from URLsearchParams.
So Qsm.remove({"key":"value"}),
just my thoughts
RDG

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

No branches or pull requests

2 participants