Allow functions as keys
#261 discusses the issues with the type definitions with nested keys, but the resolution is not type safe. To make it type safe, functions could be allowed as keys (e.g. keys: [item => item.foo.bar]) as described by @ceymard.
This also allows for simplifying the case of searching derived fields such as full name e.g. item => `${item.firstName} ${item.lastName}` which faces issues similar to those described in #302. Obviously, an intermediate object could be used for this, but that seems excessive compared to having functional keys to search.
I'd be happy to implement a PR for this if the behavior is desired.
This sounds interesting, @matt-tingen. Let's have this in a PR and take a look!
After messing around with it some, I ended up on the same solution as @ceymard which can be summed up with the following:
export type FuseKey<T> =
| keyof T
| { name: keyof T; weight: number }
| { name: string, weight?: number, getFn: (obj: T) => string }
We can't trivially use a bare function as the key because of how the weights are stored. There's a couple of techniques involving Maps which could work around this, but that would increase the minimum browser/node version which makes them non-starters in my opinion.
Unless @ceymard is still interested in this change and wants to champion it, I'll pull in their changes, update it, and make a PR later this weekend.
I don't use this library anymore for now, feel free to go ahead.
Thank you.
Le ven. 21 juin 2019 à 22:39, Matt Tingen [email protected] a écrit :
After messing around with it some, I ended up on the same solution as @ceymard https://github.com/ceymard which can be summed up with the following:
export type FuseKey
= | keyof T | { name: keyof T; weight: number } | { name: string, weight?: number, getFn: (obj: T) => string } We can't trivially use a bare function as the key because of how the weights are stored. There's a couple of techniques involving Maps which could work around this, but that would increase the minimum browser/node version which makes them non-starters in my opinion.
Unless @ceymard https://github.com/ceymard is still interested in this change and wants to champion it, I'll pull in their changes, update it, and make a PR later this weekend.
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/krisk/Fuse/issues/313?email_source=notifications&email_token=AAFUBILUHEJJGPNRZLHOIXLP3U4BLA5CNFSM4HWH3BYKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODYJQ7ZQ#issuecomment-504565734, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFUBIMDIWV5AZGBTVTYNBLP3U4BLANCNFSM4HWH3BYA .
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days