-
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
Discussion: deprecating the prop API in favor of tProp #308
Comments
I just happened upon this. Having adopted the
This might be resolved with improved documentation and division of examples for both approaches separately.
What is the current need for
The runtime failure part, I'm kind of ok with only because I'm comfortable without runtime type checking - not migrating from MST and don't expect it. But for those very comfortable with MST I can see how having silent failures would be painful.
Can't argue with the maintenance of a single API being more straight forward.
This is a pro, but at the same time constraining ideas to MST API may be a hinderance and limiting. Depends on how you look at it.
As an existing user of prop with about 80 models at the moment (and potentially growing) a migration would be a major undertaking.
One of the reasons I chose the tProp approach is precisely to avoid the typescript performance downsides. I can see how for javascript users the runtime type checking would be more beneficial. But seeing as this library seems to be geared to making typescript support first-class compared to MST, relying on the underlying One thing that is important to me in all of this is that I need the objects that come out of mobx-keystone to implement the same interface as the object going in. With Again this is just my two cents. |
@mashaalmemon I think it's important to note that using You can disable the runtime checks in development mode as well if you choose. The only difference I can see then between Translating a model between the To clarify about be closer to the MST API I only meant the familiarity of defining props using
There is no difference here between the behavior of I think at the core of this issue is that there are some useful features that seem difficult/impossible to support without models having runtime data about their own types. As far as I can see |
v0.64.0 added a feature to alleviate this problem. Basically, now if you use a tProp to model then $modelType is not a requirement anymore in the input snapshot (it will still show in the getSnapshot result though) eg. @model(...)
class M1 extends Model({
x: tProp(0)
}) {}
@model(...)
class M2 extends Model({
m: tProp(M1)
}) {}
const sn = { m: { x: 10 } }
// const m2 = fromSnapshot(sn) // this still won't work without $modelType
const m2 = fromSnapshot(M2, sn); // as long as we pass the type (M2 in this case) then ok
getSnapshot(m2) // { $modelType: "m2", m: { $modelType: "m1", x: 10 } } |
That's awesome! |
There's been some discussion of this in a couple places so I thought it might be useful to have a separate issue about it. #299 #303
Currently there are two APIs for defining model properties in mobx-keystone.
prop
allows defining properties that only have compile time typescript types.tProp
allows defining properties that have compile time typescript types and optionally the ability to check types at runtime.tProp
with runtime checking disabled is identical in behavior toprop
.Per previous discussions, there might be a number of benefits to removing the
prop
API since identical behavior can be achieved withtProp
. So far I see the following benefits:$modelType
I think there are a number of potential downsides to removing the
prop
API as well:prop
API would eventually need to transition totProp
. I think this might be very straightforward however sincetProp
is a superset ofprop
. Perhaps it could even be handled automatically by a codemod if it's a large impact?tProp
vs a direct type definition onprop
.I'm sure I'm missing things however. What do you think @xaviergonz @sisp ?
The text was updated successfully, but these errors were encountered: