Our pure JavaScript Scheduler component


Post by Jerome Cauchon »

I debug your applyChangesToRecord and i think array fields are not managed as it should be!

Scenario 1: My array field(linkedEvents) contains one element on initial load ex: [5]. On a sync request, i clear all values of the linkedEvents ex: []. In the applyChangesToRecord, the rawChanges contains the new value but the rowChangesSimplePaths have lost my linkedEvents field so my linkedEvents change is ignored!

Scenario 2: My array field(linkedEvents) is empty on initial load ex: []. On a sync request, i add a value to the linkedEvents ex: [5]. In the applyChangesToRecord, the rawChanges contains the new value but the rowChangesSimplePaths flatten my linkedEvents ex: linkedEvents.0: 5 The change is added to the record but as a "linkedEvents.0" property. It should fill my linkedEvents.

Is it a bug on your side or should i manage array field differently?

for (const key in rawChanges) {
        if (Object.prototype.hasOwnProperty.call(rawChanges, key) && !done[key]) {
          rawChangesFiltered[key] = rawChanges[key];
        }
      }

  const rowChangesSimplePaths = _Core_helper_ObjectHelper_js__WEBPACK_IMPORTED_MODULE_2__["default"].pathifyKeys(rawChangesFiltered); // Collect the changes into a change set for field names.

  for (const dataSource in rowChangesSimplePaths) {
    const field = fieldDataSourceMap[dataSource],
          propName = field ? field.name : dataSource,
          value = modelClass.processField(propName, rowChangesSimplePaths[dataSource]),
          oldValue = dataSource in recProto ? record[propName] : _Core_helper_ObjectHelper_js__WEBPACK_IMPORTED_MODULE_2__["default"].getPath(data, dataSource);

    if (!(field !== null && field !== void 0 && field.isEqual ? field.isEqual(oldValue, value) : _Core_helper_ObjectHelper_js__WEBPACK_IMPORTED_MODULE_2__["default"].isEqual(oldValue, value))) {
      hasChanges = true;
      changes[propName] = value;
    }
  }

Post by saki »

Do you define the field as https://bryntum.com/docs/scheduler/#Core/data/field/ArrayDataField in a model extension?


Post by Jerome Cauchon »

Yes

export class SchedulerProEventModel extends EventModel {
  static get fields(): unknown[] {
    return [
      'detailedComment',
      'initialWoodMoisture',
      'isLocked',
      'lumberType',
      'recipe',
      'targetWoodMoisture',
      'tooltipNote',
      'woodQuantity',
      {
        name: 'linkedEvents',
        isEqual: (oldValue: any, value: any) => {
          return ObjectHelper.isEqual(oldValue, value);
        },
        type: 'array',
      },
    ];
  }
}

Post by Maxim Gorkovsky »

Hello.
Issue reproduced, ticket opened here: https://github.com/bryntum/support/issues/3390 Thank you for report!


Post by Jerome Cauchon »

Thank you!!!!


Post by chrisb »

Hey guys. Is there any ETA on this? We just stumbled across it as well. For us it's manifesting as an infinite loop on sync as it's not clearing out the modified state of our array field due to pathifyKeys returning each value in the array which causes this code in clearChanges to not clear the modified array field.

// If we've received an object with changes, we only need to clean that one up
    if (changes) {
      for (const key in changes) {
        delete meta.modified[key];
      }
    } else {
      meta.modified = {};
    }

Post by marcio »

Hey chrisb,

Unfortunately, no updates for now, please follow the ticket to get the latest news on that. I added a note to the ticket about your comment. Thanks.

Best regards,
Márcio


Post Reply