deltas property

List<ChannelDelta> get deltas

Every difference this item found, on every channel, as one flat list.

The facet contract — one shape a reader can filter, count and rank without knowing which channel a difference came from. A filter asking for events on the db channel, but not out of lib/data/cache.dart is three predicates over these fields; without the flattening it is three predicates and a walk over four differently-shaped lists.

Built on demand and never stored: index.json keeps the channels, which is where the detail belongs, and this is the view over them.

Implementation

List<ChannelDelta> get deltas => [
  // One line, because a pixel diff has no fields — but it must be here or a
  // per-channel count cannot see the channel that fires most often.
  if (pixels?.changed ?? false)
    ChannelDelta(
      channel: 'pixels',
      property: 'changed',
      head:
          '${(pixels!.diff.fraction * 100).toStringAsFixed(2)}% · '
          '${pixels!.diff.clusters.length} '
          'region${pixels!.diff.clusters.length == 1 ? '' : 's'}',
    ),
  for (var delta in tree?.diff.deltas ?? const <TreeDelta>[])
    if (delta.kind != TreeDeltaKind.shifted)
      ChannelDelta(
        channel: 'tree',
        subject: delta.path,
        property: delta.property ?? delta.kind.name,
        base: delta.base,
        head: delta.head,
      ),
  for (var text in texts?.removed ?? const <String>[])
    ChannelDelta(channel: 'texts', property: 'removed', base: text),
  for (var text in texts?.added ?? const <String>[])
    ChannelDelta(channel: 'texts', property: 'added', head: text),
  for (var event in events?.removed ?? const <String>[])
    ChannelDelta(
      channel: 'events',
      subchannel: EventChannel.subchannelOf(event),
      subject: event,
      property: 'removed',
    ),
  for (var event in events?.added ?? const <String>[])
    ChannelDelta(
      channel: 'events',
      subchannel: EventChannel.subchannelOf(event),
      subject: event,
      property: 'added',
    ),
  for (var delta in events?.deltas ?? const <EventDelta>[])
    ChannelDelta(
      channel: 'events',
      subchannel: delta.subchannel,
      subject: delta.title,
      property: delta.kind == EventDeltaKind.moved ? 'moved' : delta.property,
      base: delta.base,
      head: delta.head,
      origin: delta.origin,
    ),
];