storeObjectArray.js 2.0 KB

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