storeObjectArray.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { StoreObject } from './storeObject';
  2. export class StoreObjectArray extends StoreObject {
  3. constructor (type, lines, columns, value = null, readOnly = false) {
  4. super(type, value, readOnly);
  5. this._lines = lines;
  6. this._columns = columns;
  7. }
  8. get lines () {
  9. return this._lines;
  10. }
  11. get columns () {
  12. return this._columns;
  13. }
  14. isCompatible (another) {
  15. if(another instanceof StoreObject) {
  16. if(this.lines === another.lines &&
  17. this.columns === another.columns) {
  18. return super.isCompatible(another);
  19. }
  20. }
  21. return false;
  22. }
  23. get isVector () {
  24. return this.type.dimensions === 1;
  25. }
  26. get isValid () {
  27. if (this.value !== null) {
  28. if( this.isVector) {
  29. if(this.value.length !== this.lines) {
  30. return false;
  31. }
  32. const mustBeNull = this.value.find(v => !this.type.canAccept(v.type) );
  33. if(!!mustBeNull) {
  34. return false;
  35. }
  36. }
  37. return true;
  38. } else {
  39. if(this.lines !== this.value.length) {
  40. return false;
  41. }
  42. for (let i = 0; i < this.lines; i++) {
  43. for (let j = 0; j < this.columns; j++) {
  44. const arr = this.value[i];
  45. if(arr.length !== this.columns) {
  46. return false;
  47. }
  48. const mustBeNull = arr.find(v => !this.type.canAccept(v.type) );
  49. if(!!mustBeNull) {
  50. return false;
  51. }
  52. }
  53. }
  54. return true;
  55. }
  56. }
  57. }