Skip to content

Commit

Permalink
Make the property access to fields of a model done through an object …
Browse files Browse the repository at this point in the history
…which is validated
  • Loading branch information
corrspt committed Nov 20, 2016
1 parent 690a674 commit 735c5bc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
21 changes: 16 additions & 5 deletions app/controllers/application.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions app/utils/person-utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
PERSON: {
NAME: 'name',
AGE: 'age'
}
};

0 comments on commit 735c5bc

Please sign in to comment.