OnFire
OnFire is a library that makes it easier to develop and maintain Firebase apps that have complex
data structures, whether they are browser-based or run on Node.js.
Already implemented:
- Schema-driven, live models. Where appropriate, property values are also models, automatically.
- Makes Promises, instead of actually calling you back. :laughing:
Coming soon:
- Atomic operations that involve multiple models simultaneously.
- Persistence! This is for loading data while offline, or for priming your app for a quick start.
Here are more details.
Contents
Examples
var Person = onfire.defineModel(
{
firstName: 'string',
lastName: 'string',
jobs: {
$id: {
title: 'string',
company: 'string',
startYear: 'number',
endYear: 'number'
}
}
});
var person = new Person(ref);
person.whenLoaded().
then(function(person) {
});
console.log(person.firstName());
console.log(person.jobs().count())
person.firstName('Fred').lastName('Bloggs');
person.save().then(...);
person.
firstName('Fred').
lastName('Bloggs').
save().
then(...);
person.frtisName('John');
person.jobs().fetch('abc-123-def').
then(function(job) {
});
person.jobs().create(
{
title: 'VP Sales',
company: 'Claritude Software Ltd.',
startYear: 2014
}).
then(function(job){
console.log(job.key());
});
person.jobs().fetchOrCreate('zyx-321-cba',
{
title: 'Team Leader',
company: 'ABC & Co. Ltd.',
startYear: 2013,
endYear: 2014
}).
then(function(job) {
});
Documentation
Ref
onfire.Ref = function(urlOrRef) {};
onfire.Ref.prototype.authAnonymously = function(opt_options) {};
onfire.Ref.prototype.authWithCustomToken = function(authToken, opt_options) {};
onfire.Ref.prototype.authWithOAuthPopup = function(provider, opt_options) {};
onfire.Ref.prototype.authWithOAuthRedirect = function(provider, opt_options) {};
onfire.Ref.prototype.authWithOAuthToken = function(provider, credentials, opt_options) {};
onfire.Ref.prototype.authWithPassword = function(credentials, opt_options) {};
onfire.Ref.prototype.changeEmail = function(credentials) {};
onfire.Ref.prototype.changePassword = function(credentials) {};
onfire.Ref.prototype.createUser = function(credentials) {};
onfire.Ref.prototype.child = function(childPath) {};
onfire.Ref.prototype.generateId = function() {};
onfire.Ref.prototype.getAuth = function() {};
onfire.Ref.prototype.key = function() {};
onfire.Ref.prototype.off = function(opt_eventType, opt_callback, opt_context) {};
onfire.Ref.prototype.offAuth = function(onComplete, opt_context) {};
onfire.Ref.prototype.offValue = function(callback, context) {};
onfire.Ref.prototype.on = function(eventType, callback, cancelCallback, context) {};
onfire.Ref.prototype.onAuth = function(onComplete, opt_context) {};
onfire.Ref.prototype.once = function(eventType) {};
onfire.Ref.prototype.onceValue = function() {};
onfire.Ref.prototype.onValue = function(callback, cancelCallback, context) {};
onfire.Ref.prototype.parent = function() {};
onfire.Ref.prototype.path = function() {};
onfire.Ref.prototype.push = function(opt_value) {};
onfire.Ref.prototype.ref = function() {};
onfire.Ref.prototype.remove = function() {};
onfire.Ref.prototype.removeUser = function(credentials) {};
onfire.Ref.prototype.resetPassword = function(credentials) {};
onfire.Ref.prototype.root = function() {};
onfire.Ref.prototype.set = function(value) {};
onfire.Ref.prototype.transaction = function(updateFn) {};
onfire.Ref.prototype.unauth = function() {};
onfire.Ref.prototype.update = function(values) {};
defineModel
onfire.defineModel = function(schema) {};
Model
onfire.model.Model = function(ref) {};
onfire.model.Model.prototype.dispose = function() {};
onfire.model.Model.prototype.exists = function() {};
onfire.model.Model.prototype.get = function(key) {};
onfire.model.Model.prototype.getBasicValue = function(key) {};
onfire.model.Model.prototype.getModel = function(key) {};
onfire.model.Model.prototype.hasChanges = function() {};
onfire.model.Model.prototype.key = function() {};
onfire.model.Model.prototype.onValueChanged = function(callback) {};
onfire.model.Model.prototype.save = function() {};
onfire.model.Model.prototype.set = function(key, value) {};
onfire.model.Model.prototype.whenLoaded = function() {};
Collection
Offers all the Model properties with the following additions and changes.
onfire.model.Collection = function(ref, opt_memberCtor) {};
onfire.model.Collection.prototype.containsKey = function(key) {};
onfire.model.Collection.prototype.count = function() {};
onfire.model.Collection.prototype.create = function(opt_values) {};
onfire.model.Collection.prototype.fetch = function(key) {};
onfire.model.Collection.prototype.fetchOrCreate = function(key, values) {};
onfire.model.Collection.prototype.forEach = function(callback) {};
onfire.model.Collection.prototype.get = function(key) {};
onfire.model.Collection.prototype.getBasicValue = function(key) {};
onfire.model.Collection.prototype.getModel = function(key) {};
onfire.model.Collection.prototype.keys = function() {};
onfire.model.Collection.prototype.onChildAdded = function(callback) {};
onfire.model.Collection.prototype.onChildRemoved = function(callback) {};
onfire.model.Collection.prototype.remove = function(key) {};
onfire.model.Collection.prototype.set = function(key, value) {};
Error Messages
onfire.model.Error.INVALID_REF;
onfire.model.Error.NOT_LOADED;
onfire.model.Error.NO_SUCH_KEY;
onfire.model.Error.NOT_A_MODEL;
onfire.model.Error.NOT_A_PRIMITIVE;
How to use OnFire in your project
Browser based projects
- Load
onfire.min.js
into your project, after the line that references Firebase. For example:
<script src="./bower_components/onfire/dist/onfire.min.js"></script>
- Optional:
bower install --save isabo/onfire
Node.js based projects
npm install --save onfire
var onfire = require('onfire');
How to set up the development environment
This is not needed if you just want to use OnFire in your project.
Pre-requisites
- Java - used by Google Closure Compiler to optimise and minify Javascript.
- NPM - used to manage dependencies. This is usually installed together with
Node.js.
Dependencies
- Install the dependencies locally:
npm install
- Update the dependencies to the most recent compatible versions:
npm update
How To Run the Test Suite
npm test
How to Build the Distributables
npm run build