Ember.js,限制REST适配器调用

时间:2015-05-14 00:05:25

标签: ember.js ember-data

我正在使用Parse,它只允许30个req​​s / sec到他们的后端。

因此,我想通过REST适配器限制所有转到Parse的调用(特别是扩展DS.RESTAdapter的{​​{3}}。

我尝试限制ajax方法,我认为需要返回一个Promise:

export default ParseAdapter.extend({
    applicationId: ENV.APP.applicationId,
    restApiId: ENV.APP.restApiId,

    ajax: function(url, type, options) {
        var self = this;
        return new Ember.RSVP.Promise(function(resolve, reject) {
            Ember.run.later(this,resolve,5000); // I would prefer this to be Ember.run.throttle, but not sure if that will work
        }).then(function() {
            return self._super(url,type,options)
        });
    }

});

但是我收到了这个错误:

TypeError: Cannot read property 'results' of undefined
    at exports.default.DS.default.RESTSerializer.extend.extractArray (vendor.js:115817)
    at apply (vendor.js:30197)
    at superWrapper (vendor.js:29749)
    at ember$data$lib$system$serializer$$default.extend.extractFindAll (vendor.js:81161)
    at ember$data$lib$system$serializer$$default.extend.extract (vendor.js:81144)
    at superFunction [as _super] (vendor.js:25863)
    at exports.default.DS.default.RESTSerializer.extend.extract (vendor.js:115843)
    at apply (vendor.js:30197)
    at superWrapper [as extract] (vendor.js:29749)

如何限制REST适配器?

1 个答案:

答案 0 :(得分:0)

如果我理解正确,您想要一起批处理API请求吗?

我不知道自己做这个的最好方法,但是开始寻找的好地方可能就是这个Ember CLI插件,'ember-model-batch'

Direct link to source code

相关问题