mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-29 13:52:10 +03:00
4679302303
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
40 lines
1.0 KiB
JavaScript
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();
|
|
}
|
|
});
|