mobxjs / mobx

Simple, scalable state management.
http://mobx.js.org
MIT License
27.54k stars 1.77k forks source link

Values with prototypes #2299

Closed thepian closed 4 years ago

thepian commented 4 years ago

Intended outcome:

class State {
@observable dashboard:
@computed get widget() { return dashboard.widget; }
}

state.dashboard = { widget: makeWidget() };

function makeWidget() {
return Object.assign(Object.create({ x: 'default', y: 'default' }), { title: '' });
}

I would not expect dashboard.widget.x to be "default"

Actual outcome:

I would not expect dashboard.widget.x to be "default", but it is undefined as the prototype is thrown away.

How to reproduce the issue:

https://codesandbox.io/s/nice-khorana-lwnxu

danielkcz commented 4 years ago

Would this work for you? https://codesandbox.io/s/angry-ptolemy-yiu6e

I mean you had obvious bug there not binding setWidget, but I don't see any problem after fixing that.

thepian commented 4 years ago

Interesting it seems to work. We must be doing something wrong elsewhere in our codebase.

lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs or questions.