question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow functions as keys

See original GitHub issue

#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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ceymardcommented, Jun 21, 2019

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 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 .

0reactions
github-actions[bot]commented, May 14, 2020

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Simple Ways to Enable Function Keys: 4 Steps (with Pictures)
Hold down the Fn key. This key is usually found in the bottom-left corner of your keyboard next to the Ctrl or Control...
Read more >
How do I use the Fn key/F Lock key/Alternate command keys?
To enable FN Lock on the All in One Media Keyboard, press the FN key, and the Caps Lock key at the same...
Read more >
How To Use Function Keys Without Pressing Fn Key On ...
Method 1. Toggle the Fn Lock key ... Some keyboards, most commonly laptop keyboards, come with a dedicated Fn Lock key. Pressing this...
Read more >
How to Enable / Disable Fn Key to Use With Action / Function ...
In this tutorial, you will learn to lock/unlock the Fn Key behavior by changing the BIOS Setting. Learn Also: How to Fix Cannot...
Read more >
In JavaScript how can I use a function parameter as the key to ...
Use the conventional Object syntax. function myFunc(key, value) { myObj = new Object(); myObj[key] = ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found