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

akita-ng-fire

v7.0.1

Published

A service to connect Akita and Angular Firestore

Downloads

4,369

Readme

akita-ng-fire build status

Looking for maintainers/contributors

If you are interested maintaining this library or want to contribute to it, please contact us creating an issue or write an email to: [email protected]

Akita Angular Firebase

Simplify connection between Akita and Firebase inside an Angular project

Connect Firebase and Akita :

  • [x] Firestore Collection
  • [x] Firestore Document
  • [x] Firestore Collection Group
  • [x] Akita Array with Subcollections
  • [x] Authentication
  • [x] Real Time Database (beta)

Schematics :

  • [x] ng generate collection-service
  • [ ] ng generate collection-guard

Compatibility

| akita-ng-fire | Angular | Firebase | AngularFire | | --------------| --------|----------|--------------| | 7 | 12 | 9 | ^7.0 | | 6 | 9-12 | 8 | ^6.1.5 |

Installation

Create an Angular project:

ng new project-name
cd project-name

Add @angular/fire:

ng add @angular/fire

Setup your environment with AngularFirestoreModule.

You can use the akita-cli to instantiate an akita store.

Setup your environment

Getting Started

In your component you can now start listening on Firebase :

@Component({
  selector: 'app-root',
  template: `
    <ul>
      <li *ngFor="let movie of movies$ | async">{{ movie.title }}</li>
    </ul>
  `,
})
export class AppComponent implements OnInit {
  public movies$: Observable<Movie[]>;

  constructor(private service: MovieService, private query: MovieQuery) {}

  ngOnInit() {
    // Subscribe to the collection
    this.service.syncCollection().subscribe();
    // Get the list from the store
    this.movies$ = this.query.selectAll();
  }
}

The MovieService should looks like that :

@Injectable({ providedIn: 'root' })
@CollectionConfig({ path: 'movies' })
export class MovieService extends CollectionService<MovieState> {
  constructor(store: MovieStore) {
    super(store);
  }
}

⚠️: If you use Akita's router store, don't forget to import RouterModule.forRoot()

Collection

Documentation for Collection can be found here :

Authentication

Documentation to manage authentication can be found here :

Cookbook 📚

Examples of what you can do with akita-ng-fire

Real time database

How to use the real time database service.

Document

You can subscribe to a specific document :

In Component :

ngOnInit() {
  this.router.params.pipe(
    switchMap(params => this.service.syncDoc({ id: params.id })),
    takeUntil(this.destroyed$)
  );
}

Or with the Guard :

@Injectable({ providedIn: 'root' })
export class MovieGuard extends CollectionGuard<Movie> {
  constructor(service: MovieService) {
    super(service);
  }

  // Override the default `sync` method
  protected sync(next: ActivatedRouteSnapshot) {
    return this.service.syncDoc({ id: next.params.id });
  }
}

Akita array with subcollection

import {
  CollectionService,
  CollectionConfig,
  Query,
  syncQuery,
} from 'akita-ng-fire';

// A query that fetch all the articles with 5 comments
const articleQuery: Query<Article> = {
  path: 'articles',
  comments: (article: Article) => ({
    path: `articles/${article.id}/comments`,
    queryConstraints: [limit(5)]
  })
};

@Injectable({ providedIn: 'root' })
@CollectionConfig({ path: 'articles' })
export class MoviesService extends CollectionService<MoviesState> {
  // syncQuery needs to be bind to the service and takes a Query as second argument
  syncQuery = syncQuery.bind(this, articleQuery);
  constructor(store: MoviesStore) {
    super(store);
  }
}

Here we use bind() to link the syncQuery to the service. This design helps you to only import what you need.

To take advantage of types, add "strictBindCallApply": true inside your tsconfig.json file.

Now in Component:

ngOnInit() {
  this.service.syncQuery()
    .pipe(takeUntil(this.destroyed$))
    .subscribe();
}

Or in the Guard :

@Injectable({ providedIn: 'root' })
export class MovieGuard extends CollectionGuard<Movie> {
  // Note: Here service has to be protected to access syncQuery
  constructor(protected service: MovieService) {
    super(service);
  }

  // Override the default `sync` method
  protected sync(next: ActivatedRouteSnapshot) {
    return this.service.syncQuery();
  }
}

Credits

Many thanks to :

  • Netanel Basal for building, maintaining, and sharing his knowledge about Akita
  • Loïc Marie for all his feedbacks and contribution.
  • Eduard (ex37) for all his feedbacks and contribution.
  • Ariel Gueta for his great article about Akita and Firebase.