-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Computed triggering the creation of an observable map invariant failed #798
Comments
Ahhhhhh, snap. My example works with Mobx 2.7.0. |
Hmm yes this is caused by observableMap with initial values causing the |
N.B. I think the following might work around this issue:
|
I've tried working your suggestion into my fiddle every which way I can think of and it's still throwing. |
Digging into the source (Yeah, I know Ruby and Typescript? What has the world come to!) It looks like you're setting |
Yeah now that i think of it, i don't think it will work this way. But i
hope the charm of TS gets you in the mean time 😊
Op di 24 jan. 2017 23:27 schreef Matt Ruby <[email protected]>:
… Digging into the source (Yeah, I know Ruby and Typescript? What has the
world come to!) It looks like you're setting allowStateChanges for me.
I'm still working my way through how that works and why the second run
doesn't.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#798 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABvGhKrJRQrAF3ZGeURPduRhwomTRIx7ks5rVnrdgaJpZM4LsfQz>
.
|
O, I'm enjoying myself. The rabbit hole is both deep and wide over here! Anyhow, would wrapping the:
|
…#798 Altered the initial map.merge to really be untracked.
OK, I liked my |
I think I'm way off... I'm going to hit the same issue with |
Could you try: |
That does fix the issue. And I see that you've worked my test case in already. However, my real use case runs much much deeper than the example where I'm creating my form handlers based on those computeds. As those handlers are built they will use |
@mweststrate Crazy! I just isolated my issue. Please see my fiddle here for a very simple example: https://jsfiddle.net/7tfswdxt/1/ I'm overwriting or wrapping an existing map entry before returning the object. Mobx is throwing:
PS: I'll create a new unit test on your branch! |
…#798 Added a map.set into the test case. The tests are now broken.
Wrapping |
But that is probably vague, let's see if we can do without.. (if not in strict mode) |
See also #563 Proposal to change the state modification guard to the following behavior: Changing a piece of state is only allowed if any of the following conditions are met:
For reference, the current behavior of the guard is: |
I think your proposal will work well! Let me know if I can help in any way.
…On Wed, Feb 1, 2017 at 5:50 AM, Michel Weststrate ***@***.***> wrote:
See also #563 <#563>
Proposal to change the state modification guard to the following behavior:
Changing a piece of state is only allowed if any of the following
conditions are met:
- (!strict mode || in action) && (!in computed || no observers)
(supports return *new* observables from a derivation
- observable created in same tick && no observers (support creating
and initializing observables in constructors, without marking constructor
as @action (which is not possible)
For reference, the current behavior of the guard is: (!strict mode || in
action) && (!in computed)
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#798 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAIrcj90DAp78CcZSs4cSkp3IZKDMDl8ks5rYHFqgaJpZM4LsfQz>
.
--
-Matt Ruby-
[email protected]
|
Just to make things clear - please correct me if I am wrong: @computed
get user() {
return new ObservableUser({ cart: this.cart });
} There are two inconveniences though - the constructor can't modify observables (even outside of strict mode) and can't invoke any actions (which is kind of the same thing). So the guard is not about returning new observables, but it allows mutating unobserved state from derivation (the action si required in strict mode, but has no practical use in this case). However I am not sure if this should be a fix for this particular issue - imho the ObservableMap simply shoudn't call any actions (modify state) during it's initialization in the first place. |
@urugator your observations are largely correct. So there are some things that could be improved, and all relate to each other
So the proposal is roughly
|
Ok, I think the current solution is overly complicated, both from technical perspective and to explain. I think it could simply work by changing the semantics to:
It basically means strict mode is relaxed to only protect observed state. This avoids jumping through hoops when creating and initializing new state as described in this issue and #563. |
Changes can be tested with |
Looks good to me! |
Released as 3.1.0 :) |
I'm having issues with computeds and observable map creation.
I have a very simple test case here: https://jsfiddle.net/7e6Ltscr/
I get the following error:
The text was updated successfully, but these errors were encountered: