Permalink
Browse files

Make the property access to fields of a model done through an object …

…which is validated
  • Loading branch information...
corrspt committed Nov 19, 2016
1 parent 690a674 commit 735c5bc098de76d9d3bc5239147097ca3c8aa68b
Showing with 22 additions and 5 deletions.
  1. +16 −5 app/controllers/application.js
  2. +6 −0 app/utils/person-utils.js
@@ -1,23 +1,34 @@
import Ember from 'ember';
import PersonUtil from '../utils/person-utils';
const {
Controller,
get,
inject: { service }
inject: { service },
assert,
isEmpty
} = Ember;
const {
PERSON
} = PersonUtil;
export default Controller.extend({
i18n: service(),
setField(field, value) {
assert(`Must pass a valid attribute - ${field}`, !isEmpty(field));
let model = get(this, 'model');
model.set(field, value);
},
actions: {
setName(name) {
let model = get(this, 'model');
model.set('name', name);
this.setField(PERSON.NAME, name);
},
setAge(age) {
let model = get(this, 'model');
model.set('age', age);
this.setField(PERSON.AGE, age);
},
setLocale(value) {
@@ -0,0 +1,6 @@
export default {
PERSON: {
NAME: 'name',
AGE: 'age'
}
};

0 comments on commit 735c5bc

Please sign in to comment.