-
-
Notifications
You must be signed in to change notification settings - Fork 772
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
Allow functions as keys #313
Comments
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 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 <notifications@github.com> 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<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 <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
<#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 |
#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.
The text was updated successfully, but these errors were encountered: