Skip to content

Commit

Permalink
Prep for 4.0.0-beta release (#577)
Browse files Browse the repository at this point in the history
  • Loading branch information
offirgolan authored Apr 2, 2018
1 parent 79a41fa commit d59ef90
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 67 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,23 @@ You can also learn more by watching this Global Ember Meetup talk:

[![Introduction to ember-cp-validations](https://i.vimeocdn.com/video/545445254.png?mw=1920&mh=1080&q=70)](https://vimeo.com/146857699)

Installation
------------------------------------------------------------------------------
## Installation

```shell
ember install ember-cp-validations
```

## Upgrading to 3.x
## Upgrading to 4.x

If you are upgrading from 2.x to 3.x, please checkout the [upgrading documentation](UPGRADING.md).
If you are upgrading from 3.x to 4.x, please checkout the [upgrading documentation](UPGRADING.md).

## Helpful Links

- ### [Live Demo](http://offirgolan.github.io/ember-cp-validations)

- ### Documentation
- [3.x](http://offirgolan.github.io/ember-cp-validations/docs)
- [2.x](https://rawgit.com/offirgolan/ember-cp-validations/c08fedbf3dcfff1e8904a6469c8defd1fc2bfdf5/docs/modules/Home.html)
- [4.x](http://offirgolan.github.io/ember-cp-validations/docs)
- [3.x](https://rawgit.com/offirgolan/ember-cp-validations/c4123c983e54f24dd790ffa1bad66cfdf2f47ec6/docs/index.html)

- ### [Changelog](CHANGELOG.md)

Expand Down
80 changes: 26 additions & 54 deletions UPGRADING.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,42 @@
# Upgrading v2.x to 3.x
# Upgrading v3.x to 4.x

This document is here to show breaking changes when upgrading from v2.x to v3.x

### Computed Options
## Support Latest 2 LTS Releases

In 2.x, we introduced the notion of `Options as Functions` which allowed any validator's option to be a function that would
be lazily called right before a validation happened. In 3.x, we noticed that such implementation very much resembled the
workings of a Computed Property (without the caching of course). Converting our functional approach to an Ember CP approach made defining validations a whole lot simpler.
As Ember is evolving, we have to be able to keep up. v3.x supported Ember versions as old
as 1.11 which not only made this addon difficult to maintain, but also added a
lot of bloat. Going forward, this addon will target and test against only the 2
latest LTS releases.

**Before (2.x)**
## Inline Validator

```javascript
validator('length', {
dependentKeys: ['isDisabled', 'meta.username.minLength', 'meta.username.maxLength'],
disabled(model) {
return model.get('isDisabled');
},
min(model) {
return model.get('meta.username.minLength')
},
max(model) {
return model.get('meta.username.maxLength')
},
description(model, attribute) {
return model.generateDescription(attribute);
}
});
```

**After (3.x)**

```javascript
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(function() {
// CPs have access to the `model` and `attribute`
return this.get('model').generateDescription(this.get('attribute'));
}).volatile() // Disable caching and force recompute on every get call
});
```

Some more reasons why this is better:

- Any option that uses a CP doesn't have to re-declare those dependents in the `dependentKeys` collection.
- You can use any Ember.computed operation (computed.`and`, computed.`or`, computed.`filterBy`, etc.)
This library has always supported the ability to pass in a custom validate function
to the `validator` but it didn't feel consistent with the rest of the API. To normalize
this, we created a new `inline` validator that you can pass a function to via
the `validate` option.

### dependentKeys

There might be instances where your validator is dependent on external properties. For this reason, we introduced `dependentKeys` in 2.x. In 3.x, the only change to this is that all dependent keys must be prefixed with `model`.

**Before (2.x)**
**Before (3.x)**

```javascript
validator('presence', {
presence: true,
dependentKeys: ['someService.someProperty', 'foo', 'bar.baz']
validator(function(value, options, model, attribute) {
return value === options.username ?
true :
`Username must be ${options.username}`;
}, {
username: 'offirgolan'
});
```

**After (3.x)**
**After (4.x)**

```javascript
validator('presence', {
presence: true,
dependentKeys: ['model.someService.someProperty', 'model.foo', 'model.bar.baz']
validator('inline', {
username: 'offirgolan',
validate(value, options, model, attribute) {
return value === options.username ?
true :
`Username must be ${options.username}`;
}
});
```
2 changes: 1 addition & 1 deletion addon/validators/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ const Base = EmberObject.extend({
* @param {String} type The validator type (e.x. 'presence', 'length', etc.)
* The following types are unsupported:
* 'alias', 'belongs-to', 'dependent', 'has-many'
* @param {...} args The params to pass through to the validator
* @param {...args} args The arguments to pass through to the validator
* @return {Object} The test result object which will contain `isValid`
* and `message`. If the validator is async, then the
* return value will be a promise.
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,16 @@
"loader.js": "^4.2.3",
"prettier": "^1.10.2",
"qunit-dom": "^0.5.0",
"yuidoc-ember-theme": "^1.4.0"
"yuidoc-ember-theme": "^2.0.1"
},
"keywords": [
"ember-addon",
"ember-data",
"validator",
"validation",
"model"
"model",
"input",
"form"
],
"dependencies": {
"ember-cli-babel": "^6.6.0",
Expand Down
3 changes: 2 additions & 1 deletion tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
{{#nav.dropdown as |dd|}}
{{#dd.toggle}}Documentation <span class="caret"></span>{{/dd.toggle}}
{{#dd.menu as |ddm|}}
{{#ddm.item}}<a href='docs'>v3.x</a>{{/ddm.item}}
{{#ddm.item}}<a href='docs'>v4.x</a>{{/ddm.item}}
{{#ddm.item}}<a href='https://rawgit.com/offirgolan/ember-cp-validations/c4123c983e54f24dd790ffa1bad66cfdf2f47ec6/docs/index.html'>v3.x</a>{{/ddm.item}}
{{#ddm.item}}<a href='https://rawgit.com/offirgolan/ember-cp-validations/c08fedbf3dcfff1e8904a6469c8defd1fc2bfdf5/docs/index.html'>v2.x</a>{{/ddm.item}}
{{/dd.menu}}
{{/nav.dropdown}}
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9238,9 +9238,9 @@ yui@^3.18.1:
dependencies:
request "~2.40.0"

yuidoc-ember-theme@^1.4.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/yuidoc-ember-theme/-/yuidoc-ember-theme-1.4.0.tgz#b7ba649be58993530b3092e12fc114a07e81c414"
yuidoc-ember-theme@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/yuidoc-ember-theme/-/yuidoc-ember-theme-2.0.1.tgz#3798c592e3f35bf4216b7be40903cc039702c8b6"

yuidocjs@^0.10.0:
version "0.10.2"
Expand Down

0 comments on commit d59ef90

Please sign in to comment.