It is relatively trivial to watch for changes in an array in Javascript.
One method I use is like this:
// subscribe to add, update, delete, and splice changes
Array.observe(viewHelpFiles, function(changes) {
// handle changes... in this case, we'll just log them
changes.forEach(function(change) {
console.log(Object.keys(change).reduce(function(p, c) {
if (c !== "object" && c in change) {
p.push(c + ": " + JSON.stringify(change[c]));
}
return p;
}, []).join(", "));
});
});
However, I have recently read that Array.observe
is deprecated and we should use the proxy object instead.
How can we detect changes in an array the Proxy object? I am unable to find any examples, anyone interested in elaborating?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…