Skip to content

Derived fields follow-ups: read-only enforcement, Store changedFields closure, canAggregateFn guard, docs #4748

Description

@lbwexler

Follow-ups to #4701 (derived fields), lifted from the review of #4638 before it was closed in favor of #4701.

1. Enforce read-only on derived fields

Store.modifyRecords() currently ignores writes to a derived field, and a grid column bound to one is still editable - an inline edit appears to succeed and then vanishes. Proposed:

  • modifyRecords() throws when a modification names a derived field, e.g. Field 'notional' is derived and read-only - its value is computed at read time and cannot be modified.
  • Column.isEditableForRecord() returns false for a column whose field is derived, regardless of the column's editable config.
  • Doc FieldSpec.derivedFn accordingly (currently says writes are "ignored").

2. Close Store changedFields over dependsOn

#4701 (post catch-up) closes a producer's changedFields over dependsOn in View.dataOnlyUpdate, so a Cube tick naming only price still re-sums a derived notional. A plain Store has the same hole: updateData() with a StoreTransaction.changedFields hint naming only inputs is passed through to RecordSetDelta.changedFields, and GridTransactionManager.sortUnchanged() trusts it - a grid sorted on a derived column would not re-sort. Proposed: apply the same transitive closure in Store.updateData() before the hint reaches the RecordSet, and have the View reuse it (or a shared util) rather than keeping its own copy.

3. Guard canAggregateFn on level-derived CubeFields

CubeField throws on derivedFn + isDimension, but a level-derived field (no aggregator) that also sets canAggregateFn is accepted and the fn silently never runs. Throw at construction, as for isDimension.

4. Doc carry-overs

The FieldSpec.calculatedFn / Cube README prose from #4638 on read-by-name semantics (getters are not own properties, so never rely on own-property enumeration - use StoreRecord.getValues), keeping the fn pure and fast (it runs per cell paint and per sort comparison), and returning primitives or stable references so grid change detection can skip unchanged cells applies verbatim to derivedFn and should land in data/README.md / data/cube/README.md. The Cube README's WeightedAverageAggregator example should be replaced by the SUM/SUM/ratio decomposition (see #4747).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions