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

@pamlight/ngx-client

v0.0.4

Published

The angular library for Pamlight client SDK

Downloads

3

Readme

Pamlight Angular Client SDK

Pamlight is a service for managing realtime connections to your database with whatever technology it is powered by. This tool (Angular Client SDK) is used to connect an Angular 2+ project from client domains to pamlight endpoints at a high level.

Getting started

For more detailed instructions and guides on client side integration, check Pamlight client integration and also how Pamlight works, see our official documentations here.

Installation

Install pamlight angular client sdk via npm by running the following command:

npm install @pamlight/ngx-client --save

Usage

Register the NgxPamlightModule in your app module (or any other module you want to use it).

import { NgxPamlightModule } from '@pamlight/ngx-client';

import { NgxPamlightModule } from '@pamlight/ngx-client';

@NgModule({
 declarations: [],
 imports: [
   ...,
   NgxPamlightModule
 ],
 providers: [],
 bootstrap: []
})
export class AppModule {}

Use NgxPamlightService service in your component or in another service like below:

import { Component, OnInit } from '@angular/core';
import { NgxPamlightService } from '@pamlight/ngx-client';

@Component({
    selector: 'app-component-a',
    templateUrl: './component-a.component.html',
    styleUrls: ['./component-a.component.scss']
})
export class ComponentName implements OnInit {    
    constructor(
        private ngxPamlightService: NgxPamlightService
    ) { }

    ngOnInit() {
        // code actions here
    }
}

Initialize

Connect Pamlight client by initializing with the service. Its is adviceable to run init() method in a singleton service so as to ensure only a single instance is running.

import { Injectable } from '@angular/core';
import { NgxPamlightService } from '@pamlight/ngx-client';

@Injectable()
export class ServiceName {
    constructor(
        private ngxPamlightService: NgxPamlightService
    ) {
        this.initPamlight();
    }

    private initPamlight(): void {
        // replace `PROJECT_ID` with your project ID from Pamlight dashboard
        const projectId: string = `PROJECT_ID`;

        this.ngxPamlightService.init().then(() => {
            console.log('Pamlight connected successfully');
        }).catch(err => {
            throw Error(err);
        });
    }
}

sync data from database

Reading and subscribing to data changes in your database is straight forward. The read method returns an rxjs observable which can be subscribe to for subsequent data changes. For example, to get a User document from data base by userId, you could do something like this:

const routeId = 'getUserByUserID';
const query = {
    userId: `USER_ID`
};

this.ngxPamlightService.read<User>(routeId, query).subscribe(user => {
    console.log(user);
});

write data to database

Writing data to your database is by calling the write method on the connected client object. This returns a promise object with result if expected or void otherwise.

const routeId = 'updateUserProfile';
const payload = {
  firstName: 'Alice',
  lastName: 'Bob',
  age: 32
};

this.ngxPamlightService.write(routeId, payload, true).then((result) => {
  console.log(result);
}).catch((e) => {
  throw Error(e);
});

Further Reading

For further reading and information, check more client read operations as well as client write operations.