Skip to content

Selectors for parent collection cacheΒ #16

@Floriferous

Description

@Floriferous

It would be an interesting addition to be able to provide a selector for the parent collection. For example:

// Only add a chairCount on furniture of type "table"
Furniture.cacheCount({
  collection: Furniture,
  referenceField: 'furnitureLink',
  cacheField: 'chairCount',
  parentSelector: { type: 'table' },
  selector: { type: 'chair' },
})

// Only add a legCount on furniture of type "chair"
Furniture.cacheCount({
  collection: Legs,
  referenceField: 'furnitureLink',
  cacheField: 'legCount',
  parentSelector: { type: 'chair' },
})

This allows "polymorphic" collections to have different caches depending on their category, type, etc.

It is mostly done for keeping things clean, but one could also imagine using different cache configurations with the same name:

Here's a sarcastic example 🀣:

Users.cacheCount({
  collection: Users,
  referenceField: 'friendIds',
  cacheField: 'americanFriends',
  parentSelector: { citizenShip: 'american' },
  selector: { citizenShip: 'american' },
})

Users.cacheCount({
  collection: Users,
  referenceField: 'friendIds',
  cacheField: 'americanFriends',
  parentSelector: { citizenShip: 'european' },
  selector: { citizenShip: { $in: ['north-american', 'south-american', 'american'] } },
})

You would be responsible for maintaining non-overlapping parent selectors of course, otherwise it will not work.

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