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

Add reduceChildren iterator #8

Merged
merged 1 commit into from
Oct 12, 2024
Merged

Add reduceChildren iterator #8

merged 1 commit into from
Oct 12, 2024

Conversation

skirtles-code
Copy link
Owner

This PR adds a new reduceChildren iterator function. It is intended to be similar to the native Array.prototype.reduce.

Example usage:

import { reduceChildren } from '@skirtle/vue-vnode-utils'

// Inside a render function
const children = slots.default?.() ?? []
const count = reduceChildren(children, sum => sum + 1, 0)

Unlike Array.prototype.reduce, the initial value is a required argument. Making it optional would have been difficult, as reduceChildren also needs to support passing the IterationOptions. This could be revisited if use cases emerge.

This feature should be included in 0.2.0.

@skirtles-code skirtles-code merged commit d4bdaa2 into main Oct 12, 2024
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 this pull request may close these issues.

1 participant