diff --git a/addon/index.js b/addon/index.js index 47ba42cd..8b6ba459 100644 --- a/addon/index.js +++ b/addon/index.js @@ -27,8 +27,6 @@ import Validator from './validations/validator'; * ```javascript * // models/user.js * - * import Ember from 'ember'; - * import DS from 'ember-data'; * import { validator, buildValidations } from 'ember-cp-validations'; * * const Validations = buildValidations({ @@ -60,6 +58,8 @@ import Validator from './validations/validator'; * ```javascript * // models/user.js * + * import Model from '@ember-data/model'; + * * export default Model.extend(Validations, { * 'username': attr('string'), * 'password': attr('string'), @@ -69,20 +69,20 @@ import Validator from './validations/validator'; * * ## Objects * - * You can also use the generated `Validations` mixin on any `Ember.Object` or child - * of `Ember.Object`, like `Ember.Component`. For example: + * You can also use the generated `Validations` mixin on any `EmberObject` or child + * of `EmberObject`, like `Component`. For example: * * ```javascript * // components/x-foo.js * - * import Ember from 'ember'; + * import Component from '@ember/component'; * import { validator, buildValidations } from 'ember-cp-validations'; * * const Validations = buildValidations({ * bar: validator('presence', true) * }); * - * export default Ember.Component.extend(Validations, { + * export default Component.extend(Validations, { * bar: null * }); * ``` @@ -90,14 +90,16 @@ import Validator from './validations/validator'; * ```javascript * // models/user.js * - * export default Ember.Object.extend(Validations, { + * import EmberObject from '@ember/object'; + * + * export default EmberObject.extend(Validations, { * username: null * }); * ``` * * ## A Note on Testing & Object Containers * - * To lookup validators, container access is required, which can cause an issue with `Ember.Object` creation + * To lookup validators, container access is required, which can cause an issue with `EmberObject` creation * if the object is statically imported. The current fix for this is as follows. * * **Ember < 2.3.0** @@ -105,9 +107,10 @@ import Validator from './validations/validator'; * ```javascript * // routes/index.js * + * import Route from '@ember/routing/route'; * import User from '../models/user'; * - * export default Ember.Route.extend({ + * export default Route.extend({ * model() { * const container = this.get('container'); * return User.create({ username: 'John', container }) @@ -120,12 +123,14 @@ import Validator from './validations/validator'; * ```javascript * // routes/index.js * + * import { getOwner } from '@ember/application'; + * import Route from '@ember/routing/route'; * import User from '../models/user'; * - * export default Ember.Route.extend({ + * export default Route.extend({ * model() { * return User.create( - * Ember.getOwner(this).ownerInjection(), + * getOwner(this).ownerInjection(), * { username: 'John' } * ); * } @@ -203,7 +208,6 @@ import Validator from './validations/validator'; * ``` * * ```javascript - * import Ember from 'ember'; * import { validator, buildValidations } from 'ember-cp-validations'; * * const Validations = buildValidations({ @@ -237,12 +241,15 @@ import Validator from './validations/validator'; * Please note that the `message` option of a validator can also be a function with [the following signature](http://adopted-ember-addons.github.io/ember-cp-validations/docs/modules/Validators.html#message). * * ```javascript + * import { computed } from '@ember/object'; + * import { not, readOnly } from '@ember/object/computed'; + * * const Validations = buildValidations({ * username: validator('length', { - * disabled: Ember.computed.not('model.meta.username.isEnabled'), - * min: Ember.computed.readOnly('model.meta.username.minLength'), - * max: Ember.computed.readOnly('model.meta.username.maxLength'), - * description: Ember.computed('model', 'attribute', function() { + * disabled: not('model.meta.username.isEnabled'), + * min: readOnly('model.meta.username.minLength'), + * max: readOnly('model.meta.username.maxLength'), + * description: computed('model', 'attribute', function() { * // CPs have access to the `model` and `attribute` * return this.get('model').generateDescription(this.get('attribute')); * }) @@ -255,7 +262,8 @@ import Validator from './validations/validator'; * When declaring object validations (not including Ember Data models), it is possible to validate child objects from the parent object. * * ```javascript - * import Ember from 'ember'; + * import Component from '@ember/component'; + * import { alias } from '@ember/object/computed'; * import { validator, buildValidations } from 'ember-cp-validations'; * * const Validations = buildValidations({ @@ -265,7 +273,7 @@ import Validator from './validations/validator'; * 'user.account.number': validator('number') * }); * - * export default Ember.Component.extend(Validations, { + * export default Component.extend(Validations, { * acceptTerms: false, * user: { * firstName: 'John', @@ -274,7 +282,7 @@ import Validator from './validations/validator'; * number: 123456, * } * }, - * isFormValid: Ember.computed.alias('validations.isValid'), + * isFormValid: alias('validations.isValid'), * }); * ``` * diff --git a/addon/utils/deep-set.js b/addon/utils/deep-set.js index 5ef1e964..4340ae9a 100644 --- a/addon/utils/deep-set.js +++ b/addon/utils/deep-set.js @@ -1,7 +1,7 @@ /** * Assigns a value to an object via the given path while creating new objects if * the pathing requires it. If the given path is `foo.bar`, it will create a new object (obj.foo) - * and assign value to obj.foo.bar. If the given object is an Ember.Object, it will create new Ember.Objects. + * and assign value to obj.foo.bar. If the given object is an EmberObject, it will create new EmberObjects. */ import { isDescriptor } from './utils'; import { isNone } from '@ember/utils'; diff --git a/addon/validations/factory.js b/addon/validations/factory.js index 50a6dac0..220c6d27 100644 --- a/addon/validations/factory.js +++ b/addon/validations/factory.js @@ -198,7 +198,7 @@ function normalizeOptions(validations = {}, globalOptions = {}) { * @param {Object} inheritedValidationsClass * @param {Object} validations * @param {Object} model - * @return {Ember.Object} + * @return {EmberObject} */ function createValidationsClass(inheritedValidationsClass, validations, model) { let validationRules = {}; @@ -307,7 +307,7 @@ function createValidationsClass(inheritedValidationsClass, validations, model) { * @param {Object} validatableAttributes * @param {Object} validationRules * @param {Object} model - * @return {Ember.Object} + * @return {EmberObject} */ function createAttrsClass(validatableAttributes, validationRules, model) { let nestedClasses = {}; diff --git a/addon/validators/base.js b/addon/validators/base.js index 33ce0a38..2c649609 100644 --- a/addon/validators/base.js +++ b/addon/validators/base.js @@ -364,11 +364,11 @@ export default Base; * ```javascript * // app/validators/unique-username.js * - * import Ember from 'ember'; + * import { service } from '@ember/service'; * import BaseValidator from 'ember-cp-validations/validators/base'; * * const UniqueUsername = BaseValidator.extend({ - * store: Ember.inject.service(), + * store: service(), * * validate(value, options, model, attribute) { * return this.get('store').findRecord('user', value).then((user) => { diff --git a/addon/validators/belongs-to.js b/addon/validators/belongs-to.js index a013f75d..ded75f93 100755 --- a/addon/validators/belongs-to.js +++ b/addon/validators/belongs-to.js @@ -4,7 +4,7 @@ import { isPromise } from 'ember-cp-validations/utils/utils'; /** * [See All Options](#method_validate) * - * Identifies a `belongs-to` relationship in an Ember Data Model or Ember.Object. + * Identifies a `belongs-to` relationship in an Ember Data Model or EmberObject. * This is used to create a link to the validations object of the child model. * * _**Note:** Validations must exist on **both** models/objects_ @@ -42,18 +42,20 @@ import { isPromise } from 'ember-cp-validations/utils/utils'; * ```javascript * // model/users.js * + * import { getOwner } from '@ember/application'; + * import EmberObject from '@ember/object'; * import UserDetails from '../user-details'; * * const Validations = buildValidations({ * details: validator('belongs-to') * }); * - * export default Ember.Object.extend(Validations, { + * export default EmberObject.extend(Validations, { * details: null, * * init() { * this._super(...arguments); - * let owner = Ember.getOwner(this); + * let owner = getOwner(this); * this.set('details', UserDetails.create(owner.ownerInjection())); * } * }); diff --git a/addon/validators/has-many.js b/addon/validators/has-many.js index c2c6386a..e1e06b77 100755 --- a/addon/validators/has-many.js +++ b/addon/validators/has-many.js @@ -4,7 +4,7 @@ import { isPromise } from 'ember-cp-validations/utils/utils'; /** * [See All Options](#method_validate) * - * Identifies a `has-many` relationship in an Ember Data Model or Ember.Object. + * Identifies a `has-many` relationship in an Ember Data Model or EmberObject. * This is used to create a validation collection of the `has-many` validations. * * _**Note:** Validations must exist on **all** models/objects_ @@ -28,11 +28,13 @@ import { isPromise } from 'ember-cp-validations/utils/utils'; * ```javascript * // model/users.js * + * import EmberObject from '@ember/object'; + * * const Validations = buildValidations({ * friends: validator('has-many') * }); * - * export default Ember.Object.extend(Validations, { + * export default EmberObject.extend(Validations, { * friends: null * }); * ```