Giter VIP home page Giter VIP logo

aurelia-fire's Introduction

aurelia-fire

A Firebase adapter plugin for Aurelia. Based on AngularFire.

This plugin provides synchronized firebase arrays, objects and authentication. You'll need to install this plugin with jspm and then add it to your Aurelia startup as a plugin.

You can initialize a firebase object with a 'three-way-binding' to allow changes to the object to automatically propagate to the firebase store, without requiring any save/update action. Use wisely.

Note: This is a work in progress and isn't stable. Breaking changes etc. etc.

Install

jspm install aurelia-fire=github:edmulraney/angular-fire

Project status

Working

  • FirebaseArray
  • FirebaseObject

In progress

  • FirebaseAuthentication

Todo

  • Tests
  • Extract FirebaseUtils into proper classes
  • Documentation
  • Remove lodash dependency

Usage

FirebaseArray

Note: you must use the FirebaseArray methods to update your array:

  • add()
  • remove()
  • save()

Do not call splice(), push(), pop(), shift() directly.

import Firebase from 'firebase';
import {FirebaseArray} from 'aurelia-fire';

export class Example {
  people = [];

  constructor(){
    this.ref = new Firebase('https://INSTANCE.firebaseio.com/people');
    this.array = new FirebaseArray(this.ref).then(result => this.people = result);
  }

  // Example: Adding data
  add() {
    this.people.add({Age: 27, Name: 'John Doe'});
  }

  // Example: Removing data
  remove() {
    // all array items store their unique Firebase Key in their $id property
    let exampleId = this.plants[0].$id;
    this.plants.remove(exampleId);
  }

  // Example: Updating data
  update() {
    let person = this.people[0];
    person.Name = "Joe Bloggs";
    person.Age = 23;
    this.people.save(person);
  }
}

FirebaseObject (Standard synchronized object)

import Firebase from 'firebase';
import {FirebaseObject} from 'aurelia-fire';

export class Example {  
  person = {};

  constructor() {
    this.ref = new Firebase('https://INSTANCE.firebaseio.com/people');
    this.obj = new FirebaseObject(this.ref).then(result => this.person = result);
  }

  update() {
    this.person.Name = "Thomas Hobbes";
    this.person.Age = 50;
    this.person.save();
  }
}

FirebaseObject (Three way binding)

import Firebase from 'firebase';
import {FirebaseObject} from 'aurelia-fire';
import {ObserverLocator} from 'aurelia-framework';

export class Example {
  static inject = [ObserverLocator];
  person = {};

  constructor(observer){
    this.ref = new Firebase('https://INSTANCE.firebaseio.com/people');
    this.obj = new FirebaseObject(ref).then(result => result.bindTo(this, 'person', observer));
  }

  // No need for an 'update' method anymore, changes in the UI are automatically synchronized to firebase
  update() {
  }
}

aurelia-fire's People

Contributors

edmulraney avatar

Watchers

 avatar  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.