-
-
Notifications
You must be signed in to change notification settings - Fork 81
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
Feature/fix circular refs #128
Conversation
@godness84 I updated this branch with your code. I'm still getting issues in
I think this is the same issue I'm seeing on the toggle action in |
@chrisdrackett I pushed a new fix to my branch! I applied the same anti-circular-refs technique onto With that fix I pushed, it seems solved. 🤞 |
@godness84 ok, this is awesome!
|
It seems to work all right with my schema as well, awesome! The "self" casting is a bit strange but I can live with that for now. Although in this form it could be made compatible with future implementations:
Formulated this way the actions will always use "self" and if the implementation changes and we don't need But of course it is more typing and error prone to have a function and then return the object literal containing the func than just having an object literal as the function's result. |
About the
|
@chrisdrackett I updated my branch with a fix to pass tests! 😉 |
@beepsoft the only downside to your recommendation (as I understand it) is that it will give you a performance penalty as noted at the bottom of https://github.com/mobxjs/mobx-state-tree#using-a-mst-type-at-design-time |
@godness84 this looks good to me! I'd love at least one more person to review before we merge. Maybe @beepsoft or @zenflow can take a last look? |
@chrisdrackett Regarding the performance penalty issue, you are probably right. The PR seems to be OK for me, tests run all right and I've been using the models generated by feature/fixCircularRefs for a week or so now with no problem. |
@chrisdrackett @beepsoft is the performance penalty issue related to the use of the |
@godness84 No,
The MST docs say:
|
@beepsoft Mmm, I have some difficulties to understand 🤔 , maybe I'm missing something. What is your |
@godness84 Yes, it is the same |
@beepsoft Ok, understood. But if your example code suffers from performance penalties, even my code should suffer from it - they're very similar, you just cast self once and reuse it everywhere. Hope it's understandable what I wrote 😄 P.S. I tried to reproduce the issue described in the MST docs, but I failed: I could not see the |
19ed87d
to
e1d9650
Compare
@godness84 I went ahead and updated the example projects using this code. I'm running into issues in example 3 that I think are worth looking at before we merge. I'll note them inline now. |
/** | ||
* MessageModel | ||
*/ | ||
export const MessageModel = MessageModelBase.views(self => ({ | ||
get isLikedByMe() { | ||
return self.likes.includes(self.store.me) | ||
return as(self).likes.includes(self.store.me) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting Property 'likes' does not exist on type 'MessageModelType'.
here. Should this not work when using as()
?
if (self.likes.includes(self.store.me)) | ||
self.likes.remove(self.store.me) | ||
else self.likes.push(self.store.me) | ||
if (as(self).likes.includes(self.store.me)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above here.
} | ||
})) | ||
.actions(self => ({ | ||
afterCreate() { | ||
self.subscribeNewMessages({}, MESSAGE_FRAGMENT, message => { | ||
self.sortedMessages.unshift(message) | ||
as(self).sortedMessages.unshift(message) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
both sortedMessages
and message
are coming through as any
for me.
@@ -22,13 +26,13 @@ export const RootStore = RootStoreBase.props({ | |||
}) | |||
.views(self => ({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for some reason all the self
's on rootStore are giving me a Parameter 'self' implicitly has an 'any' type, but a better type may be inferred from usage.
I'm not sure if actually related to this PR, but I just found that in a Model's action, when I want to access the I have something like this:
Should this work? |
@chrisdrackett @beepsoft Uh oh, it looks like I fell down the rabbit hole of circular refs, but maybe I reached the top again. Maybe. The
To solve 1) it is enough to make explicit the result type.
While working on this, a different way of solving circular refs came to my mind. So far we have solved it by removing ref props from the type of the model and reintroducing them on the type of the model instance. But it caused us to use the I propose a different way: use type assertion directly on the model type ( How it works (few and ugly words):
I know it means we should start over, with a new PR, new updated examples and so on, but I think it's worth it! Let me know :) |
@godness84 I have no problem having a better solution without Now I tried your https://github.com/godness84/mst-gql/tree/feature/fixCircularRefs-safe branch and for me the generated models and all the So, what should we expect to have working in feature/fixCircularRefs-safe? |
Mmm, weird.
TS version? Do you a repo that I could try with?
Il gio 31 ott 2019, 21:47 beep <notifications@github.com> ha scritto:
… @godness84 <https://github.com/godness84> I have no problem having a
better solution without as(). :-) Although for me things seemed to work
with your previous solution as well.
Now I tried your
https://github.com/godness84/mst-gql/tree/feature/fixCircularRefs-safe
branch and for me the generated models and all the selfs are all of type
any at the moment. I've built mst-gql from your branch and npm linked to
my project and checked that I have safeRefs() in mst-gql and also in the
generated models.
So, what should we expect to have working in feature/fixCircularRefs-safe?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#128?email_source=notifications&email_token=AA5NBDOP2MZQY3BTMKEM45LQRM75PA5CNFSM4JCKXUX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECZGIFY#issuecomment-548561943>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA5NBDO63V54WGEEDJAKHRLQRM75PANCNFSM4JCKXUXQ>
.
|
TS 3.6.4 ("typescript": "^3.6.4"). I just did the build/npm link and run a clean generation like
with this schema: https://gist.github.com/beepsoft/84a64102a80a3ac7eb1f656b64fc2af8 Then checked the generated sources in my IDE and saw |
@beepsoft I tried your schema and it works for me. Sure that |
@beepsoft what happens if you try to scaffold the example projects in mst-gql repo? |
If I do the scaffolding in the mst-gql project, then in eg.
As a result this import line won't actually load
|
It means you have problems in linking or something. Did you launch yarn command in the root folder and in the example folder? |
@godness84 Ok, now I generated the model into the Now, with this schema https://gist.github.com/beepsoft/84a64102a80a3ac7eb1f656b64fc2af8 autocomplete seems to work (in VSCode better than in IntelliJ). One thing I found is that I had to make the type of the /**
* choicesModel
*/
export const choicesModel = choicesModelBase
.actions(self => ({
foo() {
self.poll.choices!.forEach((v: choicesModelType) => v.poll.created_at);
}
})) |
@godness84 @beepsoft sorry for the delay in chiming in on this, I've been pretty busy with other things! I haven't yet had time to try the new repo myself but it sounds really promising! @godness84 if you want to create a new PR here we can move discussion related to that work to its PR? |
I'll double check on monday that this indeed fixes #117. Great job @godness84 ! |
merge simple circular example with @godness84's circular ref fix.