NgRx Auto-Entity
Primary version
Primary version
  • NgRx Auto-Entity
  • Getting Started
    • Installation
    • Quick Start
    • Use your State!
      • Enhancing your Facade
      • Simplify your Component
    • From Scratch
      • App Interfaces
      • App Reducer
      • App State Module
      • Entity Model
      • Entity State
      • Update App State
      • Entity Service
      • Update App Module
  • Advanced Topics
    • Advanced Usage
      • Paradigm Changes
        • Models
        • Services
        • Service Providers
      • Taking Control
        • Integrating Custom Effects
      • Building Your Entities
        • Entity Names
        • Sort Comparers
        • Data Transforms
      • Building Your Entity States
        • The buildState() function
        • The buildFeatureState() function
        • The IEntityState Interface
        • The Selector Map
      • Generic Actions
        • Actions Now
        • Reusable Generic Actions
        • Custom Criteria
        • Loading Actions
          • Loading Entities
          • Loading Pages
          • Loading Ranges
        • Optional Loading
        • CURD Actions
        • Utility Actions
      • Correlation
      • Common Selectors
        • Exporting Selectors
      • Extra Selectors
      • Custom Selectors
        • Adding to Facades
        • Using Custom Selectors
      • Custom Effects
        • Composing Actions
        • Workflows
    • Leveraging Facades
      • Preparing Facades
      • The Interface: Selections
        • Using Facade Selections
        • Simplifying Further
      • The Interface: Activities
        • Using Facade Activities
      • So Little Code!
    • Utility Functions
      • Prototyping your Entities
        • Entity Making Performance
      • Entity Name Utilities
      • Entity Key Utilities
      • Entity Comparers
  • Examples
    • Sample Application
      • App Module
      • State
      • Models
      • Services
      • Facades
      • Container Components
      • Presentation Components
      • Modal Component
  • Documentation
    • Reference
  • Extras
    • Github Link
Powered by GitBook
On this page
  • Activities (Action Dispatching Methods)
  • Familiar Functionality
Export as PDF
  1. Advanced Topics
  2. Leveraging Facades

The Interface: Activities

Prefabricated facades in NgRx Auto-Entity expose all the necessary properties and methods to allow you to fully leverage all of the state, actions and selectors Auto-Entity manages. Once you have extended a class from the base facade class, you may leverage all of this functionality without any additional effort.

Activities (Action Dispatching Methods)

In addition to properties for each selection, entity facades also expose a number of methods that wrap NgRx action dispatch calls. Each of these methods handles creation and subsequent dispatch of the appropriate generic action, including handling all the type information. We call these activities. The available methods on every facade include:

select(entity: TModel): Selects a single entity selectByKey(key: EntityIdentity): Selects a single entity by the specified key selectMany(entities: TModel[]): Selects the specified entities selectMore(entities: TModel[]): Selects more entities and updates the current selection selectManyByKeys(keys: EntityIdentity[]): Selects entities by the specified keys selectMoreByKeys(keys: EntityIdentity[]): Selects more entities by the specified keys deselect(): Deselects any previously selected entity deselectMany(entities: TModel[]): Deselects the specified entities deselectManyByKeys(keys: EntityIdentity[]): Deselects the specified entities by keys deselectAll(): Deselects all selected entities

load(keys: any, criteria?: any, corrId?: string): Loads entity by the specified key loadMany(criteria: any, corrId?: string): Loads many entities by the specified criteria loadAll(criteria?: any, corrId?: string): Loads all entities loadPage(page: Page, criteria?: any, corrId?: string): Loads a page of entities loadRange(range: Range, criteria?: any, corrId?: string): Loads a range of entities create(entity: TModel, criteria?: any, corrId?: string): Creates a new entity createMany(entities: TModel[], criteria?: any, corrId?: string): Bulk creates entities update(entity: TModel, criteria?: any, corrId?: string): Updates an entity updateMany(entities: TModel[], criteria?: any, corrId?: string): Bulk updates entities

upsert(entity: TModel, criteria?: any, corrId?: string): Updates/inserts an entity upsertMany(entities: TModel[], criteria?: any, corrId?: string): Bulk upserts entities replace(entity: TModel, criteria?: any, corrId?: string): Replace an entity replaceMany(entities: TModel[], criteria?: any, corrId?: string): Bulk replace entities delete(entity: TModel, criteria?: any, corrId?: string): Delete an entity deleteMany(entities: TModel[], criteria?: any, corrId?: string): Bulk delete entities deleteByKey(key: EntityIdentity, criteria?: any, corrId?: string): Delete an entity by its key deleteManyByKeys(keys: EntityIdentity[], criteria?: any, corrId?: string): Delete many entities by their keys clear(): Clears all state for the entity type and resets it to empty

The last parameter of each activity is a correlation id. In the above descriptions, this has been shortened to the term corrId to condense this documentation a bit, however the actual parameter is called correlationId and is optional. This allows the end developer to control what the correlationId is for any given set of initiation/result actions dispatched with auto-entity. If this parameter is not provided, the correlationId will be a randomly generated uuid.

Familiar Functionality

All of these methods, as with the properties, are encapsulating functionality you may already be familiar with. In the past with plain old NgRx, you might have done something like the following:

this.store.dispatch(new LoadAll(Customer, { organizationId: orgId }));

This is in fact what all of the entity facade methods are doing for you. We simplify the above repetitive procedure so you may simply call a method with just the bare bones required arguments, rather than have to bring in the store, dispatch and construct new actions yourself:

loadAll(criteria?: any): void {
  this.store.dispatch(new LoadAll(this.modelType, criteria));
}

The model type is tracked when you extend the facade base class with your own concrete implementation:

export class CustomerFacade extends CustomerFacadeBase {
    constructor(private store: Store<AppState>) {
        super(Customer, store); // Passing Customer here sets this.modelType
    }
}
PreviousSimplifying FurtherNextUsing Facade Activities

Last updated 4 years ago