mirror of
https://github.com/kemko/nomad.git
synced 2026-01-04 01:15:43 +03:00
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:
27
ui/app/utils/classes/abstract-stats-tracker.js
Normal file
27
ui/app/utils/classes/abstract-stats-tracker.js
Normal 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));
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user