Skip to content

Commit

Permalink
Fix a couple deprecations and update Ember CLI Babel
Browse files Browse the repository at this point in the history
The `errors.unknownProperty` accessor would initialise the property
on every attempt to access. If this happens more than once during a
render cycle, newer Ember will complain since it is highly inefficient.
See emberjs/ember.js#13948 for more details.

Also removes the use of the `getOwner` polyfill, which was added
natively to `Ember.getOwner` in Ember 2.3.

Lastly updates the dependency on `ember-cli-babel` to be in line with
newer Ember CLI requirements.
  • Loading branch information
fdanielsen committed Nov 4, 2021
1 parent 2bc04f0 commit 4418b36
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
7 changes: 4 additions & 3 deletions addon/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ const {
A: emberArray,
Object: EmberObject,
get,
set
set,
run
} = Ember;

export default EmberObject.extend({
unknownProperty(property) {
set(this, property, emberArray());
return get(this, property);
run.once(() => set(this, property, emberArray()));
return emberArray();
}
});
11 changes: 5 additions & 6 deletions addon/mixin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Ember from 'ember';
import Errors from 'ember-validations/errors';
import Base from 'ember-validations/validators/base';
import getOwner from 'ember-getowner-polyfill';

const {
A: emberArray,
Expand All @@ -19,7 +18,7 @@ const {
} = Ember;

const setValidityMixin = Mixin.create({
isValid: computed('validators.@each.isValid', function() {
isValid: computed('validators.@each.isValid', function () {
let compactValidators = get(this, 'validators').compact();
let filteredValidators = compactValidators.filter((validator) => !get(validator, 'isValid'));

Expand All @@ -29,7 +28,7 @@ const setValidityMixin = Mixin.create({
isInvalid: not('isValid')
});

const pushValidatableObject = function(model, property) {
const pushValidatableObject = function (model, property) {
let content = get(model, property);

model.removeObserver(property, pushValidatableObject);
Expand All @@ -41,8 +40,8 @@ const pushValidatableObject = function(model, property) {
}
};

const lookupValidator = function(validatorName) {
let owner = getOwner(this);
const lookupValidator = function (validatorName) {
let owner = Ember.getOwner(this);
let service = owner.lookup('service:validations');
let validators = [];
let cache;
Expand Down Expand Up @@ -118,7 +117,7 @@ export default Mixin.create(setValidityMixin, {
this.buildValidators();

this.validators.forEach((validator) => {
validator.addObserver('errors.[]', this, function(sender) {
validator.addObserver('errors.[]', this, function (sender) {
let errors = emberArray();

this.validators.forEach((validator) => {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
"ember-addon"
],
"dependencies": {
"ember-cli-babel": "^5.1.6",
"ember-getowner-polyfill": "^1.0.0"
"ember-cli-babel": "^6.6.0"
},
"ember-addon": {
"configPath": "tests/dummy/config"
Expand Down

0 comments on commit 4418b36

Please sign in to comment.