Last active
January 18, 2017 00:05
-
-
Save offirgolan/ee8b637b217fe8dc445360f21da8ffbd to your computer and use it in GitHub Desktop.
CP Validations DS.PromiseObject Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle' | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from "ember-data/model"; | |
import attr from "ember-data/attr"; | |
import { belongsTo, hasMany } from "ember-data/relationships"; | |
import { buildValidations, validator } from 'ember-cp-validations'; | |
const Validations = buildValidations({ | |
promise: validator('number', { | |
dependentKeys: ['model.promise.content'], | |
value(model) { | |
console.log(model.get('promise.isFulfilled')); | |
return model.get('promise.content'); | |
}, | |
allowString: false, | |
integer: true, | |
gt: 500 | |
}) | |
}); | |
export default DS.Model.extend(Validations, { | |
value: attr('string'), | |
promise: Ember.computed('value', function() { | |
let promise = new Ember.RSVP.Promise((resolve) => { | |
Ember.run.later(() => resolve(getRandomInt(1, 1000)), 500); | |
}); | |
return DS.PromiseObject.create({ promise }); | |
}) | |
}); | |
function getRandomInt(min, max) { | |
min = Math.ceil(min); | |
max = Math.floor(max); | |
return Math.floor(Math.random() * (max - min)) + min; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return this.store.createRecord('user'); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.10.7", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js", | |
"ember": "2.10.0", | |
"ember-data": "2.10.0", | |
"ember-template-compiler": "2.10.0", | |
"ember-testing": "2.10.0" | |
}, | |
"addons": { | |
"ember-cp-validations": "3.1.5" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment