Authors:Akira Sudoh, Ed Chatelain
Developers:Akira Sudoh, Ed Chatelain

dojox/mvc/StatefulArray is a class that inherits JavaScript native Array class, adding dojo/Stateful capability. The dojox/mvc/StatefulArray class can be created in below form:

new StatefulArray([0, 1, 2]);

Watch callbacks

dojox/mvc/StatefulArray has watch() function that works in the same way as the one in dojo/Stateful. The change in array length, as well as updates in array element, will be reflected to such watch callbacks. dojox/mvc/StatefulArray also has watchElements() function, that allows to watch for removals/adds of array elements. Like watch() function, watchElements() function returns a handle that allows disconnection of the watch at some point in future. For example:

require(["dojox/mvc/StatefulArray"], function(StatefulArray){
    var a = new StatefulArray([0, 1, 2]);
    var handle = a.watchElements(function(index, removals, adds){
        alert("Removed: " + removals + " At: " + index);
    a.shift(); // Caused an alert box as the change of a is being watched
    a.shift(); // Does not cause an alert box as the change of a is no longer being watched
Error in the documentation? Can’t find what you are looking for? Let us know!