modella/modella — pull request #13 by rschmukler (2013-06-16 01:11:41+00:00)
Title: Better Dirty Checking, add type util, and clone on accessor

This PR does a few things:

1) Better dirty checking. It now detects differences in arrays and objects, in addition to primitives.

2) Added the `type.js` utility. This is component/type. Also exposed it to `Modella.utils` in case plugins might find it useful. (For example, `modella/validators` can be refactored to use this.

3) Made it so that the accessor method returns a clone of the object, instead of a direct pointer. Initially this felt a little weird, but now that I think about it we don't want to return the pointer to `model.attrs[field]`, otherwise it encourages direct manipulation of that (doesn't matter with primitives, but with objects and arrays we dont want people mutating that directly, we want them using `model.field(newVal)`. This also enables dirty checking to work, as if it was returning the original pointer, it would be difficult to see if it had changed unless the author cloned it themselves before mutating using the setter.

@yields and @MatthewMueller since 3 is sort of a big point, I'd appreciate your guys agreement with what I did, or a reason not to accept it.