mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
1f40f113aa
closes #334 closes #336 closes #338 closes #339 closes #341 closes #342 closes #343 closes #346 closes #348
707 B
707 B
🦉 Observer 🦉
Owl needs to be able to react to state changes. For example, whenever the state of a component is changed, we need to rerender it. To help with that, we have an Observer class. Its job is to observe some object state, and react to any change. To do that, it recursively replaces all keys of the observed state by getters and setters.
For example, this code will display update in the console:
const observer = new owl.Observer();
observer.notifyCB = () => console.log("update");
const obj = observer.observe({ a: { b: 1 } });
obj.a.b = 2;
The observer is implemented with the native Proxy object. Note that this
means that it will not work on older browsers.