nx-js / observer-util

Transparent reactivity with 100% language coverage. Made with ❤️ and ES6 Proxies.
MIT License
1.2k stars 94 forks source link

Problem when changing whole objects #37

Closed ciaoben closed 4 years ago

ciaoben commented 5 years ago

I am using a library that basically thin wrap this utility: react-easy-state. It seems that re-assigning a new object to an observable property do not trigger the change.

Is there any special case?? Here is a simplification of what is happening to me.. I would like to have some suggestion of what can be wrong or I can debug this. Can't wrap my head around this problem:

// Component A
const A => view(() => <div>{store.nestedObject.title}</div>)

// Component B = this way DOES NOT WORK! Component A does not update
class A extends React.Component {

  updateNested = () => {
    store.nestedObject = object // => this is a big object I receive from server
  }

  render() {
    return <button onClick={this.updateNested}>click me</button>
  }
}

// Component B = this way WORK! Component A does UPDATE!!
class A extends React.Component {

  updateNested = () => {
    store.nestedObject.title = object.title // different approach that works
  }

  render() {
    return <button onClick={this.updateNested}>click me</button>
  }
}

It seems to not detect when I change the whole object

solkimicreb commented 5 years ago

Hi! Is that the exact reproduction (or you left out some other code)? This example should work and it does work: https://codesandbox.io/s/oolzowkk0y Could you give me access to the original code or post a bigger snippet here?