Une Bévue
1/11/2015 10:16:00 AM
say, I've an Object :
var org_ytho_controller = Object.create(null);
with the 'categories' attribute :
org_ytho_controller.categories = 'Android BIOS CSS'.split(' ');
and I observe this Object by:
var org_ytho_controllerChanges = function(changes) {
document.getElementById('log').innerHTML += "changes.length
= " + changes.length + "" + "\n";
changes.forEach(function(change) {
var txt = "change.type = '" + change.type + "', ";
txt += "change.name = '" + change.name + "', ";
txt += "change.oldValue = '" + change.oldValue + "'";
document.getElementById('log').innerHTML += txt + "\n";
});
console.log("changes:");
console.dir(changes);
}
Object.observe(org_ytho_controller, org_ytho_controllerChanges);
(Notice the element with id "log" is a pre one.)
when the changes are done like that :
org_ytho_controller.categories[org_ytho_controller.categories.length] =
'Another Category';
org_ytho_controllerChanges(changes) report nothing.
then i thought, this is because org_ytho_controller.categories is still
an Array, the no change.
However changing like that :
var a = org_ytho_controller.categories;
org_ytho_controller.categories = null;
a[a.length] = 'Another Category';
org_ytho_controller.categories = a;
Then, org_ytho_controllerChanges(changes) report 2 changes :
change.type = 'update', change.name = 'categories', change.oldValue =
'Android BIOS CSS Another Category'
change.type = 'update', change.name = 'categories', change.oldValue = 'null'
the NEW value 'Android BIOS CSS Another Category' coming as an oldValue ???
may be the sole workaround could be to add a length property :
org_ytho_controller.categoriesLength =
org_ytho_controller.categories.length;
and update it each time org_ytho_controller.categories is updated :
org_ytho_controller.categories[org_ytho_controller.categories.length] =
'Another Category';
org_ytho_controller.categoriesLength =
org_ytho_controller.categories.length;
BUT the Array could be changed without affecting the number of
categories, for example:
org_ytho_controller.categories[1] = 'SBIOS'; // BIOS -o-> SBIOS
org_ytho_controller.categoriesLength =
org_ytho_controller.categories.length; // no change here...