Skip to content
This repository has been archived by the owner on Dec 31, 2020. It is now read-only.

Question: should observer always apply pure? #160

Closed
mweststrate opened this issue Nov 14, 2016 · 3 comments
Closed

Question: should observer always apply pure? #160

mweststrate opened this issue Nov 14, 2016 · 3 comments

Comments

@mweststrate
Copy link
Member

Currently observer tries do a shallow comparison on next available properties. However if there is a data structure (object) passed into the props which is not an observable object, mobx-react assumes it might have been deeply mutated (similar to the assumption react makes) and re-renders to not take any changes.

Sometimes this is confusing for people, as they might expect shallow / pure comparison always. Should this be changed? Is it worth the potential risk of accidentally optimizing too much renders away?

cc: @Strate @andykog @ConneXNL

@mweststrate
Copy link
Member Author

Ok, asking the question is answering it I think.

@andykog
Copy link
Member

andykog commented Nov 14, 2016

@mweststrate,

  1. This behaviour can be configurable like in redux connect.
  2. Or mobx-react can export pureRendering checker (or dirtyRendering depending on what to choose as a default behaviour, so one can use it like:
import observer, { pureRendering } from 'mobx-react';
observer(class extends Component {
  shouldComponentUpdate(...args) {
    return pureRendering(...args);
  }
  render() {}
})

I would be comfortable with pure by default

@mweststrate
Copy link
Member Author

Released as part of 4.0.0

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants