Giter Site home page Giter Site logo

pedrocoder / angularfire2-offline Goto Github PK

View Code? Open in Web Editor NEW

This project forked from adriancarriger/angularfire2-offline

0.0 1.0 0.0 10.12 MB

๐Ÿ”Œ A simple wrapper for AngularFire2 to read and write to Firebase while offline, even after a complete refresh.

Home Page: https://angularfire2-offline.firebaseapp.com/

License: MIT License

JavaScript 8.90% TypeScript 91.10%

angularfire2-offline's Introduction

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

Demos

Example Gif

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.

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.

angularfire2-offline's People

Contributors

adriancarriger avatar danielsogl avatar ciekawy avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.