Files
owl/doc/observer.md
T
Géry Debongnie 1f40f113aa [DOC] update the documentation
closes #334
closes #336
closes #338
closes #339
closes #341
closes #342
closes #343
closes #346
closes #348
2019-10-17 12:08:24 +02:00

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.