AriaFallah / mobx-store

A data store with declarative querying, observable state, and easy undo/redo.
MIT License
282 stars 9 forks source link

mobx-store with mobx-react #33

Closed ifokeev closed 8 years ago

ifokeev commented 8 years ago

I'm trying to use your beautiful code.

I check the code of mobx-react and think that if I add @observer(['store']) and will use Provider <Provider store={store} /> it will affect componentWillReceiveProps on every update of the store and render again all components that observe the store.

Am I wrong?

The same issue I added on mobx-react: https://github.com/mobxjs/mobx-react/issues/79

Also if use react-redux it will only update props that I mapped via mapStateToProps. Am I wrong with this too?

So the main question is how to prevent unneeded rerender

AriaFallah commented 8 years ago

@ifokeev I'm actually unsure about this and don't have much experience with it, but if you can find more information or the root cause I can definitely work on fixing it.

ifokeev commented 8 years ago

@AriaFallah as I understand all properties in your mobxstore are observable. So maybe it's a "feature" of the mobx-react, because it can't observes part of the object – it observes object at all.

mweststrate commented 8 years ago

observer should not rerender as long as you do not replace the store with another instance. ( the injected props are then shallowly the same still and shouldcomponentupdate will return false in that case). so observer will only rerender if you used some observable property of the store in your render method.

Op do 7 jul. 2016 17:39 schreef Aria Fallah notifications@github.com:

@ifokeev https://github.com/ifokeev I'm actually unsure about this and don't have much experience with it, but if you can find more information or the root cause I can definitely work on fixing it.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/AriaFallah/mobx-store/issues/33#issuecomment-231117603, or mute the thread https://github.com/notifications/unsubscribe/ABvGhJWeZa8pM-1XgizxIO0EHE8iaYD4ks5qTR2lgaJpZM4JHM21 .

ifokeev commented 8 years ago

@mweststrate

if you used some observable property of the store in your render method.

How can I check this in the code?

AriaFallah commented 8 years ago

@ifokeev

Have you tried https://github.com/mobxjs/mobx-react-devtools?

ifokeev commented 8 years ago

@AriaFallah

Have you tried https://github.com/mobxjs/mobx-react-devtools?

No, I'm trying to understand all of this. Now I understand that mobx will react only on properties in "trackable function" (i.e. render()). But I want to check it :)

AriaFallah commented 8 years ago

@ifokeev

Well the dev tools log into the console whenever something rerenders. You should™ be able to check it with them.

ifokeev commented 8 years ago

@mweststrate @AriaFallah thanks for your help and fast responses.