Options
All
  • Public
  • Public/Protected
  • All
Menu

Module entity-store

Index

Type aliases

Functions

Type aliases

EntityStore

EntityStore<T>: { subscribe: Subscribe<Normalized<T>>; get: any; remove: any; reset: any; set: any; update: any }

Simple Svelte store that normalized data by ID and provides helpers for common data access patterns.

Type parameters

  • T

Type declaration

  • subscribe: Subscribe<Normalized<T>>

    See (Svelte's docs)[https://svelte.dev/docs#svelte_store] for details on the Store contract and subscribe function.

  • get: function
    • get(): Readable<T[]>
    • get(id: ID): Readable<T>
    • get(ids: ID[]): Readable<T[]>
    • get(pred: Predicate<T>): Readable<T[]>
    • Gets a derived store containing every entity in the store.

      Returns Readable<T[]>

      Array of all entities

    • Gets a derived store containing the entity if the ID is found, or undefined otherwise.

      Parameters

      • id: ID

        ID of the entity to find

      Returns Readable<T>

      Entity object if found, undefined otherwise

    • Gets a derived store containing a list of all entities found by ID. IDs that aren't found in the store are ignored. The list of entities is not guaranteed to be the same length as the list of IDs.

      Parameters

      • ids: ID[]

        Array of IDs to find

      Returns Readable<T[]>

      Array of found entities

    • Gets a derived store containing a list of all entities in the store that match the filter function.

      Parameters

      Returns Readable<T[]>

      Array of all entities matching the filter function

  • remove: function
    • remove(id: ID): void
    • remove(ids: ID[]): void
    • remove(entity: T): void
    • remove(entities: T[]): void
    • remove(pred: Predicate<T>): void
    • Removes the entity from the store, if found.

      Parameters

      • id: ID

        ID of the entity to remove

      Returns void

    • Removes the given entities from the store, if found.

      Parameters

      • ids: ID[]

        Array of IDs to remove from the store

      Returns void

    • Removes an entity from the store, if found.

      Parameters

      • entity: T

        The entity to remove

      Returns void

    • Removes multiple entities from the store, if found.

      Parameters

      • entities: T[]

        Array of entities to remove

      Returns void

    • Removes all entities that match the filter function.

      Parameters

      • pred: Predicate<T>

        Filter function which returns true for each entity to be removed

      Returns void

  • reset: function
    • reset(): void
  • set: function
    • set(entity: T): void
    • set(entities: T | T[]): void
    • Adds the given entity to the store. If the entity is already in the store, their old value is replaced.

      Parameters

      • entity: T

        Entity to be added or updated

      Returns void

    • Adds the given entities to the store. For entities that are already in the store, their old value is replaced.

      Parameters

      • entities: T | T[]

        Entity or entities to be added or updated

      Returns void

  • update: function
    • update(updater: Updater<T>): void
    • update(updater: Updater<T>, id: ID): void
    • update(updater: Updater<T>, ids: ID[]): void
    • update(updater: Updater<T>, entity: T): void
    • update(updater: Updater<T>, entities: T[]): void
    • update(updater: Updater<T>, pred: Predicate<T>): void
    • Runs every entity through the updater function and stores the new state.

      Parameters

      • updater: Updater<T>

        Callback to update the entity

      Returns void

    • If found, runs the entity through the updater function and stores the new state.

      Parameters

      • updater: Updater<T>

        Callback to update the entity

      • id: ID

        ID of the entity to update

      Returns void

    • Runs the matching entity through the updater function and stores the new state.

      Parameters

      • updater: Updater<T>

        Callback to update each entity

      • ids: ID[]

        IDs of the entities to update

      Returns void

    • If found, runs the entity through the updater function and stores the new state.

      Parameters

      • updater: Updater<T>

        Callback to update the entity

      • entity: T

        The entity to update

      Returns void

    • Runs each existing entity through the updater function and stores the new state.

      Parameters

      • updater: Updater<T>

        Callback to update each entity

      • entities: T[]

        Array of the entities to update

      Returns void

    • Runs each matching entity through the updater function and stores the new state.

      Parameters

      • updater: Updater<T>

        Callback to update each entity

      • pred: Predicate<T>

        Filter function that returns true for each entity to update

      Returns void

Functions

entityStore

  • Creates a new entity store.

    Type parameters

    • T

      Entity type being stored

    Parameters

    • getID: GetID<T>

      Function that returns the ID of an entity

    • initial: T[] = []

      (optional) Initial array of items to be stored

    Returns EntityStore<T>

Generated using TypeDoc