An abstract class for capturing nomad stats

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.
This commit is contained in:
Michael Lange
2018-08-29 17:15:55 -07:00
parent a8480fab30
commit 5c5e44df61

View File

@@ -0,0 +1,27 @@
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));
},
});