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

Auto adding query into any options variable #308

Closed
lixelv opened this issue Aug 27, 2024 · 1 comment
Closed

Auto adding query into any options variable #308

lixelv opened this issue Aug 27, 2024 · 1 comment

Comments

@lixelv
Copy link

lixelv commented Aug 27, 2024

For some reason, when I'm giving to subscribe function some options variable, It wraps her arguments in query: {}. This is not cool, to find, that your variable was edited, when you just gave it to your function. I've fixed this by replacing options (in func) on JSON.parse(JSON.stringify(options)). May be there are more efficient way, but idk. Here is example:

let options = {
	sort: '-updated',
	expand: 'allowed,owner'
};

await pb.collection('users').subscribe('*', () => {}, options);

console.log(options);

// options = {
//     "query": {
//         "sort": "-updated",
//         "expand": "allowed,owner"
//     }
// }
@ganigeorgiev
Copy link
Member

I've pushed a minor update in v0.21.5 release to shallow copy the options argument similar to the other methods.

Note that we don't do deep clone because the options argument could technically contain user defined functions (e.g. fetch) which will require special manual handling. I'll think a little more on it with the refactoring and eventually may create a helper that will call structuredClone + some additional handling for the special cases but for now remains a low priority.

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