So far, using ember-cp-validations require to inject validations in the to-be-validated object. This may be useful, but when working with DS.Model, it imposes a single validation abstraction.
This addon proposes to:
- decouple the validator from the "validatee"
- Applies changes to a proxy object that will carry the validation model
- Keep using ember-cp-validations
export default DS.Model.extend(buildValidations(...), {
// ...
})
//
// what we currently have
//
let model = this.store.findRecord('my-type', myId);
console.log(model.isValid)
// or
export default Component.extend({
model: null // will be given at runtime
isEverythingOk: reads('model.isValid')
})
//
// What we want
//
function doYourMagic() {
this === ?
}
let ThingValidations = buildValidations(...)
export default Component.extend({
model: null // will be given at runtime
validatedModel2: computed('thingTobeValidated', function () {
return doYourMagic(this, 'thingTobeValidated', ThingValidations) // <== a proxy with validations
})
})
ember install ember-cp-buffered-validations
[Longer description of how to use the addon in apps.]
git clone <repository-url>
cd ember-cp-buffered-validations
yarn install
yarn lint:hbs
yarn lint:js
yarn lint:js --fix
ember test
– Runs the test suite on the current Ember versionember test --server
– Runs the test suite in "watch mode"ember try:each
– Runs the test suite against multiple Ember versions
ember serve
- Visit the dummy application at http://localhost:4200.
For more information on using ember-cli, visit https://ember-cli.com/.
This project is licensed under the MIT License.