The array is not a DOM element:
array = [0, 0, 0, 0, 0];
It's just hanging out in index.js for now. User clicks, fetch calls, etc. can change it. I want to somehow cause any change in the array to trigger a function call. Something like this:
when array.changesInAnyWay(){
doSomething();
}
Context:
-I think RxJS and thus observables require REACT, which I can't use for this project. I spent a lot of time trying to apply the observer pattern but it only broke the page and feels overkill anyway. -Similar limitation for MobX. I'm just using vanilla JS.
I think proxies should be a good solution, but I am having a hard time figuring out how to apply them to my code. I tried imitating what I found in discussions like these, but neither worked.
Detecting changes in a Javascript array using the Proxy object https://codeburst.io/understanding-javascript-proxies-by-examining-on-change-library-f252eddf76c2
I spent two hours trying to implement the latter with this:
const onChange = require('./js/on-change');
const foo = onChange({
a: generalArray
}, () => console.log(foo));
Can anyone nudge me (or write!) some actual code that works? I've been Googling & trying things all week.