2018-08-30 00:15:55 +00:00
|
|
|
import Mixin from '@ember/object/mixin';
|
|
|
|
import { assert } from '@ember/debug';
|
|
|
|
|
|
|
|
export default Mixin.create({
|
|
|
|
url: '',
|
|
|
|
|
|
|
|
fetch() {
|
2018-08-31 02:57:28 +00:00
|
|
|
assert('StatsTrackers need a fetch method, which should have an interface like window.fetch');
|
2018-08-30 00:15:55 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
append(/* frame */) {
|
|
|
|
assert(
|
2018-08-31 02:57:28 +00:00
|
|
|
'StatsTrackers need an append method, which takes the JSON response from a request to url as an argument'
|
2018-08-30 00:15:55 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
poll() {
|
|
|
|
const url = this.get('url');
|
|
|
|
assert('Url must be defined', url);
|
|
|
|
|
|
|
|
return this.get('fetch')(url)
|
|
|
|
.then(res => {
|
|
|
|
return res.json();
|
|
|
|
})
|
|
|
|
.then(frame => this.append(frame));
|
|
|
|
},
|
|
|
|
});
|