dustingetz / react-cursor

Immutable state for React.js
1.03k stars 50 forks source link

Observe Cursor.value for mutations and throw an error if any are detected #56

Closed danielmiladinov closed 8 years ago

lijunle commented 9 years ago

@danielmiladinov Is Object.observe deeply observe the object? If yes, maybe great to use Object.observe.

Object.freeze only freeze the first level properties. For deeply freeze, MDN provide a performance-affecting snippet.

Besides, is there a way to do such validation in debug mode only? (Future implementation is OK for this.)

dustingetz commented 9 years ago

+1 on doing all these performance-impacting things in debug mode only

danielmiladinov commented 9 years ago

@lijunle See the tests, any mutations to refined cursor values, even when they're scalars, do cause the root cursor's value's mutation to be observed. Object.freeze still remains a worthy alternative to explore, and I'm also in favor of only performing Object.observe in debug mode.

lijunle commented 9 years ago

@danielmiladinov I am OK with Object.observe. Seeing from the ES7 supporting table, only Chrome supports it. (Opera is not tested in the table.)

Then, say something like this in README: In debug mode, it will block and throws an exception when mutate cursor object. (Only support Chrome browser).

dustingetz commented 8 years ago

We went with object.freeze approach - closing this unmerged