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.

[Request] move key field from public API to optional argument

See original GitHub issue

During of Recoil usage I faced with unnecessary boilerplate in key field for atom or selector for state with static root.

For the project it looks like creating of additnional constants. image

From API-usage point it looks like: “I need to define API unique required filed as public for private API goals”. In other words for common api usage the key is redundant.

The request is next: Move key field out and setup it within the Recoil. For dynamic usage like dynamicKey_${id} it could be placed to the second argument as optional. For other metadata and params not related to default the same operation could be performed

In case it it could be he result could be next:

// before
const atomState = atom({
  key: 'uniqueAtomState',
  default: 'defaultStateValue'
});

const selectorState = selector({
  key: 'uniqueSelectorState',
  get: ({get}) => get(atomState)
});

// after
const atomState = atom('defaultStateValue');
const selectorState = selector({
  get: ({get}) => get(atomState)
});

in case if I key is need to be used for dynamic atoms we can move it out to the second argument as optional.

const atomState = atom('defaultStateValue'); // without public defined key

const atomState = atom('defaultStateValue', 'uniqueAtomState'); // with public defined key as string
const atomState = atom('defaultStateValue', {key: 'uniqueAtomState'}); // with public defined key as an object (good way if API will be extended with more option values)

For the last case for implementation the adding of private isPrivateKey: boolean field to each atom/selector could be a good way to define how key was defined.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:23
  • Comments:10

github_iconTop GitHub Comments

2reactions
nblum-solspeccommented, Jul 7, 2020

Agreed, forcing the user to set and remember strings for each atom is too much to ask, in addition the user is going to have to remember all of the magic strings used for keys in their application since it has to be unique, which is going to cause mad problems once the user’s application grows beyond a todo list. Recommend use guid for key and then add optional name / label field if desired for debugging purposes

1reaction
fantasticsoulcommented, Jul 9, 2020

hey, my friend, maybe you can have a look and try concent, ❤️ build-in dependency collection, a predictable、zero-cost-use、progressive、high performance’s react develop framework.

here is a js online example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

REST API Best practices: Where to put parameters? [closed]
However, here are a few guidelines I use when determining where to put parameters in an url: Optional parameters tend to be easier...
Read more >
REST API Design Best Practices for Parameter and Query ...
Where to put the parameters for APIs? Best practices for parameter and query string usage in REST APIs.
Read more >
Step 3: Parameters (API reference tutorial) | Documenting APIs
REST APIs have several types of parameters: Header parameters: Parameters included in the request header, usually related to authorization.
Read more >
Request Parameters in Postman - Tools QA
Request parameter starts with a question mark (?). Request parameters follow "Key=Value" data format. In our example "q" is the Key and "ToolsQA ......
Read more >
Pass API Gateway REST API parameters to a Lambda ... - AWS
Choose Integration Request. 8. Expand the URL Query String Parameters section. Note: By default, the method request query string parameters are ...
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