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

ngfire

v0.0.52

Published

Unofficial library for angular & firebase.

Downloads

17

Readme

ngfire

Unofficial library for angular & firebase.

Setup

Prerequirement

Install firebase & firebase-tools:

npm install -D firebase-tools
npm install firebase

Initialize your firebase project:

npx firebase init

Setup the lib

Install the lib

npm install ngfire

Add the firebase config

environment.ts (use emulator) :

import { authEmulator, databaseEmulator, firestoreEmulator, functionsEmulator, storageEmulator } from "ngfire";

export const environment = {
  production: false,
  firebase: {
    options: {
      projectId: 'demo-firebase',
      apiKey: 'demo',
      authDomain: 'demo-firebase.firebaseapp.com',
      storageBucket: 'default-bucket',
    },
    firestore: firestoreEmulator('localhost', 8000),
    auth: authEmulator('http://localhost:9099', { disableWarnings: true }),
    storage: storageEmulator("localhost", 9199),
    functions: functionsEmulator("localhost", 5001),
    database: databaseEmulator("localhost", 9000),
  },
}

environment.prod.ts :

export const environment = {
  production: false,
  firebase: {
    options: {
      apiKey: '******',
      authDomain: '******',
      projectId: '******',
      storageBucket: '******',
      messagingSenderId: '******',
      appId: '******',
      measurementId: '******',
    }
  },
}

Connect with angular: app.module.ts:

...
import { FIREBASE_CONFIG } from 'ngfire';
import { environment } from '../environments/environment';

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, ReactiveFormsModule],
  providers: [{ provide: FIREBASE_CONFIG, useValue: environment.firebase }],
  bootstrap: [AppComponent],
})
export class AppModule {}

CollectionService

You can create a new service per collection of Firestore:

flight.service.ts:

import { Injectable } from '@angular/core';
import { FireCollection } from 'ngfire';

export interface Flight {
  number: string;
  info: string;
}

@Injectable({ providedIn: 'root' })
export class FlightService extends FireCollection<Flight> {
  // Collection path
  readonly path = 'flights';
  // Memorize all requests that has been done
  memorize = true;
}

The service exposes an API to do most of common tasks:

  • valueChanges: returns an Observable
  • load: returns a Promise using the cache if available
  • getValue: returns a Promise without using the cache
  • add: adds a new documet to the collection
  • update: update an existing document to the collection
  • upsert: add or update a document
  • remove: remove a document from the collection
  • removeAll: remove all documents from a collection

TransferState (SSR)

ngfire supports state transfer from your server into the browser for Documents and Collections (not queries).

To implement it you need to :

  1. Set memorize: true on the FireCollection
  2. Add BrowserTransferStateModule into your app.module.ts:
@NgModule({
  imports: [..., BrowserTransferStateModule]
})
  1. Add ServerTransferStateModule into your app.server.module.ts:
@NgModule({
  imports: [..., ServerTransferStateModule]
})