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
  • Selections (Observable Data Properties)
  • Familiar Functionality
  • Still Observable
Export as PDF
  1. Advanced Topics
  2. Leveraging Facades

The Interface: Selections

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.

Selections (Observable Data Properties)

Each entity facade exposes a number of properties that wrap NgRx state selections, exposing the streaming data within. Each of these properties returns and Observable of the appropriate type based on the state Auto-Entity tracks. We call these selections. The available properties on every entity facade include the following:

all$: Observable<TModel[]>; Array of entity objects in state entities$: Observable<IEntityDictionary<TModel>>; Map of ids to entity objects ids$: Observable<EntityIdentity[]>; Array of entity identities in state total$: Observable<number>; Total umber of entities in state

current$: Observable<TModel>; Selected single entity currentKey$: Observable<EntityIdentity>; Key of selected single entity

currentSet$: Observable<TModel[]>; Selected entities (New v0.2) currentSetKeys$: Observable<EntityIdentity[]>; Keys of selected entities (New v0.2)

currentPage$: Observable<Page>; Info about the current page of entities in state currentRange$: Observable<Range>; Info about the current range of entities in state totalPageable$: Observable<number>; Total number of entities that can be paged

edited$: Observable<Partial<TModel>>; The currently edited entity (partial) isDirty$: Observable<boolean>; Flag indicating if there have been changes to edited entity

isLoading$: Observable<boolean>; Flag indicating if entities are currently loading isSaving$: Observable<boolean>; Flag indicating if entities are currently saving isDeleting$: Observable<boolean>; Flag indicating if entities are currently deleting

loadedAt$: Observable<Date>; Timestamp of last load savedAt$: Observable<Date>; Timestamp of last save createdSt$: Observable<Date>; Timestamp of last creation deletedAt$: Observable<Date>; Timestamp of last delete

Familiar Functionality

All of these 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.customers$ = this.store.select(allCustomers);

This is in fact what all of the entity facade properties are doing for you. We simplify the above repetitive procedure so you may simply access a property rather than have to bring in the store, pipe and select yourself:

get all$(): Observable<TModel> {
    return this.store.select(selectAll);
}

Still Observable

Since all of our entity facade properties are observables, you are still free to use .pipe() on them as necessary, and leverage the full power of RxJs and reactive programming.

this.customers$ = this.customerFacade.all$.pipe(
    withLatestFrom(this.activatedRoute.paramMap),
    map(([customers, params]) => [customers, params.get('search')]),
    map(([customers, search]) => 
        customers.map(customer => customer.name.match(search))
    )
);
PreviousPreparing FacadesNextUsing Facade Selections

Last updated 4 years ago