diff --git a/addon/adapters/sails-socket.js b/addon/adapters/sails-socket.js index 94369ae..90f50ed 100644 --- a/addon/adapters/sails-socket.js +++ b/addon/adapters/sails-socket.js @@ -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); }, @@ -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(); } @@ -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] = {}; } @@ -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); diff --git a/addon/mixins/store.js b/addon/mixins/store.js index 1145575..82d1c70 100644 --- a/addon/mixins/store.js +++ b/addon/mixins/store.js @@ -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); diff --git a/addon/serializers/sails.js b/addon/serializers/sails.js index 628b0b8..4e496fd 100644 --- a/addon/serializers/sails.js +++ b/addon/serializers/sails.js @@ -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); @@ -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); @@ -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); }), @@ -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 @@ -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