akita-ng-fire
A service to connect Akita and Angular Firestore
Last updated 20 days ago by fritzschoff .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install akita-ng-fire 
SYNC missed versions from official npm registry.

akita-ng-fire build status

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

Schematics :

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

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 :

Subcollection

Documentation for Subcollection can be found here :

Authentication

Documentation to manage authentication can be found here :

Cookbook ????

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

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`,
    queryFn: (ref) => ref.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.

Current Tags

  • 4.1.0-beta.1                                ...           beta (20 days ago)
  • 4.0.1                                ...           latest (20 days ago)
  • 2.0.0-rc.5                                ...           next (8 months ago)
  • 3.1.8                                ...           test (19 days ago)

93 Versions

  • 3.1.8                                ...           19 days ago
  • 4.1.0-beta.1                                ...           20 days ago
  • 4.0.1                                ...           20 days ago
  • 4.0.0                                ...           24 days ago
  • 3.1.7                                ...           25 days ago
  • 3.1.6                                ...           2 months ago
  • 3.1.5                                ...           2 months ago
  • 3.1.4                                ...           2 months ago
  • 3.1.3                                ...           3 months ago
  • 3.1.2                                ...           3 months ago
  • 3.1.1                                ...           3 months ago
  • 3.1.0                                ...           3 months ago
  • 3.0.5                                ...           3 months ago
  • 3.0.4                                ...           3 months ago
  • 3.0.3                                ...           4 months ago
  • 3.0.2                                ...           5 months ago
  • 3.0.1                                ...           5 months ago
  • 3.0.0                                ...           5 months ago
  • 2.0.4                                ...           5 months ago
  • 2.0.3                                ...           7 months ago
  • 2.0.2-test.1 [deprecated]           ...           7 months ago
  • 2.0.2-test                                ...           7 months ago
  • 2.0.2                                ...           7 months ago
  • 2.0.1                                ...           7 months ago
  • 2.0.0                                ...           7 months ago
  • 2.0.0-rc.5 [deprecated]           ...           8 months ago
  • 2.0.0-rc.5-test                                ...           8 months ago
  • 2.0.0-rc.4-test                                ...           8 months ago
  • 2.0.0-rc.4                                ...           8 months ago
  • 2.0.0-rc.3                                ...           8 months ago
  • 2.0.0-rc.2                                ...           8 months ago
  • 2.0.0-rc.2-test                                ...           8 months ago
  • 2.0.0-rc.1                                ...           8 months ago
  • 2.0.0-alpha.29                                ...           9 months ago
  • 2.0.0-alpha.29-test.2                                ...           9 months ago
  • 2.0.0-alpha.29-test                                ...           9 months ago
  • 2.0.0-alpha.28                                ...           10 months ago
  • 2.0.0-alpha.27                                ...           10 months ago
  • 2.0.0-alpha.27-test.1                                ...           10 months ago
  • 2.0.0-alpha.27-test                                ...           10 months ago
  • 2.0.0-alpha.26                                ...           10 months ago
  • 2.0.0-alpha.25                                ...           10 months ago
  • 2.0.0-alpha.24                                ...           10 months ago
  • 2.0.0-alpha.23                                ...           10 months ago
  • 2.0.0-alpha.22                                ...           a year ago
  • 2.0.0-alpha.21                                ...           a year ago
  • 2.0.0-alpha.20                                ...           a year ago
  • 2.0.0-alpha.19                                ...           a year ago
  • 2.0.0-alpha.18                                ...           a year ago
  • 2.0.0-alpha.17                                ...           a year ago
  • 2.0.0-alpha.16                                ...           a year ago
  • 2.0.0-alpha.15                                ...           a year ago
  • 2.0.0-alpha.14                                ...           a year ago
  • 2.0.0-alpha.13                                ...           a year ago
  • 2.0.0-alpha.12                                ...           a year ago
  • 2.0.0-alpha.11                                ...           a year ago
  • 2.0.0-alpha.10                                ...           a year ago
  • 2.0.0-alpha.9                                ...           a year ago
  • 2.0.0-alpha.8                                ...           a year ago
  • 2.0.0-alpha.7                                ...           a year ago
  • 2.0.0-alpha.6                                ...           a year ago
  • 2.0.0-alpha.5                                ...           a year ago
  • 2.0.0-alpha.4                                ...           a year ago
  • 2.0.0-alpha.3                                ...           a year ago
  • 2.0.0-alpha.2                                ...           a year ago
  • 2.0.0-alpha.1                                ...           a year ago
  • 1.5.13                                ...           a year ago
  • 1.5.12                                ...           a year ago
  • 1.5.11                                ...           a year ago
  • 1.5.10                                ...           a year ago
  • 1.5.9                                ...           a year ago
  • 1.5.8                                ...           a year ago
  • 1.5.7                                ...           a year ago
  • 1.5.6                                ...           a year ago
  • 1.5.5                                ...           a year ago
  • 1.5.4                                ...           a year ago
  • 1.5.3                                ...           a year ago
  • 1.5.2                                ...           a year ago
  • 1.5.1                                ...           a year ago
  • 1.5.0                                ...           a year ago
  • 1.4.1                                ...           a year ago
  • 1.4.0                                ...           a year ago
  • 1.3.1                                ...           a year ago
  • 1.3.0                                ...           a year ago
  • 1.2.0                                ...           a year ago
  • 1.1.0                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
  • 0.2.2                                ...           a year ago
  • 0.2.1                                ...           a year ago
  • 0.2.0                                ...           a year ago
  • 0.1.4                                ...           a year ago
  • 0.1.3                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 1
This Month 1
Last Day 0
Last Week 0
Last Month 46
Dependencies (1)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |