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.
The
memory
package (and maybe other DB adapters?) should take aselector
option. This service already takes amatcher
andsorter
option.See: https://github.com/feathersjs/feathers/blob/09519fb1c454ea718747a09797bc6dfd3b6a79a3/packages/memory/src/index.ts#L25
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.I will try to open a PR for this when I get a chance.