-
Notifications
You must be signed in to change notification settings - Fork 25
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
Arbitrary late type support #424
Comments
recursive and cross referenced models are supported, see for example the test cases in https://github.com/xaviergonz/mobx-keystone/blob/master/packages/lib/test/model/recursive.test.ts |
the only requirement is that if you use types.model for those cases you have to include the type in the generic, like |
Right, that's working well for me, but as far as I can tell you can't do the same thing with a union of models that then cross reference / recurse, because the union doesn't accept a function, it only accepts already defined values. MST's API allows this because you can do const outer = types.union(
types.late(() => types.model({thing: outer}),
types.late(() => types.model({otherThing: outer}))
) or what have you. My question is would you be open to adding something like |
did you try inheritance? https://mobx-keystone.js.org/class-models#inheritance and/or the factory pattern https://mobx-keystone.js.org/class-models#factory-pattern--generics ? |
For big projects that have a number of circular references,
types.model(() => SomeType)
is great for breaking the cycle and allowing types to reference themselves by not strictly requiring them to do so at require time. Right now AFAICT keystone only supports this behaviour for model types and object types, but not for other types like enums or unions.mobx-state-tree supports
types.late(() => ...)
for arbitrary late type support such that you can late-reference an enum type or a union type that maybe has model references within it that cause circular import issues.Is this something you fine folks have considered for keystone, and would it be possible? Happy to look into it but would love to know if there are any hard blockers.
The text was updated successfully, but these errors were encountered: