Last active
March 31, 2016 10:54
-
-
Save gustaff-weldon/9260a736357cc99880c2c70750819bce to your computer and use it in GitHub Desktop.
New 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 Ember from 'ember'; | |
import Profile from 'demo-app/models/profile' | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
init() { | |
let payload = { | |
id: 666, | |
first_name: 'Michal', | |
last_name: 'Kechner', | |
date_of_birth: '1989-12-23', | |
gender: 1, | |
nationality: 'PL', | |
marital_status: 0, | |
preferred_language: 'en', | |
mobile_number: '555540457', | |
city: 4 | |
} | |
const normalizedPayload = this.store.normalize('profile', payload) | |
let profile = this.store.push(normalizedPayload) | |
this.set('profile', profile) | |
Profile.eachAttribute(function(name, meta) { | |
console.log(name, meta, profile.get(name)); | |
//apply.set(name, profile.get(name)) | |
}); | |
} | |
}); |
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 DS from 'ember-data' | |
import Ember from 'ember' | |
export default DS.Model.extend({ | |
firstName: DS.attr(), | |
lastName: DS.attr('string'), | |
fullName: Ember.computed('firstName','lastName', function() { | |
return this.get('firstName') + ' ' + this.get('lastName') | |
}), | |
dateOfBirth: DS.attr('date'), | |
gender: DS.attr('gender'), | |
nationality: DS.attr('string'), | |
maritalStatus: DS.attr('string'), | |
preferredLanguage: DS.attr('string'), | |
mobileNumber: DS.attr('string'), | |
city: DS.attr('string') | |
}) |
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 DS from 'ember-data' | |
import Ember from 'ember' | |
/** | |
* JSONSerializer exptects output to be either the object or array of objects. | |
* see https://guides.emberjs.com/v2.4.0/models/customizing-serializers/#toc_jsonserializer | |
*/ | |
export default DS.JSONSerializer.extend({ | |
/** | |
* Map from camelCase model attributes to under_scored names expected by backend | |
* eg. firstName -> first_name | |
*/ | |
keyForAttribute(attr) { | |
return Ember.String.underscore(attr) | |
} | |
}) |
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 DS from 'ember-data' | |
export default DS.Transform.extend({ | |
/** | |
* Deserialization converts a value to a format that the client expects. | |
*/ | |
deserialize(genderId) { | |
let id = Number(genderId) | |
let result = null | |
switch(id) { | |
case 0: result = { id: 1, name: 'Female'} | |
case 1: result = { id: 1, name: 'Male'} | |
} | |
return result | |
}, | |
/** | |
* Serialization does the reverse and converts a value to the format expected by the persistence layer. | |
*/ | |
serialize(genderObj) { | |
if(!genderObj) { | |
return null | |
} | |
return genderObj.id | |
} | |
}) |
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.7.1", | |
"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.4.3", | |
"ember-data": "2.4.3", | |
"ember-template-compiler": "2.4.3" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment