Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Ember CLI 0.2.0 and Ember Data 1.0.0-beta.15 #70

Merged
merged 1 commit into from
May 13, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions addon/adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ export default DS.RESTAdapter.extend({
*/
createRecord: function( store, type, record ) {
var serializer = store.serializerFor( type.typeKey ),
snapshot = record._createSnapshot(),
data = {},
adapter = this;

serializer.serializeIntoHash( data, type, record, { includeId: true } );
serializer.serializeIntoHash( data, type, snapshot, { includeId: true } );

return new Ember.RSVP.Promise( function( resolve, reject ) {
adapter.ajax( adapter.buildURL( type.typeKey ), 'POST', { data: data } ).then(
Expand All @@ -70,13 +71,14 @@ export default DS.RESTAdapter.extend({
*/
updateRecord: function(store, type, record) {
var serializer = store.serializerFor( type.typeKey ),
snapshot = record._createSnapshot(),
id = record.get( 'id' ),
sendDeletes = false,
deleteds = {},
data = {},
adapter = this;

serializer.serializeIntoHash(data, type, record);
serializer.serializeIntoHash(data, type, snapshot, { includeId: true });

type.eachRelationship(function( key ) {
if ( data[key] && data[key].deleteds ) {
Expand Down Expand Up @@ -128,22 +130,23 @@ export default DS.RESTAdapter.extend({
* objects.
*/
findHasMany: function( store, record, relatedInfo ) {
var query = {
var relatedInfo_ = JSON.parse( relatedInfo ),
query = {
where: {
'$relatedTo': {
'object': {
'__type' : 'Pointer',
'className' : this.parseClassName( record.typeKey ),
'objectId' : record.get( 'id' )
},
key: relatedInfo.key
key: relatedInfo_.key
}
}
};

// the request is to the related type and not the type for the record.
// the query is where there is a pointer to this record.
return this.ajax( this.buildURL( relatedInfo.type.typeKey ), 'GET', { data: query } );
return this.ajax( this.buildURL( relatedInfo_.typeKey ), "GET", { data: query } );
},

/**
Expand Down
60 changes: 30 additions & 30 deletions addon/serializers/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default DS.RESTSerializer.extend({
*/
extractMeta: function( store, type, payload ) {
if ( payload && payload.count ) {
store.metaForType( type, { count: payload.count } );
store.setMetadataFor( type, { count: payload.count } );
delete payload.count;
}
},
Expand Down Expand Up @@ -86,9 +86,18 @@ export default DS.RESTSerializer.extend({
// the links property so the adapter can async call the
// relationship.
// The adapter findHasMany has been overridden to make use of this.
if ( options.relation ) {
hash.links = {};
hash.links[key] = { type: relationship.type, key: key };
if(options.relation) {
// hash[key] contains the response of Parse.com: eg {__type: Relation, className: MyParseClassName}
// this is an object that make ember-data fail, as it expects nothing or an array ids that represent the records
hash[key] = [];

// ember-data expects the link to be a string
// The adapter findHasMany will parse it
if (!hash.links) {
hash.links = {};
}

hash.links[key] = JSON.stringify({typeKey: relationship.type.typeKey, key: key});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeKey as the key? Not type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

joshfester@121909d introduced the JSON.stringify() call and joshfester@337d2ff changed "type" to "typeKey"

I mean to include the commit messages from each of these hashes into this commit listed under each referenced hash. If this is preferred I can cancel this pull request and re-commit.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes were from a pull request by @Kira2 so hopefully we can get her involved. Without running any tests I'm not sure of the difference between typeKey and type. @mixonic could you elaborate on that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typeKey is an Ember-Data internal string version of the model name. Creating a payload for push that looks like:

{
  typeKey: 'someFoo'
}

Would not actually set the typeKey. Instead polymorphic payload are intended to pass their type in a payload as type:

{
  type: 'someFoo'
}

In short, pushing typeKey: into the store doesn't so anything afaik.

}

if ( options.array ) {
Expand Down Expand Up @@ -121,11 +130,11 @@ export default DS.RESTSerializer.extend({
this._super( type, hash );
},

serializeIntoHash: function( hash, type, record, options ) {
Ember.merge( hash, this.serialize( record, options ) );
serializeIntoHash: function( hash, type, snapshot, options ) {
Ember.merge( hash, this.serialize( snapshot, options ) );
},

serializeAttribute: function( record, json, key, attribute ) {
serializeAttribute: function( snapshot, json, key, attribute ) {
// These are Parse reserved properties and we won't send them.
if ( 'createdAt' === key ||
'updatedAt' === key ||
Expand All @@ -135,29 +144,19 @@ export default DS.RESTSerializer.extend({
delete json[key];

} else {
this._super( record, json, key, attribute );
this._super( snapshot, json, key, attribute );
}
},

serializeBelongsTo: function( record, json, relationship ) {
var key = relationship.key,
belongsTo = record.get( key );

if ( belongsTo ) {
// @TODO: Perhaps this is working around a bug in Ember-Data? Why should
// promises be returned here.
if ( belongsTo instanceof DS.PromiseObject ) {
if ( !belongsTo.get('isFulfilled' ) ) {
throw new Error( 'belongsTo values *must* be fulfilled before attempting to serialize them' );
}

belongsTo = belongsTo.get( 'content' );
}
serializeBelongsTo: function( snapshot, json, relationship ) {
var key = relationship.key,
belongsToId = snapshot.belongsTo(key, { id: true });

if ( belongsToId ) {
json[key] = {
'__type' : 'Pointer',
'className' : this.parseClassName( belongsTo.constructor.typeKey ),
'objectId' : belongsTo.get( 'id' )
'className' : this.parseClassName(key),
'objectId' : belongsToId
};
}
},
Expand All @@ -171,10 +170,11 @@ export default DS.RESTSerializer.extend({
}
},

serializeHasMany: function( record, json, relationship ) {
var key = relationship.key,
hasMany = record.get( key ),
options = relationship.options;
serializeHasMany: function( snapshot, json, relationship ) {
var key = relationship.key,
hasMany = snapshot.hasMany( key ),
options = relationship.options,
_this = this;

if ( hasMany && hasMany.get( 'length' ) > 0 ) {
json[key] = { 'objects': [] };
Expand All @@ -190,8 +190,8 @@ export default DS.RESTSerializer.extend({
hasMany.forEach( function( child ) {
json[key].objects.push({
'__type' : 'Pointer',
'className' : child.parseClassName(),
'objectId' : child.get( 'id' )
'className' : _this.parseClassName(child.type.typeKey),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In serializeBelongsTo the key (used in serialization to the server) is passed to parseClassName. Here however the typeKey is passed, the Ember-Data internal value.

IMO only the typeKey should be passed to parseClassName, but can you clarify?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something hopefully @joshfester or @Kira2 can speak to. I'm honestly just going through the commits at github.com/joshfester/ember-parse-adapter and extracting the ones that are applicable to Ember Data 1.0.0-beta.15 and replaying them onto the Ember CLI Add-on version of the adapter. I will then do the same thing with other commits against Ember Data 1.0.0-beta.16 and again with other generic fixes, etc.

I have not been focusing on the specific changes that were applied or why - if the tests are passing and the demo app still functions I have viewed it as being functionally correct. I am trying to facilitate the convergence of several different development efforts into this single repository in the Ember CLI format. At that point I, and others, can begin focusing specifically on refactors and improvements.

If there is a different approach you would rather I and others to follow I am open to suggestions - I am just trying to move progress forward.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The serializeBelongsTo in this code does not appear to be the version @Kira2 was talking about.

'objectId' : child.attr( 'id' )
});
});

Expand Down
11 changes: 5 additions & 6 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"name": "ember-parse-adapter",
"dependencies": {
"handlebars": "~1.3.0",
"jquery": "^1.11.1",
"ember": "1.8.1",
"ember-data": "1.0.0-beta.14.1",
"ember-resolver": "~0.1.11",
"loader.js": "ember-cli/loader.js#1.0.1",
"ember": "1.10.0",
"ember-data": "1.0.0-beta.15",
"ember-resolver": "~0.1.12",
"loader.js": "ember-cli/loader.js#3.2.0",
"ember-cli-shims": "ember-cli/ember-cli-shims#0.0.3",
"ember-cli-test-loader": "ember-cli/ember-cli-test-loader#0.1.1",
"ember-cli-test-loader": "ember-cli-test-loader#0.1.3",
"ember-load-initializers": "ember-cli/ember-load-initializers#0.0.2",
"ember-qunit": "0.2.8",
"ember-qunit-notifications": "0.0.7",
Expand Down
19 changes: 7 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.0.0",
"broccoli-ember-hbs-template-compiler": "^1.6.1",
"ember-cli": "0.1.15",
"ember-cli-app-version": "0.3.1",
"ember-cli": "0.2.0",
"ember-cli-app-version": "0.3.2",
"ember-cli-babel": "^4.0.0",
"ember-cli-dependency-checker": "0.0.7",
"ember-cli-dependency-checker": "0.0.8",
"ember-cli-htmlbars": "0.7.4",
"ember-cli-ic-ajax": "0.1.1",
"ember-cli-inject-live-reload": "^1.3.0",
"ember-cli-qunit": "0.3.7",
"ember-cli-qunit": "0.3.9",
"ember-cli-uglify": "1.0.1",
"ember-data": "1.0.0-beta.14.1",
"ember-export-application-global": "^1.0.2",
"express": "^4.8.5",
"glob": "^4.4.2"
"ember-data": "1.0.0-beta.15",
"ember-export-application-global": "^1.0.2"
},
"keywords": [
"ember-addon",
Expand All @@ -48,8 +46,5 @@
],
"ember-addon": {
"configPath": "tests/dummy/config"
},
"dependencies": {
"rimraf": "^2.3.2"
}
}