diff --git a/README.md b/README.md
index ac54b35..0615232 100644
--- a/README.md
+++ b/README.md
@@ -13,19 +13,26 @@ Getting Started
Include both firebase.js and backbone-firebase.js in your application.
They're both served off of Firebase's CDN, which you are welcome to use!
+### As a Script Include
``` html
```
-Backfire is also available on Bower.
+You will now have access to the `Backbone.Firebase`,
+`Backbone.Firebase.Collection`, and `Backbone.Firebase.Model` objects.
+### Bower Install
``` bash
bower install backfire
```
-You will now have access to the `Backbone.Firebase`,
-`Backbone.Firebase.Collection`, and `Backbone.Firebase.Model` objects.
+### Node Install
+``` js
+var BackboneFirebase = require('./backbone-firebase.js');
+```
+
+Pretty much just like web installs; use `BackboneFirebase.Collection`, and `BackboneFirebase.Model`.
Backbone.Firebase
-----------------
diff --git a/backbone-firebase.js b/backbone-firebase.js
index 229e784..9e712da 100644
--- a/backbone-firebase.js
+++ b/backbone-firebase.js
@@ -1,15 +1,20 @@
/**
* Backbone Firebase Adapter.
*/
-
-"use strict";
-
-(function() {
-
- var _ = window._;
- var Backbone = window.Backbone;
-
- Backbone.Firebase = function(ref) {
+(function (win, factory) {
+ if (typeof module === 'object' && typeof exports === 'object' && exports === module.exports) {
+ module.exports = factory(require('underscore'), require('backbone'), require('firebase'));
+ }
+ else if (typeof define === 'function' && define.amd) {
+ define(['underscore', 'backbone', 'firebase'], factory);
+ }
+ else {
+ win.Backbone.Firebase = factory(win._, win.Backbone, win.Firebase);
+ }
+}(this, function(_, Backbone, Firebase) {
+ "use strict";
+
+ var BackboneFirebase = function(ref) {
this._fbref = ref;
this._children = [];
if (typeof ref == "string") {
@@ -22,7 +27,7 @@
this._fbref.on("child_removed", this._childRemoved, this);
};
- _.extend(Backbone.Firebase.prototype, {
+ _.extend(BackboneFirebase.prototype, {
_childAdded: function(childSnap, prevChild) {
var model = childSnap.val();
model.id = childSnap.name();
@@ -119,7 +124,7 @@
});
- Backbone.Firebase.sync = function(method, model, options, error) {
+ BackboneFirebase.sync = function(method, model, options, error) {
var store = model.firebase || model.collection.firebase;
// Backwards compatibility with Backbone <= 0.3.3
@@ -160,13 +165,13 @@
Backbone.sync = function(method, model, options, error) {
var syncMethod = Backbone.oldSync;
if (model.firebase || (model.collection && model.collection.firebase)) {
- syncMethod = Backbone.Firebase.sync;
+ syncMethod = BackboneFirebase.sync;
}
return syncMethod.apply(this, [method, model, options, error]);
};
// Custom Firebase Collection.
- Backbone.Firebase.Collection = Backbone.Collection.extend({
+ BackboneFirebase.Collection = Backbone.Collection.extend({
sync: function() {
this._log("Sync called on a Firebase collection, ignoring.");
},
@@ -183,16 +188,16 @@
this.firebase = options.firebase;
}
switch (typeof this.firebase) {
- case "object":
- break;
- case "string":
- this.firebase = new Firebase(this.firebase);
- break;
- case "function":
- this.firebase = this.firebase();
- break;
- default:
- throw new Error("Invalid firebase reference created");
+ case "object":
+ break;
+ case "string":
+ this.firebase = new Firebase(this.firebase);
+ break;
+ case "function":
+ this.firebase = this.firebase();
+ break;
+ default:
+ throw new Error("Invalid firebase reference created");
}
// Add handlers for remote events.
@@ -419,7 +424,7 @@
});
// Custom Firebase Model.
- Backbone.Firebase.Model = Backbone.Model.extend({
+ BackboneFirebase.Model = Backbone.Model.extend({
save: function() {
this._log("Save called on a Firebase model, ignoring.");
},
@@ -449,16 +454,16 @@
this.firebase = options.firebase;
}
switch (typeof this.firebase) {
- case "object":
- break;
- case "string":
- this.firebase = new Firebase(this.firebase);
- break;
- case "function":
- this.firebase = this.firebase();
- break;
- default:
- throw new Error("Invalid firebase reference created");
+ case "object":
+ break;
+ case "string":
+ this.firebase = new Firebase(this.firebase);
+ break;
+ case "function":
+ this.firebase = this.firebase();
+ break;
+ default:
+ throw new Error("Invalid firebase reference created");
}
// Add handlers for remote events.
@@ -521,4 +526,5 @@
});
-})();
+ return BackboneFirebase;
+}));
\ No newline at end of file