[Request] move key field from public API to optional argument
See original GitHub issueDuring 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.
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:
- Created 3 years ago
- Reactions:23
- Comments:10
Top GitHub Comments
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
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.