diff --git a/README.md b/README.md index f47dbe9e..e0d1ff67 100644 --- a/README.md +++ b/README.md @@ -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; } }) @@ -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 diff --git a/addon/utils/collection-action.ts b/addon/utils/collection-action.ts index e390157a..0a5e5c3e 100644 --- a/addon/utils/collection-action.ts +++ b/addon/utils/collection-action.ts @@ -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'; @@ -25,7 +24,7 @@ export default function collectionOp(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); diff --git a/addon/utils/member-action.ts b/addon/utils/member-action.ts index 633d362b..3fa8fca6 100644 --- a/addon/utils/member-action.ts +++ b/addon/utils/member-action.ts @@ -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'; @@ -23,12 +22,14 @@ export default function instanceOp(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; + }); }; } diff --git a/tests/dummy/app/models/fruit.js b/tests/dummy/app/models/fruit.js index e3267a77..3cac776b 100644 --- a/tests/dummy/app/models/fruit.js +++ b/tests/dummy/app/models/fruit.js @@ -1,5 +1,4 @@ // BEGIN-SNIPPET fruit-model -import { assign } from '@ember/polyfills'; import { collectionAction, memberAction, serializeAndPush } from 'ember-api-actions'; import DS from 'ember-data'; @@ -7,7 +6,7 @@ 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({