Skip to content
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

After upgrading to 5.0.0, ObservableMap.size is no longer reactive #1583

Closed
roostapour opened this issue Jun 8, 2018 · 4 comments
Closed

Comments

@roostapour
Copy link

I am using MobX+React in my project. I upgraded the MobX to 5.0.0 yesterday and my code does not work anymore. Here is an example of how I use MobX:

AppStore.ts:

class Store {
@observable elements: Map<string, Element> = new Map<string, Element>();

@action addElement (ID, color) {
   this.elements.set(ID, new Element(ID, color)
 }
}

class Element {
@observable ID: string;
@observable color: string;
...
}

main.tsx:

ReactDOM.render(
        <Provider appStore={appStore}>
            <App />
        </Provider>,
        document.getElementById("app"));

App.tsx:

@inject("appStore")
@observer
export class App extends React.Component<any, any> {
render() {
return (<div>
              <Selector/>
              <Data/>
        </div>);
}
}

Selector.tsx:

@inject("appStore")
@observer
export class Selector extends React.Component<any, any> {
onSelect(id, color){
    this.props.appStore.addElement(id, color);
}
}

Data.tsx:

@inject("appStore")
@observer
export class Data extends React.Component<any, any> {
render() {
var elements = this.props.appStore.elements;
return (<div>
             {elements}
         </div>);
}
}

Before, when I select something in selector, it adds a new element to the appstore elements and the render function of Data gets called and shows the elements including the new one. But after the upgrade, by selecting and adding an element the Data's render() doesn't get called! Any idea what can be the problem?

Here are my packages:
"mobx": "^5.0.0"
"mobx-react": "^5.2.1"
"mobx-utils": "^5.0.0"

@mweststrate
Copy link
Member

mweststrate commented Jun 8, 2018 via email

@roostapour
Copy link
Author

@mweststrate Sure. I added the example here: https://codesandbox.io/s/0o6vxpzjr0

If you switch between "mobx": "^5.0.0" and "mobx": "^4.3.1" you will see that the first one does not show the updated size of the elements (always zero, renders the Data only once) but the next one dose it correctly.

@urugator
Copy link
Collaborator

urugator commented Jun 9, 2018

@mweststrate map.size is not reactive in v5, here is a small repro: https://codesandbox.io/s/5y7j2x0nx

@mweststrate mweststrate changed the title Upgraded to 5.0.0 and my code doesn't work! After upgrading to 5.0.0, ObservableMap.size is no longer reactive Jun 11, 2018
@mweststrate
Copy link
Member

Thanks for the report @roostapour and analysis @urugator! Released a fix as 5.0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants