All Projects → adriancarriger → Angularfire2 Offline

adriancarriger / Angularfire2 Offline

Licence: mit
🔌 A simple wrapper for AngularFire2 to read and write to Firebase while offline, even after a complete refresh.

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Angularfire2 Offline

Todo Angular Firebase
Todo app with Angular CLI • AngularFire2 • Firebase • OAuth • SW-Precache
Stars: ✭ 517 (+147.37%)
Mutual labels:  firebase, offline, angular4, angular-cli
React Firebase Admin
React ⚛️ starter kit with Firebase 🔥 and Bulma for setting up an admin dashboard - Highly scalable, PWA, Serverless
Stars: ✭ 232 (+11%)
Mutual labels:  firebase, offline, pwa
Rwa Trivia
Trivia App - Real World Angular series
Stars: ✭ 251 (+20.1%)
Mutual labels:  firebase, angular-cli, angular-2
Angular4-seed
Angular 4 Seed for Angular Forms
Stars: ✭ 37 (-82.3%)
Mutual labels:  angular4, angular-2, angular-cli
Coreui Free Bootstrap Admin Template
CoreUI is free bootstrap admin template
Stars: ✭ 11,038 (+5181.34%)
Mutual labels:  angular4, angular-cli, angular-2
ncg-crud-ngx-md
Angular 4+ Material Design CRUD/Admin app by NinjaCodeGen http://DNAfor.NET
Stars: ✭ 36 (-82.78%)
Mutual labels:  angular4, angular-2, angular-cli
laravel5Angular4
Laravel 5.4 & Angular 4.3.4
Stars: ✭ 37 (-82.3%)
Mutual labels:  angular4, angular-2, angular-cli
React Most Wanted
React starter kit with "Most Wanted" application features
Stars: ✭ 1,867 (+793.3%)
Mutual labels:  firebase, offline, pwa
Angularconcepts
Key Angular Concepts using Latest Angular version 5
Stars: ✭ 31 (-85.17%)
Mutual labels:  firebase, angular4, angular-cli
Sol Journal
✎ Simple, personal journaling progressive web app
Stars: ✭ 470 (+124.88%)
Mutual labels:  firebase, offline, pwa
Coreui Free Angular Admin Template
CoreUI Angular is free Angular 2+ admin template based on Bootstrap 4
Stars: ✭ 1,279 (+511.96%)
Mutual labels:  angular4, angular-cli, angular-2
Bento Starter
🍱 Full-Stack solution to quickly build PWA applications with Vue.js and Firebase
Stars: ✭ 1,519 (+626.79%)
Mutual labels:  firebase, offline, pwa
Paper Kit 2 Angular
Free Bootstrap 4 UI Kit for Angular 2+
Stars: ✭ 133 (-36.36%)
Mutual labels:  angular4, angular-cli
Ngx Openlayers
Angular2+ components for Openlayers 4.x
Stars: ✭ 131 (-37.32%)
Mutual labels:  angular4, angular-2
Buefy Shop
A sample shop built with Nuxt, Stripe, Firebase and Serverless Functions
Stars: ✭ 207 (-0.96%)
Mutual labels:  firebase, pwa
Angular Firebase App
The code for the Angular and Firebase - Build a Web App Course
Stars: ✭ 124 (-40.67%)
Mutual labels:  firebase, angular-cli
Angular9 Example App
Angular 13 Example App + Angular CLI + i18n + GraphQL
Stars: ✭ 1,769 (+746.41%)
Mutual labels:  firebase, angular-cli
Wooionic3
An eCommerce App for WooCommerce stores using Ionic 3.
Stars: ✭ 208 (-0.48%)
Mutual labels:  ionic-framework, angular4
Spring Boot Angular4 Boilerplate
Quickstart for spring boot + angular 4 projects
Stars: ✭ 151 (-27.75%)
Mutual labels:  angular4, angular-cli
Angular Lab
Angular Lab
Stars: ✭ 151 (-27.75%)
Mutual labels:  firebase, angular-2

AngularFire2 Offline npm version

🔌 A simple wrapper for AngularFire2 to read and write to Firebase while offline, even after a complete refresh.

Build Status Codecov Dependency Status devDependency Status Downloads

Demos

Example Gif

Version Support

The latest version of angularfire2-offline only supports Angular 4. If you would like to upgrade to a more recent version, please try out Cloud Firestore which comes with offline support. For more info see issue #89.

Legacy Versions

Install

npm install angularfire2-offline angularfire2 firebase --save

Setup @NgModule

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AngularFireModule } from 'angularfire2';
import { AngularFireOfflineModule } from 'angularfire2-offline';
import { AngularFireDatabaseModule } from 'angularfire2/database';

import { AppComponent } from './app.component';

export const firebaseConfig = {
  apiKey: '<your-key>',
  authDomain: '<your-project-authdomain>',
  databaseURL: '<your-database-URL>',
  storageBucket: '<your-storage-bucket>'
};

@NgModule({
  declarations: [AppComponent],
  imports: [
    AngularFireDatabaseModule,
    AngularFireModule.initializeApp(firebaseConfig),
    AngularFireOfflineModule,
    BrowserModule
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Usage

  • Methods mirror AngularFire2 database methods for object and list.

Read Data Offline

import { Component } from '@angular/core';
import {
  AfoListObservable,
  AfoObjectObservable,
  AngularFireOfflineDatabase } from 'angularfire2-offline/database';

@Component({
  selector: 'project-name-app',
  template: `
  <h1>{{ (info | async)?.name }}</h1>
  <ul>
    <li *ngFor="let item of items | async">
      {{ item?.name }}
    </li>
  </ul>
  `
})
export class MyApp {
  info: AfoObjectObservable<any>;
  items: AfoListObservable<any[]>;
  constructor(afoDatabase: AngularFireOfflineDatabase) {
    this.info = afoDatabase.object('/info');
    this.items = afoDatabase.list('/items');
  }
}

Write data offline

If writes are made offline followed by a page refresh, the writes will be sent when a connection becomes available.

AngularFire2 Offline specific features

In addition to wrapping most database features from AngularFire2, a minimal amount of offline specific features are provided:

Offline promises

  • Regular promises - Making a write to Firebase will return a promise as expected. The promise will complete after the data has been saved to Firebase.
  • Offline promises - If you application only needs to know when the write has been saved offline (which will sync on reconnect) you can access the offline promise within the regular promise by calling promise.offline.then().

Offline promise example

const promise = this.afoDatabase.object('car').update({maxSpeed: 100});
promise.offline.then(() => console.log('offline data saved to device storage!'));
promise.then(() => console.log('data saved to Firebase!'));

Also see working with promises

reset - delete offline data

The reset method is useful for deleting sensitive data when a user signs out of an application. This also helps prevent permission errors when using Firebase auth.

Use reset with caution

If writes are made while offline reset will delete them before they can reach Firebase.

reset example

onUserSignout() {
  this.afoDatabase.reset()
}

Calling reset on specific references

You can reset a specific Firebase reference by passing the reference string to the reset method

onUserSignout() {
  this.afoDatabase.reset('my/firebase/ref')
}

How it works

  • While online, Firebase data is stored locally (as data changes the local store is updated)
  • While offline, local data is served if available, and writes are stored locally
  • On reconnect, app updates with new Firebase data, and writes are sent to Firebase
  • Even while online, local data is used first when available which results in a faster load

Contributing to AngularFire2 Offline

Pull requests are welcome! If you have a suggested enhancement, please open an issue. Thanks!

Here is how you can setup a development environment:

Clone repo

  1. git clone https://github.com/adriancarriger/angularfire2-offline.git
  2. cd angularfire2-offline

Setup example

  1. cd examples/angular-cli
  2. yarn
  3. npm start

Setup development environment

  1. Open a new shell/terminal
  2. cd angularfire2-offline
  3. yarn
  4. npm run start-dev

License

angularfire2-offline is licensed under the MIT Open Source license. For more information, see the LICENSE file in this repository.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].