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

Arrays in query params #46

Closed
demershov opened this issue Nov 15, 2022 · 11 comments · Fixed by #47
Closed

Arrays in query params #46

demershov opened this issue Nov 15, 2022 · 11 comments · Fixed by #47

Comments

@demershov
Copy link

Hi Kirill,
Thank's for developing for the open source.

I have a question, what to do with the array of values for the URL query param? For example - url?query=alpha,beta,gamma
Because adding a new value to the computed variable, that is array, isn't calling the set() in computed.

Cheers.

@Djaler
Copy link
Owner

Djaler commented Nov 18, 2022

Hello. Can you provide a reproduction for your problem?

@demershov
Copy link
Author

demershov commented Nov 19, 2022

Yep, of course.
Suppose we have a filter, the value of which can be several values at the same time, usually in the URL I saw it as https://url?some-query=value1,value2,value3

I've attempted the following, but it doesn't work.

const filters = reactive({
        someFilterName: useRouteQuery("some-query", [], {
            fromQuery(value) {
                return value.split(",");
            },

            toQuery(value) {
                return value.join(",");
            },
        }),
});

function addValueToSomeFilterName(value = " ") {
        filters.someFilterName.push(value)
}

Of course, I can do the following:

function addValueToSomeFilterName(value = " ") {
        filters.someFilterName.push(value);
        filters.someFilterName = filters.someFilterName;

}

But it seems strange to me, at least.

What do you think about it?
Best wishes.

@Djaler
Copy link
Owner

Djaler commented Nov 21, 2022

I have an idea how to handle this. Will try to do someting

@demershov
Copy link
Author

demershov commented Nov 21, 2022

I have an idea how to handle this. Will try to do someting

Thanks for your answer.
I'm interested in the direction of your proposed solution. Are you going to refuse from computed property?

@Djaler
Copy link
Owner

Djaler commented Nov 23, 2022

No, I think I can wrap a value created in get into reactive and watch it for changes

@Djaler
Copy link
Owner

Djaler commented Nov 23, 2022

Maybe you can take a look at #47

Djaler added a commit that referenced this issue Nov 23, 2022
@demershov
Copy link
Author

I looked at your solution, thank you.

It seems to be working. It's a little confusing me to create a watcher every time, but it's working. It seems that need to assign the result of stopping the watcher to a variable, isn't it?

@Djaler
Copy link
Owner

Djaler commented Nov 28, 2022

There are no result of stopping the watcher

@demershov
Copy link
Author

There are no result of stopping the watcher

A little suffocating.
Yep, it's returns undefined, but the variable keeps storing the function after stopped, isn't it? So checking with the optional chaining isn't quite correct.

@Djaler
Copy link
Owner

Djaler commented Nov 28, 2022

I think nothing bad will happen if I call stop more then once

@demershov
Copy link
Author

You’re right. Thanks.

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 a pull request may close this issue.

2 participants