storeObject.js 780 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { BigNumber } from 'bignumber.js'
  2. export class StoreObject {
  3. constructor (type, value, readOnly = false) {
  4. this._type = type;
  5. this._value = value;
  6. this._readOnly = readOnly;
  7. this._id = null;
  8. }
  9. setID (id) {
  10. this._id = id;
  11. }
  12. get id () {
  13. return this._id;
  14. }
  15. get inStore () {
  16. return this.id !== null;
  17. }
  18. get type () {
  19. return this._type;
  20. }
  21. get value () {
  22. return this._value;
  23. }
  24. get number () {
  25. if (this._value instanceof BigNumber) {
  26. return this._value.toNumber();
  27. } else {
  28. return null;
  29. }
  30. }
  31. get readOnly () {
  32. return this._readOnly;
  33. }
  34. isCompatible (another) {
  35. if( another instanceof StoreObject) {
  36. return this.type === another.type;
  37. }
  38. return false;
  39. }
  40. }