Skip to content
This repository was archived by the owner on Jan 31, 2019. It is now read-only.

Commit df62c2f

Browse files
committed
Aggregated all on('init') calls into one function
1 parent 4f9d8a4 commit df62c2f

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

addon/validators/base.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,32 @@ export default Ember.Object.extend({
1313
};
1414
this.model.addObserver(this.property, this, this._validate);
1515
},
16-
addObserversForDependentValidationKeys: Ember.on('init', function() {
16+
AfterInit: Ember.on('init', function() {
17+
this._validate();
18+
this.pushDependentValidationKeyToModel();
19+
this.pushConditionalDependentValidationKeys();
20+
this.addObserversForDependentValidationKeys();
21+
}),
22+
addObserversForDependentValidationKeys: function() {
1723
this.dependentValidationKeys.forEach(function(key) {
1824
this.model.addObserver(key, this, this._validate);
1925
}, this);
20-
}),
21-
pushConditionalDependentValidationKeys: Ember.on('init', function() {
26+
},
27+
pushConditionalDependentValidationKeys: function() {
2228
Ember.A(['if', 'unless']).forEach((conditionalKind) => {
2329
const conditional = this.conditionals[conditionalKind];
2430
if (typeof(conditional) === 'string' && typeof(this.model[conditional]) !== 'function') {
2531
this.dependentValidationKeys.pushObject(conditional);
2632
}
2733
});
28-
}),
29-
pushDependentValidationKeyToModel: Ember.on('init', function() {
34+
},
35+
pushDependentValidationKeyToModel: function() {
3036
var model = get(this, 'model');
3137
if (model.dependentValidationKeys[this.property] === undefined) {
3238
model.dependentValidationKeys[this.property] = Ember.A();
3339
}
3440
model.dependentValidationKeys[this.property].addObjects(this.dependentValidationKeys);
35-
}),
41+
},
3642
call: function () {
3743
throw 'Not implemented!';
3844
},
@@ -56,7 +62,7 @@ export default Ember.Object.extend({
5662
}
5763
});
5864
},
59-
_validate: Ember.on('init', function() {
65+
_validate: function() {
6066
this.errors.clear();
6167
if (this.canValidate()) {
6268
this.call();
@@ -66,7 +72,7 @@ export default Ember.Object.extend({
6672
} else {
6773
return Ember.RSVP.resolve(false);
6874
}
69-
}),
75+
},
7076
canValidate: function() {
7177
if (typeof(this.conditionals) === 'object') {
7278
if (this.conditionals['if']) {

0 commit comments

Comments
 (0)