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

Documentation: strangely used parameter in context example #555

Closed
2 tasks done
Be3y4uu-K0T opened this issue May 21, 2024 · 2 comments
Closed
2 tasks done

Documentation: strangely used parameter in context example #555

Be3y4uu-K0T opened this issue May 21, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@Be3y4uu-K0T
Copy link

Description

```surql
CREATE film SET
ratings = [
{ rating: 6, user: user:bt8e39uh1ouhfm8ko8s0 },
{ rating: 8, user: user:bsilfhu88j04rgs0ga70 },
],
featured = function() {
return this.ratings.filter(
({ rating }) => rating >= 7
).map(({ rating }) => {
return {
...rating,
rating: rating * 10
};
});
}
;
```

ratings is array of objects with keys: rating (number) and user (id).
In map the object is destructuring by key rating (number) and then rating used as an object with the spread operator ...rating!

Maybe you meant something like this:

CREATE film SET
	ratings = [
		{ rating: 6, user: user:bt8e39uh1ouhfm8ko8s0 },
		{ rating: 8, user: user:bsilfhu88j04rgs0ga70 },
	],
	featured = function() {
		return this.ratings.filter(
			({ rating }) => rating >= 7
		).map(({ rating, ...data }) => {
			return {
				...data,
				rating: rating * 10
			};
		});
	}
;

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct
@Be3y4uu-K0T Be3y4uu-K0T added the documentation Improvements or additions to documentation label May 21, 2024
@Ekwuno
Copy link
Contributor

Ekwuno commented May 28, 2024

Hey @Be3y4uu-K0T thanks for pointing this out. You are correct! We shouldn't be mapping the number. I'll go with rating & User instead since it's the only other data param.

CREATE film SET
    ratings = [
        { rating: 6, user: 'user:bt8e39uh1ouhfm8ko8s0' },
        { rating: 8, user: 'user:bsilfhu88j04rgs0ga70' },
    ],
    featured = function() {
        return this.ratings.filter(
            ({ rating }) => rating >= 7
        ).map(({ rating, user }) => {
            return {
                user,
                rating: rating * 10
            };
        });
    }
;

@Ekwuno
Copy link
Contributor

Ekwuno commented May 28, 2024

Updated.

@Ekwuno Ekwuno closed this as completed May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

2 participants