|
| 1 | +/* eslint ember-suave/no-direct-property-access:1 */ |
| 2 | + |
1 | 3 | import Ember from 'ember';
|
| 4 | +import DS from 'ember-data'; |
| 5 | + |
2 | 6 | import UrlBuilder from '../utils/url-builder';
|
3 | 7 | import normalizePayload from '../utils/normalize-payload';
|
4 | 8 | import defaultConfig from '../config';
|
5 | 9 |
|
6 |
| -const { assign, getOwner, computed, isArray, ArrayProxy, ObjectProxy, Object } = Ember; |
| 10 | +const { assign, getOwner, computed, Object } = Ember; |
| 11 | + |
| 12 | +const promiseTypes = { |
| 13 | + array: DS.PromiseArray, |
| 14 | + object: DS.PromiseObject |
| 15 | +}; |
7 | 16 |
|
8 | 17 | export default Object.extend({
|
9 | 18 | model: null,
|
@@ -61,18 +70,22 @@ export default Object.extend({
|
61 | 70 | return assign(this.get('config.ajaxOptions'), { data });
|
62 | 71 | }),
|
63 | 72 |
|
| 73 | + promiseType: computed('config.promiseType', function() { |
| 74 | + return promiseTypes[this.get('config.promiseType')]; |
| 75 | + }), |
| 76 | + |
64 | 77 | callAction() {
|
| 78 | + let promise = this._promise(); |
| 79 | + return this.get('promiseType') ? this.get('promiseType').create({ promise }) : promise; |
| 80 | + }, |
| 81 | + |
| 82 | + _promise() { |
65 | 83 | return this.get('adapter').ajax(this.get('url'), this.get('requestType'), this.get('data')).then((response) => {
|
66 | 84 | if (this.get('config.pushToStore') && response.data) {
|
67 |
| - return this._pushToStore(this.get('serializer').pushPayload(this.get('store'), response)); |
| 85 | + return this.get('serializer').pushPayload(this.get('store'), response); |
68 | 86 | } else {
|
69 | 87 | return response;
|
70 | 88 | }
|
71 | 89 | });
|
72 |
| - }, |
73 |
| - |
74 |
| - _pushToStore(content) { |
75 |
| - let proxy = isArray(content) ? ArrayProxy : ObjectProxy; |
76 |
| - return proxy.create({ content }); |
77 | 90 | }
|
78 | 91 | });
|
0 commit comments