Skip to content
Open
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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ eat: memberAction({
path: 'eat',
before(attributes) {
let payload = this.serialize();
payload.data.attributes = assign(payload.data.attributes, attributes);
payload.data.attributes = Object.assign(payload.data.attributes, attributes);
return payload;
}
})
Expand Down Expand Up @@ -141,7 +141,7 @@ export default DS.Model.extend({
});
```

*Warning* this implemention only works for JSON API, but it should be easy to write your own `after` hook to handle your use case. Have a look at the [implementation of `serializeAndPush`](https://github.com/mike-north/ember-api-actions/blob/master/addon/utils/serialize-and-push.ts) for an example.
_Warning_ this implementation only works for JSON API, but it should be easy to write your own `after` hook to handle your use case. Have a look at the [implementation of `serializeAndPush`](https://github.com/mike-north/ember-api-actions/blob/master/addon/utils/serialize-and-push.ts) for an example.

## Customization

Expand Down
3 changes: 1 addition & 2 deletions addon/utils/collection-action.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { assign } from '@ember/polyfills';
import Model from 'ember-data/model';
import { Value as JSONValue } from 'json-typescript';
import { _getModelClass, _getModelName, _getStoreFromRecord, buildOperationUrl } from './build-url';
Expand All @@ -25,7 +24,7 @@ export default function collectionOp<IN = any, OUT = any>(options: CollectionOpe
const fullUrl = buildOperationUrl(model, options.path, urlType, false);
const data = (options.before && options.before.call(model, payload)) || payload;
return adapter
.ajax(fullUrl, requestType, assign(options.ajaxOptions || {}, { data }))
.ajax(fullUrl, requestType, Object.assign(options.ajaxOptions || {}, { data }))
.then((response: JSONValue) => {
if (options.after && !model.isDestroyed) {
return options.after.call(model, response);
Expand Down
15 changes: 8 additions & 7 deletions addon/utils/member-action.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { assign } from '@ember/polyfills';
import Model from 'ember-data/model';
import { Value as JSONValue } from 'json-typescript';
import { _getModelClass, _getModelName, _getStoreFromRecord, buildOperationUrl } from './build-url';
Expand All @@ -23,12 +22,14 @@ export default function instanceOp<IN = any, OUT = any>(options: InstanceOperati
const adapter = store.adapterFor(modelName);
const fullUrl = buildOperationUrl(this, path, urlType);
const data = (before && before.call(this, payload)) || payload;
return adapter.ajax(fullUrl, requestType, assign(ajaxOptions || {}, { data })).then((response: JSONValue) => {
if (after && !this.isDestroyed) {
return after.call(this, response);
}
return adapter
.ajax(fullUrl, requestType, Object.assign(ajaxOptions || {}, { data }))
.then((response: JSONValue) => {
if (after && !this.isDestroyed) {
return after.call(this, response);
}

return response;
});
return response;
});
};
}
3 changes: 1 addition & 2 deletions tests/dummy/app/models/fruit.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// BEGIN-SNIPPET fruit-model
import { assign } from '@ember/polyfills';
import { collectionAction, memberAction, serializeAndPush } from 'ember-api-actions';
import DS from 'ember-data';

const { attr, Model } = DS;

function mergeAttributes(attributes) {
const payload = this.serialize();
payload.data.attributes = assign(payload.data.attributes || {}, attributes);
payload.data.attributes = Object.assign(payload.data.attributes || {}, attributes);
return payload;
}
const Fruit = Model.extend({
Expand Down