Skip to content

austinthedeveloper/behavior-subject-entities

Repository files navigation

Behavior Subject Entitites

Code Style: Google

Jest Build Coverage ESLint

Description

Behavior Subject Entitites is a helper class designed to be used in place of a standard BehaviorSubject(). It includes all CRUD functions to make dealing with adding, removing, and deleting easier.

Installation

  • Install the package

    npm install behavior-subject-entities --save

Use

  • Import it in a TS file

import { EntityClass } from 'behavior-subject-entities';

Demo

export class TestService extends EntityClass<T>

  • Options 2: add it as a variable to a class

subject = new EntityClass<T>();

Options

EntityClass accepts a few options

Key Required Type Default Value Description
key false IdSelector (instance: any) => instance.id Id selector for the Entity. Pass a new function if you do not use id
name false string Item The Single Name for the Entity
plural false string Items The Plural Name for the Entity

Methods

Method Parameters Return
data$ N/A Observable<EntityObjContainer<T>>
items$ N/A Observable<T[]>
activeId$ N/A Observable<string>
addOne item: T void
addMany arr: T[] void
getOne id: string Observable<T>
getMany ids: string[] Observable<T[]>
updateOne item: T void
updateMany arr: T void
removeOne id: string void
removeMany ids: string[] void
snapshot N/A EntitySnapshot<T>
setActiveId id: string void