Hi Simon,
Before, I tried something similar. Array manipulation functions were wrapped to send updates to functions over arrays, and I also played with a more incremental version that would track changes to individual array elements. The latter was important for incremental optimization, but seemed too hard to use.
The important parts seems to be a) consistent maintenance of identity via detecting *all* array manipulations (arr[i] = v, arr.push(v), ..) and b) controlling when imperative reactions should occur (bundling a transaction).
Essentially, I can imagine supporting interactions like
var arr = [1,2,3];
var arrB = arrayObserverB(rawA);
var lenB = arrB.liftB(count);
arrB.push(1); //raw arr gets an extra entry and lenB increases in length
arr.push(2); //raw arr gets an extra entry, but lenB has not increased
fx.update(arr); //lenB and any other dependent behaviors update
var arr2 = arrB.identity; //get underlying array
arr2.push(2); //arbitrar imperative manipulations
fx.update(arr2) //batch update
I suspect the new proxy and weak map APIs would be helpful:
In a similar spirit to "arrayObserverB", we can probably add "objectObserverB()".
Happy holidays,
- Leo
If there are other newbies like me who found this question useful; this is a less complex approach:
<script type = "text/javascript">
var arrays = new Object();
arrays.rooms = [];