ng-fire-alarm

Firebase binding use $q in AngularJS
2 people use it
Author: 922234?v=2 tomchentw

ng-fire-alarm

Distributed via

Version     Bower Version

Firebase binding use $q in AngularJS

Travis CI   Quality     Coverage    Dependencies

Project philosophy

Develop in LiveScript

LiveScript is a compile-to-js language, which provides us more robust way to write JavaScript.
It also has great readibility and lots of syntax sugar just like you're writting python/ruby.

Use new API from $q

We use newly introduced $q API to notify you about the value/order changes, we let you decide how you deal with your data with $scope.

Firebase Collection support

We know that you want to take advantage of collection in Firebase, but still want to preserve the right order, or order by any properties in each item. ng-fire-alarm allows to transform collection object into native js array for you.

Seperation of Concerns

We follow seperation of concerns by seperating control(reference) object and data source to Alarm object and Fire object(s). So a ng-change, ng-submit, ng-click can be directly bound to Alarm object, while your Fire object(s) are clean and just like what you see in Firebase dashboard.

Installation

Just use it

Then include them through script tag in your HTML.

Rails projects (Only support 3.1+)

Add this line to your application's Gemfile:

And then execute:

Then add these lines to the top of your app/assets/javascripts/application.js file:

And include in your angular module definition:

Usage

We add a new method to Firebase.prototype:

$toAlarm

The key to transform your Firebase reference into a AngularJS powered alarm object, it take one parameter:

Options

collection: true/otherwise.

Pass true will transform collection object into native js array for you.

Alarm object

A wrapped object over Firbease reference that is returned by calling Firebase.prototype.$toAlarm.

Attributes:
  • $promise: it will be notified everytime the value/order changes.
Convenience Method:
  • $thenNotify: Same as $promise.then(void, void, callback).
    Register a callback that notify you each time the alarm rings.
    Unlike $promise.then, this method is self-chained and will return alarm object to allow chaining.
    See examples below.
Query Methods:

Ther're wrapper for Firebase.prototype.limit/startAt/endAt function, but it'll update internal Firebase reference and it'll populate new data through your callback registered via $thenNotify.

Examples:

Fast prototyping!

Write Methods:

They're wrapper for Firebase.prototype.remove/push/update/set/setPriority/setWithPriority function, but it'll return a promise object instead of passing in a callback function.

Examples:

Fast prototyping!

Fire object(s)

Object that is passed in to callbacks registered via $thenNotify, they can be primitive, object, or array:

primitive

Primitive is just js primitive. There's NO NO NO wrapper around primitive {$value: primitive}.

object

we've add two properties on it:

  1. $name
  2. $priority
array

sorted by native Firebase ordering.

Each item in array, if they're object, will have these properties:

  1. $name
  2. $priority
  3. $index: object index in array. Useful for reverse ordering

Contributing

devDependency Status

  1. Fork it ( https://github.com/tomchentw/ng-fire-alarm/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
comments powered by Disqus
This page was last updated almost 3 years ago.