Skip to content
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

Different overrides for id generator function for each idProp #423

Open
airhorns opened this issue Mar 5, 2022 · 0 comments
Open

Different overrides for id generator function for each idProp #423

airhorns opened this issue Mar 5, 2022 · 0 comments
Labels
🍗 enhancement New feature or request

Comments

@airhorns
Copy link
Contributor

airhorns commented Mar 5, 2022

We're looking at switching over to mobx-keystone from mobx-state-tree, and one tiny feature we've come to really appreciate in MST is a per-model id generator function. AFAICT, keystone currently supports one global id generator function that is overrideable, but in MST, you can configure the id generator on a per prop basis.

Our use case is putting the type name in the generated ID itself. We use an id prop similar to what keystone has by default, but we are able to do:

const Thing = types.model({
  id: types.optional(types.identifier, () => `Thing-${nanoid()}`),
})

where each different model type has an id generator that prefixes the id with the type's name. This is super useful when passing ids around to know what it is actually and id for and to make it easier to detect accidentally passing an identifier for the wrong type. I don't think mobx-keystone needs to do this by default, but being able to customize the generator for each model would be great to let us do this in userland!

@xaviergonz xaviergonz added the 🍗 enhancement New feature or request label Mar 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍗 enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants