Skip to content

Commit

Permalink
Added an optional function that will be passed to an array filter to …
Browse files Browse the repository at this point in the history
…filter out any unwanted records from the current list of records on useVingKind() records list.
  • Loading branch information
rizen committed Jun 6, 2024
1 parent 01307d1 commit d7dfd39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
19 changes: 12 additions & 7 deletions composables/ving/useVingKind.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -385,17 +385,22 @@ class VingKind {
*
* @param {'props'|'meta'|'extra'} section One of the describe section names such as `props`, or `meta`, or `extra`.
* @param {string} field The name of the field within the `section` that will serve as the labelf for this option list.
* @param {Function} filter An optional function that will be passed to an array filter to filter out any unwanted records from the current list of records.
* @returns {object[]} An array of objects with `label` and `value` attributes.
* @example
* users.recordsAsOptions('meta','displayName')
*/
recordsAsOptions(section, field) {
return this.records.map(u => {
return {
value: u.props?.id,
label: u[section][field]
}
})
recordsAsOptions(section, field, filter = () => true) {
let out = [];
for (const record of this.records) {
if (!(filter(record)))
continue;
out.push({
value: record.props?.id,
label: record[section][field]
});
}
return out;
}

/**
Expand Down
1 change: 1 addition & 0 deletions ving/docs/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ outline: deep

### 2024-06-06
* Fixed documentation for ving/utils/fs readJSON and writeJSON
* Added an optional function that will be passed to an array filter to filter out any unwanted records from the current list of records on useVingKind() records list.

### 2024-06-01
* Documented noSetAll() attribute in Ving Schemas.
Expand Down

0 comments on commit d7dfd39

Please sign in to comment.