Skip to content

Commit

Permalink
Remove isDirty (#580)
Browse files Browse the repository at this point in the history
  • Loading branch information
offirgolan authored Apr 2, 2018
1 parent 1d4bd95 commit e7616ed
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 86 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ __No observers were used nor harmed while developing and testing this addon.__
- I18n support
- Debounceable validations
- Warning validations
- Dirty tracking

[![Introduction to Ember CP Validations](https://cloud.githubusercontent.com/assets/2922250/21854491/ebda55b8-d7e8-11e6-8d13-00dff93be8d8.png)](https://embermap.com/video/ember-cp-validations)

Expand Down
35 changes: 2 additions & 33 deletions addon/-private/internal-result-object.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import EmberObject, { computed, set, get } from '@ember/object';
import { and, not, readOnly } from '@ember/object/computed';
import { isNone } from '@ember/utils';
import { makeArray } from '@ember/array';
import EmberObject, { defineProperty, computed, set, get } from '@ember/object';

import Ember from 'ember';
import ValidationError from '../validations/error';
import { isDsModel, isPromise } from '../utils/utils';

const { canInvoke } = Ember;
import { isPromise } from '../utils/utils';

export default EmberObject.extend({
model: null,
Expand All @@ -17,20 +13,13 @@ export default EmberObject.extend({
warningMessage: null,
attribute: '',

attrValue: null,
_promise: null,
_validator: null,
_type: readOnly('_validator._type'),

init() {
this._super(...arguments);

defineProperty(
this,
'attrValue',
readOnly(`model.${get(this, 'attribute')}`)
);

if (this.get('isAsync')) {
this._handlePromise();
}
Expand All @@ -46,26 +35,6 @@ export default EmberObject.extend({
return isPromise(get(this, '_promise'));
}),

isDirty: computed('attrValue', function() {
let model = get(this, 'model');
let attribute = get(this, 'attribute');
let attrValue = get(this, 'attrValue');

// Check default model values
if (isDsModel(model) && canInvoke(model, 'eachAttribute')) {
let attrMeta = model.get('constructor.attributes').get(attribute);

if (attrMeta) {
let { defaultValue } = attrMeta.options;

if (!isNone(defaultValue)) {
return defaultValue !== attrValue;
}
}
}
return !isNone(attrValue);
}),

messages: computed('message', function() {
return makeArray(get(this, 'message'));
}),
Expand Down
7 changes: 0 additions & 7 deletions addon/-private/result.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,6 @@ const Result = EmberObject.extend({
*/
isAsync: readOnly('_result.isAsync'),

/**
* @property isDirty
* @readOnly
* @type {Boolean}
*/
isDirty: readOnly('_result.isDirty'),

/**
* @property message
* @readOnly
Expand Down
1 change: 0 additions & 1 deletion addon/validations/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ function createTopLevelPropsMixin(validatableAttrs) {
let aliases = [
'isValid',
'isValidating',
'isDirty',
'isAsync',
'isNotValidating',
'isInvalid',
Expand Down
18 changes: 0 additions & 18 deletions addon/validations/result-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,6 @@ export default ArrayProxy.extend({
*/
isTruelyInvalid: isAny('content', 'isTruelyInvalid', true, false).readOnly(),

/**
* Will be true is the attribute in question is not `null` or `undefined`. If the object being
* validated is an Ember Data Model and you have a `defaultValue` specified, then it will use that for comparison.
*
* ```javascript
* // Examples
* // 'username' : DS.attr('string', { defaultValue: 'johndoe' })
* get(user, 'validations.isDirty')
* get(user, 'validations.attrs.username.isDirty')
* ```
*
* @property isDirty
* @default false
* @readOnly
* @type {Boolean}
*/
isDirty: isAny('content', 'isDirty', true, false).readOnly(),

/**
* Will be `true` only if a validation returns a promise
*
Expand Down
20 changes: 0 additions & 20 deletions tests/unit/validations/ds-model-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ module('Unit | Validations | DS.Model', function(hooks) {
this.owner.lookup('service:store').createRecord('signup')
);

assert.equal(
object.get('validations.attrs.acceptTerms.isDirty'),
false,
'isDirty was expected to be FALSE'
);
assert.equal(
object.get('validations.attrs.acceptTerms.isValid'),
false,
Expand All @@ -25,11 +20,6 @@ module('Unit | Validations | DS.Model', function(hooks) {
object.set('acceptTerms', true);
});

assert.equal(
object.get('validations.attrs.acceptTerms.isDirty'),
true,
'isDirty was expected to be TRUE'
);
assert.equal(
object.get('validations.attrs.acceptTerms.isValid'),
true,
Expand All @@ -44,11 +34,6 @@ module('Unit | Validations | DS.Model', function(hooks) {
.createRecord('signup', { acceptTerms: true })
);

assert.equal(
object.get('validations.attrs.acceptTerms.isDirty'),
true,
'isDirty was expected to be TRUE'
);
assert.equal(
object.get('validations.attrs.acceptTerms.isValid'),
true,
Expand All @@ -59,11 +44,6 @@ module('Unit | Validations | DS.Model', function(hooks) {
object.set('acceptTerms', false);
});

assert.equal(
object.get('validations.attrs.acceptTerms.isDirty'),
false,
'isDirty was expected to be FALSE'
);
assert.equal(
object.get('validations.attrs.acceptTerms.isValid'),
false,
Expand Down
9 changes: 3 additions & 6 deletions tests/unit/validators/dependent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ module('Unit | Validator | dependent', function(hooks) {
});

test('all empty attributes', function(assert) {
assert.expect(5);
assert.expect(4);

options = defaultOptions;
builtOptions = Validator.buildOptions(options);

model = setupObject(this, EmberObject.extend(Validations));

assert.equal(get(model, 'validations.isValid'), false);
assert.equal(get(model, 'validations.isDirty'), false);

message = Validator.validate(undefined, builtOptions.toObject(), model);

Expand All @@ -53,7 +52,7 @@ module('Unit | Validator | dependent', function(hooks) {
});

test('one dependent error', function(assert) {
assert.expect(5);
assert.expect(4);

options = defaultOptions;
builtOptions = Validator.buildOptions(options);
Expand All @@ -63,7 +62,6 @@ module('Unit | Validator | dependent', function(hooks) {
});

assert.equal(get(model, 'validations.isValid'), false);
assert.equal(get(model, 'validations.isDirty'), true);

message = Validator.validate(undefined, builtOptions.toObject(), model);

Expand All @@ -73,7 +71,7 @@ module('Unit | Validator | dependent', function(hooks) {
});

test('no dependent errors', function(assert) {
assert.expect(5);
assert.expect(4);
options = defaultOptions;
builtOptions = Validator.buildOptions(options);

Expand All @@ -83,7 +81,6 @@ module('Unit | Validator | dependent', function(hooks) {
});

assert.equal(get(model, 'validations.isValid'), true);
assert.equal(get(model, 'validations.isDirty'), true);

message = Validator.validate(undefined, builtOptions.toObject(), model);

Expand Down

0 comments on commit e7616ed

Please sign in to comment.