Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add some model extensions for attributes

  • Loading branch information...
commit bee7f2968dd5041f41557d54da66cf552dd82885 1 parent 8eb525b
@bschaeffer authored
View
3  packages/ember-ohm/lib/attributes.js
@@ -1,4 +1,5 @@
require('ember-ohm/attributes/namespace');
require('ember-ohm/attributes/changes');
require('ember-ohm/attributes/attribute');
-require('ember-ohm/attributes/array_attribute');
+require('ember-ohm/attributes/array_attribute');
+require('ember-ohm/attributes/model_ext');
View
45 packages/ember-ohm/lib/attributes/model_ext.js
@@ -0,0 +1,45 @@
+/**
+ @module ember-ohm
+*/
+
+/**
+ @class Ohm.Model
+*/
+Ohm.Model.reopen({
+ /**
+ The `id` property of the model.
+
+ For some reason, in my projects, this has generally been a `readonly`
+ attribute. Therfore, it's defined that way here by default.
+
+ **Note for agitators:** Pull requests welcome.
+
+ @property id
+ @type Number
+ */
+ id: Ohm.attr('number', {readonly: true}),
+
+ /**
+ `isDirty` defines whether any of the model's attributes defined using one
+ of the `Ohm` attribute methods have changed.
+
+ Privately, it is computed from the length of the model's
+ {{#crossLink "Ohm.Attributes.Changes"}}changes{{/crossLink}}.
+
+ **This property should never, ever, ever in it's life be `set`.**
+
+ @property isDirty
+ @type Boolean
+ */
+ isDirty: Ember.computed.gte('_changes.map.length', 1),
+
+ /**
+ `isClean` is simply computed from `Ember.computed.not('isDirty')`.
+ Using basic maths, this is the opposite of
+ {{#crossLink "Ohm.Model/isDirty:property"}}`isDirty`{{/crossLink}}.
+
+ @property isClean
+ @type Boolean
+ */
+ isClean: Ember.computed.gte('_changes.map.length', 1)
+});
Please sign in to comment.
Something went wrong with that request. Please try again.