npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lucasheight/odata-observable-store

v1.2.7

Published

OData observable store pattern.

Downloads

6

Readme

OData Observable Store - State management for Angular Odata services

OData Observable Store is a simple state management library that implements the observable store pattern for odata api's within Angular.

The library provides public methods for query, get, update, patch, insert and remove while maintaining state on the service.

Generally for most CRUD odata services, all that is required is to extend the ODataStore and provide the baseUrl field.

Installation

Install the npm package @lucasheight/odata-observable-store.

    npm install --save @lucasheight/odata-observable-store

How to use

The snippets below are based on the example provided in the projects folder of this repository which uses the TripPin Sample Service. More information on the service can be found here https://www.odata.org/odata-services/.

Create the IPeople interface

export interface IPeople{
    UserName:string;
    FirstName:string;
    LastName:string;
    MiddleName?:string;
    Gender:Gender;
    Age?:string|number;
    Emails?:string[];
    FavouriteFeature:string;
    Features:string[];
    Cost?:number;
    Budget?:number;
    AddressInfo:IAddress;
    HomeAddress?:any;
}

export interface IAddress{
    Address?:string;
    City?:ICity;
}
export interface ICity{
    Name:string;
    CountryRegion:string;
    Region:string;
}
export enum Gender{
    Male="Male",Female="Female",Unknown="Unknown"
}

Create a new angular service

import { Injectable } from '@angular/core';
import { IPeople } from './IPeople';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import {ODataStore,IStoreSettings} from "@lucasheight/odata-observable-store"

@Injectable({
  providedIn: 'root'
})
export class PeopleService extends ODataStore<IPeople>{
  baseUrl: string = "/People";

  constructor(protected http: HttpClient) {
    super(http, {notifyOnGet:true});
  }
  //demonstrates how to apply a filter to a query
  queryByFirstName = (query: string): void => {
    let filter = `$filter=contains(FirstName,'${query}')`;
    this.query(filter);
  }
  count = ():Observable<number>=> this.http.get<number>(`${this.baseUrl}/$count`)
}

Use in a component

import { PeopleService } from '../services/people.service';
import { takeUntil, filter, map } from 'rxjs/operators';
import { Subject, Observable } from 'rxjs';
import { Component, OnInit, OnDestroy } from '@angular/core';
import { IPeople } from '../services/IPeople';
import { action } from 'odata-observable-store/public-api';
@Component({
    selector: 'app-people',
    templateUrl: './people.component.html'
})
export class PeopleComponent implements OnInit, OnDestroy {
    destroy$: Subject<void> = new Subject();
    people$: Observable<IPeople[]>;
    person$: Observable<IPeople>;
    constructor(private peopleService: PeopleService) { }
    ngOnInit(): void {
        //subscribe to the notifier observable to receive messages on state changes
        this.peopleService.notifier$.pipe(takeUntil(this.destroy$)).subscribe(s => {
            //do something with the messages
            console.log(action[s.action], s.message)
        });
        //set up the people$ observable and map the odata value to an array of IPeople[]
        this.people$ = this.peopleService.state$.pipe(takeUntil(this.destroy$), map(m => m.value));
        //load some data
        this.query();
    }
    private query = (): void => {
        //hydrate the odata observable store by calling the query method 
        this.peopleService.query();
    }
    private update = (item: IPeople): void => {
        this.peopleService.update(item, "UserName");
    }
    private patch = (item: IPeople): void => {
        this.peopleService.patch(item, "UserName");
    }
    private insert = (item: IPeople): void => {
        this.peopleService.insert(item);
    }
    private delete = (item: IPeople): void => {
        this.peopleService.remove(item, "UserName");
    }

    ngOnDestroy(): void {
        //unsubscribe 
        this.destroy$.next();
    }


}

Check out the example app

The example app can be found under the projects folder of this repository

API Documentation

Dependencies

Rxjs, Angular