mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 10:25:42 +03:00
It follows the form of poll -> json parse -> append, Where append is defined in subclasses to add data from the new frame to long-lived rolling arrays of data.
28 lines
626 B
JavaScript
28 lines
626 B
JavaScript
import Mixin from '@ember/object/mixin';
|
|
import { assert } from '@ember/debug';
|
|
|
|
export default Mixin.create({
|
|
url: '',
|
|
|
|
fetch() {
|
|
assert('StatTrackers need a fetch method, which should have an interface like window.fetch');
|
|
},
|
|
|
|
append(/* frame */) {
|
|
assert(
|
|
'StatTrackers need an append method, which takes the JSON response from a request to url as an argument'
|
|
);
|
|
},
|
|
|
|
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));
|
|
},
|
|
});
|