storeObject.js 839 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import Decimal from 'decimal.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 Decimal) {
  26. return this._value.toNumber();
  27. } else {
  28. return null;
  29. }
  30. }
  31. get readOnly () {
  32. return this._readOnly;
  33. }
  34. set readOnly (value) {
  35. this._readOnly = value;
  36. }
  37. isCompatible (another) {
  38. if( another instanceof StoreObject) {
  39. return this.type.isCompatible(another.type);
  40. }
  41. return false;
  42. }
  43. }