ice-frontend-react-mobx
Version:
ICE Frontend REACT+MobX
104 lines (81 loc) • 2.49 kB
JavaScript
const debug = require('debug')('ice:models:feed'); // eslint-disable-line no-unused-vars
import { observable, computed } from 'mobx';
export default class Feed {
_id = null;
name = null;
symbol = null;
type = null;
metrics = [new FeedMetrics(), new FeedMetrics(), new FeedMetrics()];
store = null;
constructor (store) {
this.store = store;
}
get id () {
return this._id;
}
get toJson () {
let feed = {
name: this.name,
symbol: this.symbol,
feedType: this.type
};
if (this.id) {
feed.id = this.id;
}
return feed;
}
updateFromJson (json) {
this._id = json.id || null;
this.name = json.name || null;
this.symbol = json.symbol || null;
this.type = json.feedType || null;
}
save () {
return this.store.save(this);
}
delete () {
return this.store.delete(this.id);
}
}
export class FeedMetrics {
allocated1nW = '';
allocated2nW = '';
drLimitW = '';
maxAllocated1nW = '';
maxAllocated2nW = '';
maxPowerW = '';
phase = '';
powerW = '';
get allocated1n () {
return this.allocated1nW / 1000;
}
get allocated2n () {
return this.allocated2nW / 1000;
}
get power () {
return this.powerW / 1000;
}
get maxPower () {
return this.maxPowerW / 1000;
}
get limit () {
return this.drLimitW / 1000;
}
get maxAllocated1n () {
return this.maxAllocated1nW / 1000;
}
get maxAllocated2n () {
return this.maxAllocated2nW / 1000;
}
updateFromJson (json) {
this.allocated1nW = (json.hasOwnProperty('allocated1nW')) ? json.allocated1nW : '';
this.allocated2nW = (json.hasOwnProperty('allocated2nW')) ? json.allocated2nW : '';
this.drLimitW = (json.hasOwnProperty('drLimitW')) ? json.drLimitW : '';
this.maxAllocated1nW = (json.hasOwnProperty('maxAllocated1nW')) ? json.maxAllocated1nW : '';
this.maxAllocated2nW = (json.hasOwnProperty('maxAllocated2nW')) ? json.maxAllocated2nW : '';
this.maxPowerW = (json.hasOwnProperty('maxPowerW')) ? json.maxPowerW : '';
this.phase = (json.hasOwnProperty('phase')) ? json.phase : '';
this.powerW = (json.hasOwnProperty('powerW')) ? json.powerW : '';
this.timestamp = (json.timestamp) ? new Date(json.timestamp) : '';
}
}