Skip to content

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.

2 participants