Last active
August 24, 2019 09:14
-
-
Save James-Byrne/f0f31f50032afcf9409330b790ae54af to your computer and use it in GitHub Desktop.
Testing defineProperty
This file contains 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'; | |
import { defineProperty, computed } from '@ember/object'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
init() { | |
const attrs = { firstName: 'Foo', lastName: 'Bar' }; | |
const model = this.store.createRecord('my-model', attrs); | |
defineProperty(model, 'fullName', computed('model.{firstName,lastName}', { | |
get: () => { | |
const { firstName, lastName } = this.model; | |
return `${firstName} ${lastName}`; | |
}, | |
set: (key, value) => { | |
const names = value.split(' '); | |
this.set('model.firstName', names[0]); | |
this.set('model.lastName', names[1]); | |
return value; | |
}, | |
})); | |
this.set('model', model); | |
}, | |
actions: { | |
onSubmit(fullName) { | |
this.set('model.fullName', fullName); | |
}, | |
} | |
}); |
This file contains 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'; | |
export default Model.extend({ | |
firstName: attr('string'), | |
lastName: attr('string'), | |
}); |
This file contains 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.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.4.2" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment