facebook/react — pull request #2283 by cirocosta (2014-10-02 03:19:42+00:00)
Title: (#2272) adds warning for setting state through `this.state`

As it was addressed by #2272 , it'd be nice if we could alert the dev when doing something which may lead to messy things (in this case, setting the state directly with `this.state`). In this PR i try to implement that feature by using ES5' `Object.defineProperty`. I'd like to know from you guys what do you think about this.

My approach is: keep an internal `_state` protected so that the user won't touch it without getting alerted when setting it directly (inside an `if __DEV__`). Getting from it is safe.

I first thought about doing this through ES6s Proxies, which is something that i though it'd do more sense (creating defensive objects), but AFAIK nowadays implementations are not efficient and it'd be an overhead (correct if i am wrong, please!).

What do you think? Thanks!