You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having an issue which I'm struggling to troubleshoot. It seems as though computed values are preemptively evaluated before initial values to class member variables are assigned. At times it happens with all computed values and others it seems to only happen with Map computed values.
Here are some screen captures that I made to help demonstrate the problem. I'm triggering the exceptions by clicking the Props > store drop down for the Provider component.
I would expect that each of these computed values to not throw exceptions/instantiate new values when the store is inspected by dev tools.
Example Code
testStore.ts
import*asmobxfrom'mobx';import{observable,computed,runInAction}from'mobx';exportclassTestStore{
@observableprivate_bases!: mobx.IObservableArray<number>;constructor(){runInAction(()=>{this._bases=observable.array([0,1,2,3,4,5]);});}publicgetbases(): mobx.IObservableArray<number>{returnthis._bases;}
@computedpublicgetnumBases(): number{returnthis._bases.length;}
@computedpublicgetsumOfBases(): number{returnthis._bases.reduce((p: number,c: number)=>p+c);}
@computedpublicgetsquares(): Map<number,number>{letsqmp: Map<number,number>=newMap<number,number>([]);for(constbofthis._bases){sqmp.set(b,b*b);}returnsqmp;}// @computed public get squares(): Array<number> {// return this._bases.map((b: number) => b * b);// }}
I've searched the depth of Google, Stack Overflow, and MobX repositories to find answers, but have not found any closely related, documented (solved or not) issues or questions to the one I've outlined above.
Versions
Built from an ejected Create React App w/ react-scripts-ts.
Looks like that is a highly likely candidate. I'll start tracking the PR for that bug (facebook/react-devtools#569) and close this issue for now. If I'm still having issues after that gets merged and released I'll reopen 👍
Thanks for the second look! I can't believe I didn't think to look at the react-devtools repo 😅
Summary
I'm having an issue which I'm struggling to troubleshoot. It seems as though computed values are preemptively evaluated before initial values to class member variables are assigned. At times it happens with all computed values and others it seems to only happen with Map computed values.
Here are some screen captures that I made to help demonstrate the problem. I'm triggering the exceptions by clicking the
Props
>store
drop down for theProvider
component.I would expect that each of these computed values to not throw exceptions/instantiate new values when the store is inspected by dev tools.
Example Code
testStore.ts
testApp.tsx
index.tsx
I've searched the depth of Google, Stack Overflow, and MobX repositories to find answers, but have not found any closely related, documented (solved or not) issues or questions to the one I've outlined above.
Versions
Built from an ejected Create React App w/
react-scripts-ts
.The text was updated successfully, but these errors were encountered: