Skip to content

Commit

Permalink
chore: remove serializeAndPush util
Browse files Browse the repository at this point in the history
Will extract as a separate PR
  • Loading branch information
iezer authored and mike-north committed Oct 31, 2018
1 parent b52534b commit 10590b7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 22 deletions.
3 changes: 1 addition & 2 deletions addon/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import memberAction from './utils/member-action';
import collectionAction from './utils/collection-action';
import serializeAndPush from './utils/serialize-and-push';

export const classOp = collectionAction;
export const instanceOp = memberAction;

export { collectionAction, memberAction, serializeAndPush };
export { collectionAction, memberAction };
19 changes: 0 additions & 19 deletions addon/utils/serialize-and-push.js

This file was deleted.

16 changes: 15 additions & 1 deletion tests/dummy/app/models/fruit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// BEGIN-SNIPPET fruit-model
import DS from 'ember-data';
import { memberAction, collectionAction, serializeAndPush } from 'ember-api-actions';
import { memberAction, collectionAction } from 'ember-api-actions';
import { assign } from '@ember/polyfills';
import { isArray } from '@ember/array';

const { attr, Model } = DS;

Expand All @@ -11,6 +12,19 @@ function mergeAttributes(attributes) {
return payload;
}

// This is an example of how to extract JSON API responses and push
// them into the store.
// TODO extract and export as part of this addon
function serializeAndPush(response) {
const recordClass = this.constructor;
const modelName = recordClass.modelName;
const { store } = this;
const serializer = store.serializerFor(modelName);
const normalized = isArray(response.data) ? serializer.normalizeArrayResponse(store, recordClass, response) :
serializer.normalizeSingleResponse(store, recordClass, response);
return this.store.push(normalized);
}

export default Model.extend({
name: attr('string'),
ripen: memberAction({ path: 'doRipen' }),
Expand Down

0 comments on commit 10590b7

Please sign in to comment.