Shopify/batman — pull request #643 by jamesmacaulay (2013-02-05 03:38:56+00:00)
Title: Fix model arrays as hash keys

@hornairs and @kristianpd please review

This patch fixes an issue caused when an array is used as the key of a `Hash` or `SimpleHash`. Basically, `Array::toString` changes whenever the array itself is mutated, and it uses whatever `toString` is implemented for each of its contained items.

`Batman.Model::toString` happens to include the model's `id` (which changes from `undefined` when a new model is first saved). The issue was first discovered when rendering a set of models using the `inGroupsOf` function: each sub-array became a key in an `IteratorBinding`'s `nodeMap`, and all hell broke loose whenever one of the models was saved.

This solution ends up making it so that all arrays simply use `"[object Array]"` as their hash key. This is just like using POJOs for keys, which all use `"[object Object]"`. Unfortunately the result is that lookup time for arrays, like that for POJOs, is O(n), where n is the number of array keys in the hash. The nice thing about it, though, is that the array no longer needs to be iterated over to _calculate_ its hash key...previous to this patch, the complexity of both getting _and setting_ array keys would presumably have been O(m), where m is the number of elements in the array key.