Skip to content

Commit

Permalink
2.0 compatibility
Browse files Browse the repository at this point in the history
	- Removed all references to typeKey
	- changed serializer to use new normalize syntax
  • Loading branch information
Cody Mcculloch committed Aug 18, 2015
1 parent 5edf809 commit 87b5f65
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 17 deletions.
8 changes: 4 additions & 4 deletions addon/adapters/sails-socket.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export default SailsBaseAdapter.extend({
if (!record.id && message.id) {
record.id = message.id;
}
payload[pluralize(camelize(type.typeKey))] = [record];
payload[pluralize(camelize(type.modelName))] = [record];
store.pushPayload(type, payload);
},

Expand All @@ -150,7 +150,7 @@ export default SailsBaseAdapter.extend({
* @private
*/
_handleSocketRecordDeleted: function (store, type, message) {
var record = store.getById(type.typeKey, message.id);
var record = store.getById(type.modelName, message.id);
if (record && typeof record.get('dirtyType') === 'undefined') {
record.unloadRecord();
}
Expand Down Expand Up @@ -195,7 +195,7 @@ export default SailsBaseAdapter.extend({
this._scheduledSubscriptions = {};
}
// use an object and keys so that we don't have duplicate IDs
key = camelize(type.typeKey);
key = camelize(type.modelName);
if (!this._scheduledSubscriptions[key]) {
this._scheduledSubscriptions[key] = {};
}
Expand Down Expand Up @@ -227,7 +227,7 @@ export default SailsBaseAdapter.extend({
payload[k] = Object.keys(data[k]);
this._listenToSocket(k);
}
self.debug(fmt('asking the API to subscribe to some records of type %@', Ember.keys(data).join(', ')));
self.debug(fmt('asking the API to subscribe to some records of type %@', Object.keys(data).join(', ')));
// ask the API to subscribe to those records
this.fetchCSRFToken().then(function () {
self.checkCSRF(payload);
Expand Down
8 changes: 4 additions & 4 deletions addon/mixins/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ var StoreMixin = Ember.Mixin.create({
* @method push
* @inheritDoc
*/
push: function (typeName/*, data, _partial*/) {
push: function (result) {
var res = this._super.apply(this, arguments), id, type, adapter;
if (this._pushSubscribes && res && (id = res.get('id'))) {
type = this.modelFor(typeName);
adapter = this.adapterFor(type);
if (result.data && res && (id = res.get('id'))) {
type = this.modelFor(result.data.type);
adapter = this.adapterFor(type.modelName);
if(adapter instanceof SailsSocketAdapter)
{
adapter._scheduleSubscribe(type, id);
Expand Down
10 changes: 5 additions & 5 deletions addon/serializers/sails.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var SailsSerializer = DS.RESTSerializer.extend(WithLogger, {
* @method extractArray
* @inheritDoc
*/
extractArray: blueprintsWrapMethod(function (store, primaryType, payload) {
normalizeArrayResponse: blueprintsWrapMethod(function (store, primaryType, payload) {
var newPayload = {};
newPayload[pluralize(primaryType.typeKey)] = payload;
return this._super(store, primaryType, newPayload);
Expand All @@ -47,7 +47,7 @@ var SailsSerializer = DS.RESTSerializer.extend(WithLogger, {
* @method extractSingle
* @inheritDoc
*/
extractSingle: blueprintsWrapMethod(function (store, primaryType, payload, recordId) {
normalizeSingleResponse: blueprintsWrapMethod(function (store, primaryType, payload, recordId) {
var newPayload;
if (payload === null) {
return this._super.apply(this, arguments);
Expand All @@ -62,7 +62,7 @@ var SailsSerializer = DS.RESTSerializer.extend(WithLogger, {
* @method extractDeleteRecord
* @inheritDoc
*/
extractDeleteRecord: blueprintsWrapMethod(function (store, type, payload, id, requestType) {
normalizeDeleteRecordResponse: blueprintsWrapMethod(function (store, type, payload, id, requestType) {
return this._super(store, type, null, id, requestType);
}),

Expand All @@ -73,7 +73,7 @@ var SailsSerializer = DS.RESTSerializer.extend(WithLogger, {
*/
serializeIntoHash: blueprintsWrapMethod(function (data, type, record, options) {
var json;
if (Ember.keys(data).length > 0) {
if (Object.keys(data).length > 0) {
this.error(
fmt('trying to serialize multiple records in one hash for type %@', type.typeKey),
data
Expand All @@ -100,7 +100,7 @@ var SailsSerializer = DS.RESTSerializer.extend(WithLogger, {
* @method extract
* @inheritDoc
*/
extract: function (store, type/*, payload, id, requestType*/) {
normalizeResponse: function (store, type/*, payload, id, requestType*/) {
var adapter, typeKey, isUsingSocketAdapter;
// this is the only place we have access to the store, so that we can get the adapter and check
// if it is an instance of sails socket adapter, and so register for events if necessary on that
Expand Down
40 changes: 36 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ember-data-sails",
"name": "bc-ember-data-sails",
"version": "0.0.16",
"description": "Adapters and tools for EmberJS to work well with SailsJS",
"directories": {
Expand All @@ -11,11 +11,17 @@
"build": "ember build",
"test": "ember test"
},
"repository": "https://github.com/huafu/ember-data-sails.git",
"repository": {
"type": "git",
"url": "git://github.com/brickclick/ember-data-sails.git.git#bc-ember-data-sails"
},
"engines": {
"node": ">= 0.10.0"
},
"author": "Huafu Gandon <[email protected]>",
"author": {
"name": "Brickclick",
"email": "[email protected]"
},
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.0.2",
Expand All @@ -40,5 +46,31 @@
],
"ember-addon": {
"configPath": "tests/dummy/config"
}
},
"gitHead": "7df416974e7c85d63ff63b84c164c61c94ae7e56",
"bugs": {
"url": "https://github.com/brickclick/ember-data-sails.git/issues"
},
"homepage": "https://github.com/brickclick/ember-data-sails.git",
"_id": "[email protected]",
"_shasum": "97daa5da0ab54cff2e25b0f5baade7243b29c6c3",
"_from": "bc-ember-data-sails@*",
"_npmVersion": "2.7.4",
"_nodeVersion": "0.12.0",
"_npmUser": {
"name": "t3rminus",
"email": "[email protected]"
},
"dist": {
"shasum": "97daa5da0ab54cff2e25b0f5baade7243b29c6c3",
"tarball": "http://registry.npmjs.org/bc-ember-data-sails/-/bc-ember-data-sails-0.0.16.tgz"
},
"maintainers": [
{
"name": "t3rminus",
"email": "[email protected]"
}
],
"_resolved": "https://registry.npmjs.org/bc-ember-data-sails/-/bc-ember-data-sails-0.0.16.tgz",
"readme": "ERROR: No README data found!"
}

0 comments on commit 87b5f65

Please sign in to comment.