Ghost/ghost/admin/app/components/gh-download-count.js
Kevin Ansfield 4679302303 Don't destructure Ember.testing (#933)
no issue
- `Ember.testing` is or will soon be a getter/setter in Ember with the value set during a test, however destructuring will read the value when the module is evaluated
- moves all uses of `Ember.testing` inline
2018-01-02 10:19:59 +00:00

40 lines
1.0 KiB
JavaScript

import Component from '@ember/component';
import Ember from 'ember';
import {inject as service} from '@ember/service';
import {task, timeout} from 'ember-concurrency';
export default Component.extend({
ajax: service(),
ghostPaths: service(),
tagName: '',
count: '',
_poll: task(function* () {
let url = this.get('ghostPaths.count');
let pattern = /(-?\d+)(\d{3})/;
try {
let data = yield this.get('ajax').request(url);
let count = data.count.toString();
while (pattern.test(count)) {
count = count.replace(pattern, '$1,$2');
}
this.set('count', count);
if (!Ember.testing) { // eslint-disable-line
yield timeout(2000);
this.get('_poll').perform();
}
} catch (e) {
// no-op - we don't want to create noise for a failed download count
}
}),
didInsertElement() {
this.get('_poll').perform();
}
});