## Monitoring With Observers Lightview supports the observer programming paradigm, a powerful mechanism for responding to changes across one or more variables. To create an observer, wrap a function that references the reactive variables you want to monitor in a call to `observe`. Any time the value of one of the variables changes, the function will be called. You can cancel an observer by assigning the return value of `observe` to a variable and calling `cancel()` on that value. This can be much simpler than setting up event listeners. *Note*: In this example we only reference one reactive variable, but you can reference as many as you wish. One observer can take the place of multiple event listeners. Try pasting this code as the REPL body. ```javascript ${command||""}
${x}:${y} ``` And, paste this as the REPL script: ```javascript currentComponent.mount = function() { this.variables({x:"number",y:"number",command:"string"},{reactive}); x = 0; y = 6; let previousx, previousy; let t1, t2; const observer = observe(() => { if(x!==y) { if(x!==previousx) { previousx = x; t1 = setTimeout(() => y--,1000); } if(y!==previousy) { previousy = y; t2 = setTimeout(() => x++,1000); } } else { command = "stop!"; clearTimeout(t1); clearTimeout(t2); observer.cancel(); } }); } ```