Back to all reviewers

Single source of truth

twentyhq/twenty
Based on 2 comments
TSX

Establish a single authoritative source for each piece of data in your API interfaces rather than maintaining duplicate or parallel state. Derive computed values from the authoritative source instead of storing them separately.

API TSX

Reviewer Prompt

Establish a single authoritative source for each piece of data in your API interfaces rather than maintaining duplicate or parallel state. Derive computed values from the authoritative source instead of storing them separately.

When designing component interfaces, identify what should be the canonical source of truth and derive other values from it. This prevents inconsistencies and reduces complexity.

For example, instead of storing both headers and bodyType separately:

// Avoid: Maintaining parallel state
type BodyInputProps = {
  headers: Record<string, string>;
  bodyType: BodyType; // Duplicate information
  onChange: (value?: string, isBodyType?: boolean) => void;
};

// Prefer: Single source of truth
type BodyInputProps = {
  headers: Record<string, string>; // Single source
  onChange: (value?: string) => void;
};

// Derive bodyType from headers when needed
const bodyType = deriveBodyTypeFromHeaders(headers);

Similarly, when accessing related data, prefer getting it from the authoritative source rather than relying on indirect indicators. Instead of checking sourceHandleId, get the actual source node to ensure type safety and accuracy.

2
Comments Analyzed
TSX
Primary Language
API
Category

Source Discussions