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

Memory - add selector option #3451

Open
DaddyWarbucks opened this issue Mar 26, 2024 · 0 comments
Open

Memory - add selector option #3451

DaddyWarbucks opened this issue Mar 26, 2024 · 0 comments

Comments

@DaddyWarbucks
Copy link
Member

The memory package (and maybe other DB adapters?) should take a selector option. This service already takes a matcher and sorter option.

See:

const _select = (data: any, params: any, ...args: string[]) => {

My main use case is not wanting to JSON stringify/parse the results in large datasets to decrease the memory footprint. This particular app uses localStorage, disabled pagination, does not use $select, and has many thousands of records.

There are a number of other valuable uses cases such as using dot.notation in $select, not stringify-ing the results keeps Dates, etc.

// Return the referencial value. When using $select, you will get copies of the data because `base`
// will return a selected copy. But when not using $select it returns a reference to OG data.
// Beware mutability...but I am willing to take that risk in this case.
const selector = (data: any, params: any, ...args: string[]) => {
  const base = select(params, ...args)
  return base(data)
}

// Freeze the data
const selector = (data: any, params: any, ...args: string[]) => {
  const base = select(params, ...args)
  return Object.freeze({ ...base(data) })
}

// Custom dot.notation selection
const selector = (data: any, params: any, ...args: string[]) => {
  const base = selectWithDotNotation(params, ...args)
  return base(data)
}

I will try to open a PR for this when I get a chance.

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

1 participant